Skip to content

Commit 9478197

Browse files
committed
fix(build): fix runtime bugs in build scripts
- Fix plugin ordering in esbuild.cli.build.mjs: envVarReplacementPlugin was running before unicodeTransformPlugin despite comment saying after. Swap order so unicode transform runs first. - Fix watch mode crash in build.mjs: watchResult?.code can be undefined when spawn returns null. Add null check and fallback ?? 1. - Fix allSettled pattern in build.mjs post-processing: Promise.all swallows individual rejections. Switch to Promise.allSettled with proper rejection detection. - Fix allSettled pattern in download-assets.mjs: same Promise.all issue, now uses Promise.allSettled with r.status === 'rejected' check. - Fix allSettled pattern in download-iocraft-binaries.mjs: same fix. - Fix createBuildRunner in esbuild-shared.mjs: catch block never rethrew, so callers using allSettled could not detect failures. - Remove dead script entries from cli/package.json (e2e:smol, build:sea:internal:bootstrap, publish:sea).
1 parent b5479b0 commit 9478197

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

packages/cli/.config/esbuild.cli.build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ const config = {
145145

146146
// Handle special cases with plugins.
147147
plugins: [
148+
unicodeTransformPlugin(),
148149
// Environment variable replacement must run AFTER unicode transform.
149150
envVarReplacementPlugin(inlinedEnvVars),
150-
unicodeTransformPlugin(),
151151
{
152152
name: 'resolve-socket-packages',
153153
setup(build) {

packages/cli/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
"build:watch": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build.mjs --watch",
2424
"restore-cache": "node --import=./scripts/load.mjs scripts/restore-cache.mjs",
2525
"build:sea": "node --max-old-space-size=8192 --import=./scripts/load.mjs scripts/build-sea.mjs",
26-
"build:sea:internal:bootstrap": "node --max-old-space-size=8192 .config/esbuild.sea-bootstrap.build.mjs",
2726
"build:js": "node scripts/build-js.mjs",
2827
"dev:watch": "pnpm run build:watch",
29-
"publish:sea": "node --import=./scripts/load.mjs scripts/publish-sea.mjs",
3028
"check": "node ../../scripts/check.mjs",
3129
"check-ci": "pnpm run check",
3230
"lint": "oxlint -c ../../.oxlintrc.json",
@@ -52,7 +50,6 @@
5250
"dev:npx": "cross-env SOCKET_CLI_MODE=npx node --experimental-strip-types src/cli-dispatch.mts",
5351
"e2e-tests": "dotenvx -q run -f .env.test -- vitest run --config vitest.e2e.config.mts",
5452
"e2e:js": "node scripts/e2e.mjs --js",
55-
"e2e:smol": "node scripts/e2e.mjs --smol",
5653
"e2e:sea": "node scripts/e2e.mjs --sea",
5754
"e2e:all": "node scripts/e2e.mjs --all",
5855
"test": "run-s check test:*",

packages/cli/scripts/build.mjs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ async function main() {
141141
},
142142
)
143143

144-
if (watchResult.code !== 0) {
145-
process.exitCode = watchResult.code
146-
throw new Error(`Watch mode failed with exit code ${watchResult.code}`)
144+
if (!watchResult || watchResult.code !== 0) {
145+
process.exitCode = watchResult?.code ?? 1
146+
throw new Error(`Watch mode failed with exit code ${watchResult?.code ?? 1}`)
147147
}
148148
return
149149
}
@@ -265,7 +265,7 @@ async function main() {
265265
logger.step('Phase 4: Post-processing (parallel)...')
266266
}
267267

268-
await Promise.all([
268+
const postResults = await Promise.allSettled([
269269
// Copy CLI bundle to dist (required for dist/index.js to work).
270270
(async () => {
271271
copyFileSync('build/cli.js', 'dist/cli.js')
@@ -297,6 +297,14 @@ async function main() {
297297
})(),
298298
])
299299

300+
const postFailed = postResults.filter(r => r.status === 'rejected')
301+
if (postFailed.length > 0) {
302+
for (const r of postFailed) {
303+
logger.error(`Post-processing failed: ${r.reason?.message ?? r.reason}`)
304+
}
305+
throw new Error('Post-processing step(s) failed')
306+
}
307+
300308
if (!quiet) {
301309
printSuccess('Build completed')
302310
printFooter()

packages/cli/scripts/download-assets.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,19 @@ ${content}
331331
*/
332332
async function downloadAssets(assetNames, parallel = true) {
333333
if (parallel) {
334-
const results = await Promise.all(
334+
const settled = await Promise.allSettled(
335335
assetNames.map(name => downloadAsset(ASSETS[name])),
336336
)
337337

338-
const failed = results.filter(r => !r.ok)
338+
const failed = settled.filter(
339+
r => r.status === 'rejected' || (r.status === 'fulfilled' && !r.value.ok),
340+
)
339341
if (failed.length > 0) {
340342
logger.error(`\n${failed.length} asset(s) failed:`)
341-
for (const { name } of failed) {
342-
logger.error(` - ${name}`)
343+
for (const r of failed) {
344+
logger.error(
345+
` - ${r.status === 'rejected' ? r.reason?.message ?? r.reason : r.value.name}`,
346+
)
343347
}
344348
process.exitCode = 1
345349
}

packages/cli/scripts/esbuild-shared.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export function createBuildRunner(config, description = 'Build', importMeta) {
183183
console.error(`Build failed: ${description || 'Unknown'}`)
184184
console.error(error)
185185
process.exitCode = 1
186+
throw error
186187
}
187188
})()
188189
}

scripts/download-iocraft-binaries.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,17 @@ async function downloadBinaries(platformFilter = null) {
154154
`Downloading iocraft binaries for ${configs.length} platform(s)...`,
155155
)
156156

157-
const results = await Promise.all(
157+
const settled = await Promise.allSettled(
158158
configs.map(config => downloadIocraftBinary(config)),
159159
)
160160

161-
const failed = results.filter(r => !r.ok)
161+
const failed = settled.filter(
162+
r => r.status === 'rejected' || (r.status === 'fulfilled' && !r.value.ok),
163+
)
162164
if (failed.length > 0) {
163165
logger.error(`\n${failed.length} platform(s) failed:`)
164-
for (const { target } of failed) {
165-
logger.error(` - ${target}`)
166+
for (const r of failed) {
167+
logger.error(` - ${r.status === 'rejected' ? r.reason?.message ?? r.reason : r.value.target}`)
166168
}
167169
return false
168170
}

0 commit comments

Comments
 (0)