Skip to content

Commit e3cfb9d

Browse files
fix(optimizer): close the rolldown bundle when write() rejects (#22528)
1 parent 954cc10 commit e3cfb9d

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • packages/vite/src/node/optimizer

packages/vite/src/node/optimizer/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -855,15 +855,17 @@ async function prepareRolldownOptimizerRun(
855855
await bundle.close()
856856
throw new Error('The build was canceled')
857857
}
858-
const result = await bundle.write({
859-
...rolldownOptions.output,
860-
format: 'esm',
861-
sourcemap: true,
862-
dir: processingCacheDir,
863-
entryFileNames: '[name].js',
864-
})
865-
await bundle.close()
866-
return result
858+
try {
859+
return await bundle.write({
860+
...rolldownOptions.output,
861+
format: 'esm',
862+
sourcemap: true,
863+
dir: processingCacheDir,
864+
entryFileNames: '[name].js',
865+
})
866+
} finally {
867+
await bundle.close()
868+
}
867869
}
868870

869871
function cancel() {

0 commit comments

Comments
 (0)