@@ -48,38 +48,6 @@ async function exec(command, args, options = {}) {
4848 }
4949}
5050
51- /**
52- * Check if Homebrew is installed.
53- */
54- async function checkBrewInstalled ( ) {
55- try {
56- await exec ( 'brew' , [ '--version' ] )
57- return true
58- } catch {
59- return false
60- }
61- }
62-
63- /**
64- * Install Homebrew.
65- */
66- async function installBrew ( ) {
67- console . log ( '📦 Installing Homebrew...' )
68- console . log ( ' This may take a few minutes...\\n' )
69-
70- try {
71- const installScript =
72- '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
73- await exec ( 'bash' , [ '-c' , installScript ] , { stdio : 'inherit' } )
74- console . log ( ' ✓ Homebrew installed successfully\\n' )
75- return true
76- } catch ( e ) {
77- console . error ( ` ✗ Failed to install Homebrew: ${ e . message } ` )
78- console . error ( ' Please install manually: https://brew.sh/' )
79- return false
80- }
81- }
82-
8351/**
8452 * Check if binaryen (wasm-opt) is installed.
8553 */
@@ -93,17 +61,75 @@ async function checkBinaryenInstalled() {
9361}
9462
9563/**
96- * Install binaryen via Homebrew .
64+ * Install binaryen (wasm-opt) cross-platform .
9765 */
9866async function installBinaryen ( ) {
67+ const isWindows = process . platform === 'win32'
68+ const isMacOS = process . platform === 'darwin'
69+ const isLinux = process . platform === 'linux'
70+
9971 console . log ( '📦 Installing binaryen (wasm-opt)...' )
72+ console . log ( ' This may take a few minutes...\\n' )
10073
10174 try {
102- await exec ( 'brew' , [ 'install' , 'binaryen' ] , { stdio : 'inherit' } )
103- console . log ( ' ✓ binaryen installed successfully\\n' )
104- return true
75+ if ( isMacOS ) {
76+ // macOS: Try Homebrew first.
77+ console . log ( ' Trying Homebrew installation...' )
78+ try {
79+ await exec ( 'brew' , [ '--version' ] )
80+ await exec ( 'brew' , [ 'install' , 'binaryen' ] , { stdio : 'inherit' } )
81+ console . log ( ' ✓ binaryen installed via Homebrew\\n' )
82+ return true
83+ } catch {
84+ console . log ( ' ⚠ Homebrew not available, trying GitHub releases...' )
85+ }
86+ } else if ( isLinux ) {
87+ // Linux: Try apt-get first (Ubuntu/Debian).
88+ console . log ( ' Trying apt-get installation...' )
89+ try {
90+ await exec ( 'sudo' , [ 'apt-get' , 'update' ] , { stdio : 'pipe' } )
91+ await exec ( 'sudo' , [ 'apt-get' , 'install' , '-y' , 'binaryen' ] , { stdio : 'inherit' } )
92+ console . log ( ' ✓ binaryen installed via apt-get\\n' )
93+ return true
94+ } catch {
95+ console . log ( ' ⚠ apt-get not available or failed, trying GitHub releases...' )
96+ }
97+ } else if ( isWindows ) {
98+ // Windows: Try chocolatey first.
99+ console . log ( ' Trying Chocolatey installation...' )
100+ try {
101+ await exec ( 'choco' , [ '--version' ] )
102+ await exec ( 'choco' , [ 'install' , 'binaryen' , '-y' ] , { stdio : 'inherit' } )
103+ console . log ( ' ✓ binaryen installed via Chocolatey\\n' )
104+ return true
105+ } catch {
106+ console . log ( ' ⚠ Chocolatey not available, trying GitHub releases...' )
107+ }
108+ }
109+
110+ // Fallback: Download from GitHub releases (all platforms).
111+ console . log ( ' Downloading pre-built binaryen from GitHub...' )
112+ const version = 'version_119' // Latest stable as of implementation.
113+ let platformSuffix = ''
114+
115+ if ( isWindows ) {
116+ platformSuffix = 'x86_64-windows'
117+ } else if ( isMacOS ) {
118+ platformSuffix = process . arch === 'arm64' ? 'arm64-macos' : 'x86_64-macos'
119+ } else if ( isLinux ) {
120+ platformSuffix = 'x86_64-linux'
121+ }
122+
123+ const url = `https://github.com/WebAssembly/binaryen/releases/download/${ version } /binaryen-${ version } -${ platformSuffix } .tar.gz`
124+ console . log ( ` URL: ${ url } ` )
125+
126+ // For CI/automation, we'll gracefully degrade if GitHub releases download fails.
127+ console . log ( ' ⚠ GitHub releases download not yet implemented' )
128+ console . log ( ' ⚠ wasm-opt will be skipped (install manually for smaller bundles)' )
129+ return false
105130 } catch ( e ) {
106131 console . error ( ` ✗ Failed to install binaryen: ${ e . message } ` )
132+ console . error ( ' ⚠ wasm-opt will be skipped (install manually for optimal bundle size)' )
107133 return false
108134 }
109135}
@@ -141,25 +167,11 @@ const hasBinaryen = await checkBinaryenInstalled()
141167if ( ! hasBinaryen ) {
142168 console . log ( '❌ binaryen (wasm-opt) not found\n' )
143169
144- // Check if Homebrew is installed.
145- const hasBrew = await checkBrewInstalled ( )
146- if ( ! hasBrew ) {
147- console . log ( '❌ Homebrew not found\n' )
148- const brewInstalled = await installBrew ( )
149- if ( ! brewInstalled ) {
150- console . error (
151- '⚠ Skipping wasm-opt optimization (install manually for smaller bundle)' ,
152- )
153- }
154- }
155-
156- if ( hasBrew || ( await checkBrewInstalled ( ) ) ) {
157- const binaryenInstalled = await installBinaryen ( )
158- if ( ! binaryenInstalled ) {
159- console . error (
160- '⚠ Skipping wasm-opt optimization (install manually for smaller bundle)' ,
161- )
162- }
170+ const binaryenInstalled = await installBinaryen ( )
171+ if ( ! binaryenInstalled ) {
172+ console . log (
173+ '⚠ wasm-opt not available - bundle will be slightly larger\n' ,
174+ )
163175 }
164176} else {
165177 console . log ( '✓ binaryen (wasm-opt) found\n' )
0 commit comments