ProjectEvergreen/greenwood

call `bundle.close` when done generating Rollup bundles

オープン

#1,488 opened on 2025/04/12

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (15 件のフォーク)auto 404
CLIenhancementgood first issue

Repository metrics

Stars
 (132 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド