ProjectEvergreen/greenwood

call `bundle.close` when done generating Rollup bundles

Aperta

#1488 aperta il 12 apr 2025

 (0 commenti) (0 reazioni) (0 assegnatari)JavaScript (15 fork)auto 404
CLIenhancementgood first issue

Metriche repository

Star
 (132 stelle)
Metriche merge PR
 (Merge medio 25g 20h) (29 PR mergiate in 30 g)

Descrizione

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 the closeBundle hook.

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.close is async but 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

Guida contributor