Skip to content

Commit 58830ce

Browse files
Make zip step more robust
Use once() listeners and a settled guard to avoid double resolution, log non-fatal archiver warnings, and resolve on the write stream's 'finish' event to prevent truncated archives under I/O pressure.
1 parent cb55b24 commit 58830ce

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

build.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,25 @@ async function zipFolder(dir) {
434434
await new Promise((resolve, reject) => {
435435
const output = fs.createWriteStream(zipPath)
436436
const archive = archiver('zip', { zlib: { level: 9 } })
437-
const onError = (err) => reject(err)
438-
output.on('error', onError)
439-
archive.on('error', onError)
440-
output.on('finish', resolve)
437+
let settled = false
438+
const fail = (err) => {
439+
if (!settled) {
440+
settled = true
441+
reject(err)
442+
}
443+
}
444+
output.once('error', fail)
445+
archive.once('error', fail)
446+
archive.on('warning', (err) => {
447+
// Log non-fatal archive warnings for diagnostics
448+
console.warn('[build][zip] warning:', err)
449+
})
450+
output.once('finish', () => {
451+
if (!settled) {
452+
settled = true
453+
resolve()
454+
}
455+
})
441456
archive.pipe(output)
442457
archive.directory(dir, false)
443458
archive.finalize()

0 commit comments

Comments
 (0)