call `bundle.close` when done generating Rollup bundles
#1,488 opened on Apr 12, 2025
Repository metrics
- Stars
- (132 stars)
- PR merge metrics
- (PR metrics pending)
Description
Current State
Currently when generating bundles with Rollup in packages/cli/src/lifecycles/bundle.js, we simply call bundle.write and we're done, e.g.
async function bundleApiRoutes(compilation) {
const apiConfigs = await getRollupConfigForApiRoutes(compilation);
if (apiConfigs.length > 0 && apiConfigs[0].input.length !== 0) {
console.info("bundling API routes...");
for (const configIndex in apiConfigs) {
const rollupConfig = apiConfigs[configIndex];
const bundle = await rollup(rollupConfig);
await bundle.write(rollupConfig.output);
}
}
}
Desired State
Was reading the Rollup docs the other day and saw that they recommend calling bundle.write when done
Once you're finished with the bundle object, you should call
bundle.close(), which will let plugins clean up their external processes or services via thecloseBundlehook.
So for all three places in bundle.js where we are calling bundle.write (SSR pages, API routes, Browser scripts), we should add a bundle.close call
const rollupConfig = apiConfigs[configIndex];
const bundle = await rollup(rollupConfig);
await bundle.write(rollupConfig.output);
await bundle.close();
I'm assuming
bundle.closeisasyncbut might be good to confirm, though I think we'll need to look at the code, since I don't think it was obvious from the docs.
Additional Context
No response