ProjectEvergreen/greenwood

call `bundle.close` when done generating Rollup bundles

开放

#1,488 创建于 2025年4月12日

 (0 条评论) (0 个反应) (0 位负责人)JavaScript (15 个派生)auto 404
CLIenhancementgood first issue

仓库指标

星标
 (132 个星标)
PR 合并指标
 (平均合并 25天 20小时) (30 天内合并 29 个 PR)

描述

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

贡献者指南