1919 * - external/socket-ai-sync.mjs (brotli-compressed, base64-encoded WASM)
2020 */
2121
22- import { brotliCompressSync } from 'node:zlib'
23- import { existsSync } from 'node:fs'
24- import { promises as fs } from 'node:fs'
22+ import { existsSync , promises as fs } from 'node:fs'
2523import path from 'node:path'
2624import { fileURLToPath } from 'node:url'
25+ import { brotliCompressSync } from 'node:zlib'
2726
2827import { logger } from '@socketsecurity/lib/logger'
2928import { spawn } from '@socketsecurity/lib/spawn'
@@ -69,7 +68,9 @@ async function installBinaryen() {
6968 const isMacOS = process . platform === 'darwin'
7069 const isLinux = process . platform === 'linux'
7170
72- logger . progress ( 'Installing binaryen (wasm-opt) - this may take a few minutes' )
71+ logger . progress (
72+ 'Installing binaryen (wasm-opt) - this may take a few minutes' ,
73+ )
7374
7475 try {
7576 if ( isMacOS ) {
@@ -88,7 +89,9 @@ async function installBinaryen() {
8889 logger . substep ( 'Trying apt-get installation' )
8990 try {
9091 await exec ( 'sudo' , [ 'apt-get' , 'update' ] , { stdio : 'pipe' } )
91- await exec ( 'sudo' , [ 'apt-get' , 'install' , '-y' , 'binaryen' ] , { stdio : 'inherit' } )
92+ await exec ( 'sudo' , [ 'apt-get' , 'install' , '-y' , 'binaryen' ] , {
93+ stdio : 'inherit' ,
94+ } )
9295 logger . done ( 'binaryen installed via apt-get' )
9396 return true
9497 } catch {
@@ -125,18 +128,22 @@ async function installBinaryen() {
125128
126129 // For CI/automation, we'll gracefully degrade if GitHub releases download fails.
127130 logger . warn ( 'GitHub releases download not yet implemented' )
128- logger . warn ( 'wasm-opt will be skipped (install manually for smaller bundles)' )
131+ logger . warn (
132+ 'wasm-opt will be skipped (install manually for smaller bundles)' ,
133+ )
129134 return false
130135 } catch ( e ) {
131136 logger . error ( `Failed to install binaryen: ${ e . message } ` )
132- logger . warn ( 'wasm-opt will be skipped (install manually for optimal bundle size)' )
137+ logger . warn (
138+ 'wasm-opt will be skipped (install manually for optimal bundle size)' ,
139+ )
133140 return false
134141 }
135142}
136143
137144const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
138145const rootPath = path . join ( __dirname , '../..' )
139- const wasmBundleDir = path . join ( rootPath , 'wasm-bundle' )
146+ const wasmBundleDir = path . join ( rootPath , 'build/ wasm-bundle' )
140147const externalDir = path . join ( rootPath , 'external' )
141148
142149logger . step ( 'Build Unified WASM Bundle' )
@@ -227,9 +234,7 @@ if (!existsSync(wasmFile)) {
227234
228235let stats = await fs . stat ( wasmFile )
229236const originalSize = stats . size
230- logger . info (
231- `WASM bundle size: ${ ( originalSize / 1024 / 1024 ) . toFixed ( 2 ) } MB` ,
232- )
237+ logger . info ( `WASM bundle size: ${ ( originalSize / 1024 / 1024 ) . toFixed ( 2 ) } MB` )
233238
234239// Try to optimize with wasm-opt if available.
235240try {
@@ -446,16 +451,12 @@ const outputPath = path.join(externalDir, 'socket-ai-sync.mjs')
446451await fs . writeFile ( outputPath , syncContent , 'utf-8' )
447452
448453logger . done ( `Generated ${ outputPath } ` )
449- logger . done (
450- `File size: ${ ( syncContent . length / 1024 / 1024 ) . toFixed ( 2 ) } MB` ,
451- )
454+ logger . done ( `File size: ${ ( syncContent . length / 1024 / 1024 ) . toFixed ( 2 ) } MB` )
452455
453456logger . success ( 'Build Complete' )
454457
455458logger . info ( 'Summary:' )
456- logger . info (
457- ` Original WASM: ${ ( wasmData . length / 1024 / 1024 ) . toFixed ( 2 ) } MB` ,
458- )
459+ logger . info ( ` Original WASM: ${ ( wasmData . length / 1024 / 1024 ) . toFixed ( 2 ) } MB` )
459460logger . info (
460461 ` Compressed: ${ ( wasmCompressed . length / 1024 / 1024 ) . toFixed ( 2 ) } MB` ,
461462)
0 commit comments