@@ -2,7 +2,7 @@
|
2 | 2 | |
3 | 3 | const WASM_BUILDER_CONTAINER = 'ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970' // v0.0.9 |
4 | 4 | |
5 | | -const { execSync } = require('node:child_process') |
| 5 | +const { execSync, execFileSync } = require('node:child_process') |
6 | 6 | const { writeFileSync, readFileSync } = require('node:fs') |
7 | 7 | const { join, resolve } = require('node:path') |
8 | 8 | |
@@ -69,10 +69,10 @@ if (process.argv[2] === '--docker') {
|
69 | 69 | } |
70 | 70 | |
71 | 71 | const hasApk = (function () { |
72 | | -try { execSync('command -v apk'); return true } catch (error) { return false } |
| 72 | +try { execSync('command -v apk'); return true } catch { return false } |
73 | 73 | })() |
74 | 74 | const hasOptimizer = (function () { |
75 | | -try { execSync(`${WASM_OPT} --version`); return true } catch (error) { return false } |
| 75 | +try { execSync(`${WASM_OPT} --version`); return true } catch { return false } |
76 | 76 | })() |
77 | 77 | if (hasApk) { |
78 | 78 | // Gather information about the tools used for the build |
@@ -104,7 +104,19 @@ ${join(WASM_SRC, 'src')}/*.c \
|
104 | 104 | ${WASM_LDLIBS}`, { stdio: 'inherit' }) |
105 | 105 | |
106 | 106 | if (hasOptimizer) { |
107 | | -execSync(`${WASM_OPT} ${WASM_OPT_FLAGS} --enable-simd -o ${join(WASM_OUT, 'llhttp_simd.wasm')} ${join(WASM_OUT, 'llhttp_simd.wasm')}`, { stdio: 'inherit' }) |
| 107 | +// Split WASM_OPT_FLAGS into an array, if not empty |
| 108 | +const wasmOptFlagsArray = WASM_OPT_FLAGS ? WASM_OPT_FLAGS.split(/\s+/).filter(Boolean) : [] |
| 109 | +execFileSync( |
| 110 | +WASM_OPT, |
| 111 | +[ |
| 112 | + ...wasmOptFlagsArray, |
| 113 | +'--enable-simd', |
| 114 | +'-o', |
| 115 | +join(WASM_OUT, 'llhttp_simd.wasm'), |
| 116 | +join(WASM_OUT, 'llhttp_simd.wasm') |
| 117 | +], |
| 118 | +{ stdio: 'inherit' } |
| 119 | +) |
108 | 120 | } |
109 | 121 | writeWasmChunk('llhttp_simd.wasm', 'llhttp_simd-wasm.js') |
110 | 122 | |
|