Skip to content

fix: await bundle.close() in loadConfig and clean up every generated config file - #10347

Merged
shulaoda merged 15 commits into
mainfrom
fix/load-config-close-and-temp-dir
Oct 29, 2026
Merged

shulaoda merged 15 commits into
mainfrom
fix/load-config-close-and-temp-dir

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Jul 19, 2026 •

Copy link
Copy Markdown
Member

Description

loadConfig bundles a TypeScript config with a short-lived Rolldown build, writes it next to the config, and imports it. On main:

  • the build is never closed, so closeBundle never runs and the build stays alive until GC;
  • only the entry chunk is unlinked, so the extra chunks a config's dynamic imports create stay in the project directory;
  • every load of the same config writes the same rolldown.config.[hash].js, so two processes loading one config at the same time delete each other's file (Cannot find module .../rolldown.config.<hash>.js), and a second load in one process gets the first load's cached module.

What changed

  • bundle.close() always runs after write(). If both fail, the error is an AggregateError whose cause is the first failure.
  • Every file the build writes is removed after the import, on success and on failure. If write() fails, the files it left are found by this load's name prefix and removed too.
  • codeSplitting: false: the config is one file, so a config function that calls import() after loading still works once the files are gone.
  • Each load names its file rolldown.config.<counter>.<random>.js (.mjs / .cjs follow the config's extension): the counter keeps the name unique in the process, the random part across processes. Concurrent loads no longer share a file, and each load runs the config again instead of reusing a cached module, as the native loader already does.
  • The bundle stays beside the config: Node resolves runtime-relative lookups left in the output, such as require.resolve('./helper'), from the generated file's own directory.
  • A config that throws undefined still rejects: failures are counted when caught, not detected by their value.

Test evidence

  • tests/utils/load-config.test.ts (real bundler; after each test the fixture directory must match what it was before): a deferred config function that calls import(), require.resolve from a .cts config, throw undefined, and two concurrent loads of one config.
  • tests/utils/load-config-cleanup.test.ts (mocked bundler, private temp dir): close on every path, removal after success / failed write / failed close, a distinct file name per concurrent load, combined errors, and write rejecting with undefined.
  • Against main's load-config.ts: 9 of the 14 tests fail. The dynamic-import case leaves dynamic-function-value-<hash>.js and rolldown-runtime-<hash>.js behind. Against the previous head of this PR, 3 fail: the concurrency and failed-write cases.
  • Race script, 30 rounds × 6 fresh Node processes loading one .ts config: 43 / 180 loads failed before, 0 / 180 after, with no files left.
  • vitest run utils/ 99 passed, test:main 1239 passed (15 skipped). tsc -p tsconfig.check.json and tsc -p tests are clean. vp check is clean on the changed files, and just lint-repo passes.

Extracted from #10268 as a standalone fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda

… dir

The transient bundler used to bundle TypeScript config files was never
closed, so its closeBundle hook never fired and the build leaked. The
bundled output was also written next to the config file, littering the
project directory with rolldown.config.[hash].* files (and leaving any
non-entry chunks behind forever, since only the entry file was unlinked).

- Await bundle.close() after writing, preserving the original error when
  both the write and the close fail (AggregateError with cause).
- Write the bundled config into a fresh .rolldown-config-* temp directory
  next to the config file and remove the whole directory after importing,
  instead of unlinking just the entry chunk.
- Disable code splitting for the config bundle so dynamic imports are
  inlined and remain available to deferred config functions after the
  temp directory is removed.
- Map the @src vitest alias in the tests tsconfig so type checking and
  knip can follow the new cleanup test's imports.

Co-Authored-By: Claude Fable 5 <[email protected]>
@netlify

netlify Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 9b9c789
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6ae3102ed39783b969444b80
😎 Deploy Preview https://deploy-preview-10347--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

The `@src/*` alias pulls `../src` files into the tests type-check
program, but the tests tsconfig compiles them with TC39 decorator
semantics and without the package's ambient `ImportMeta` augmentation,
so `vitest --typecheck` reported 139 unhandled source errors (legacy
decorator signatures and `import.meta.browserBuild`). Enable
`experimentalDecorators` to match ../tsconfig.json and include
`../src/types.d.ts` in the program.

Co-Authored-By: Claude Fable 5 <[email protected]>
chatgpt-codex-connector[bot]

This comment was marked as outdated.

…t on `undefined`

Two regressions from bundling the config into a nested `.rolldown-config-*`
directory and from testing failures by the truthiness of the caught value.

Rolldown leaves runtime-relative resolution untouched in the generated
config (`require.resolve('./helper')` and friends), and Node resolves those
against the directory the generated file lives in. Moving the output into a
child directory made every such config fail with `Cannot find module`, while
it loaded fine before. Write the bundle back into the config's own directory
and remove every emitted file individually, which keeps the actual bug fixed
(non-entry chunks and assets used to be left behind forever, since only the
entry was unlinked) without changing what the config resolves against.

A config is also free to reject with any value, `undefined` included, so
`importError !== undefined` treated `throw undefined` as success and
`loadTsConfig` returned the uninitialized config instead of rejecting.
Track completion in a separate flag for the import, the write and the close.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Brooooooklyn Brooooooklyn changed the title fix: await bundle.close() in loadConfig and bundle config into a temp dir fix: await bundle.close() in loadConfig and clean up every generated config file Jul 20, 2026
…g spinoff)

Sync-merge of 96 new main commits (v1.2.0 release, client-side HMR
wave, on-demand strict-execution-order wrapping, resolveFileUrl hook and
import.meta.ROLLDOWN_FILE_URL_* support, AstFactory removal via oxc
disable_old_builder, renovate rust/npm waves incl. syn v3).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
Brooooooklyn and others added 2 commits October 6, 2026 13:21
# Conflicts:
#	packages/rolldown/tests/tsconfig.json
Every load of one config wrote the same `rolldown.config.[hash].js`, so
two processes loading it at once removed each other's file before the
import, and a second load in one process got the first load's cached
module. Each load now names its file with a random token. That token also
lets a failed `write()` find and remove whatever it left behind.

Errors are collected by push, so a rejection with `undefined` still
counts as a failure without separate flags.

The mocked tests run in a private temp dir, so the real-bundler tests can
check that the fixture directory is unchanged after every case, on
success and failure alike. Overlapping cases and fixtures are folded.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
…rocess

Node's module cache keys on the URL for the life of the process, so a
repeated file name returns the first load's module. 32 random bits can
repeat in a long-lived reloader; a per-process counter now rules that out.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-load-config-close-and-temp-dir-rolldown-rs.voidzero-docs.workers.dev (commit 304a8ce)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
9b9c789 2026-10-29T09:25:40.984Z View logs ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://dd6105ea-rolldown-rs.voidzero-docs.workers.dev 304a8ce 2026-10-29T08:16:24.597Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://5e4b1bd8-rolldown-rs.voidzero-docs.workers.dev 8e925a2 2026-10-08T06:34:48.027Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://84c3f849-rolldown-rs.voidzero-docs.workers.dev e70a036 2026-10-07T11:42:05.721Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://71d30be8-rolldown-rs.voidzero-docs.workers.dev 1e625d0 2026-10-07T08:36:32.870Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://fd0bcdf6-rolldown-rs.voidzero-docs.workers.dev 9b06e64 2026-10-07T04:34:57.472Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ace8d9c9-rolldown-rs.voidzero-docs.workers.dev ced487a 2026-10-06T10:19:36.654Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://5aed4fa5-rolldown-rs.voidzero-docs.workers.dev 545f750 2026-10-06T05:41:56.013Z Visit the dashboard ↗

Brooooooklyn commented Oct 6, 2026 •

Copy link
Copy Markdown
Member Author

Merge activity

  • Oct 6, 6:14 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 29, 9:22 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.

Brooooooklyn and others added 2 commits October 6, 2026 18:16
Drop comments that restate the code (field docs, test setup notes) and
shorten the rest to the one reason each line exists. The file-name and
single-chunk comments stay, as one or two lines each.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T06:34:26.910911Z 8e925a2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

Brooooooklyn and others added 2 commits October 7, 2026 16:33
`randomBytes()` ran between `rolldown()` and the `try` that owns the build,
so a throw there skipped `bundle.close()`. The name is now built first;
nothing between the build and its `close()` can throw.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
chatgpt-codex-connector[bot]

This comment was marked as outdated.

@rolldown rolldown deleted a comment from cursor Bot Oct 7, 2026
@rolldown rolldown deleted a comment from cursor Bot Oct 7, 2026
@rolldown rolldown deleted a comment from cursor Bot Oct 7, 2026
@rolldown rolldown deleted a comment from cursor Bot Oct 7, 2026
@rolldown rolldown deleted a comment from chatgpt-codex-connector Bot Oct 7, 2026
@rolldown rolldown deleted a comment from chatgpt-codex-connector Bot Oct 7, 2026
@rolldown rolldown deleted a comment from chatgpt-codex-connector Bot Oct 7, 2026
Brooooooklyn and others added 3 commits October 8, 2026 14:27
…ouble dot in the file name

A failed removal after a successful import rejected the whole load, while
`main` ignored it. Windows can briefly lock a freshly written file, so a
config that loaded now stays loaded; removal errors are still reported
alongside an import failure.

The output prefix ended with `.`, so the file was named
`rolldown.config.<n>.<random>..mjs`.
@shulaoda
shulaoda merged commit 9c0af88 into main Oct 29, 2026
35 of 36 checks passed
@shulaoda
shulaoda deleted the fix/load-config-close-and-temp-dir branch October 29, 2026 09:36
This was referenced Oct 29, 2026
shulaoda added a commit that referenced this pull request Oct 29, 2026
## [1.2.16] - 2026-10-29

### 🚀 Features

- perf-kit: check rendered output against the original build (#11140) by @IWANABETHATGUY
- perf-kit: node/deno server startup mode (#10601) by @IWANABETHATGUY
- perf-kit: browser page-load perf harness for coding agents (#10365) by @IWANABETHATGUY
- devtools: report mode - agent-readable build metrics report (#10364) by @IWANABETHATGUY
- inline-common-chunks: print record factories parenthesized so they compile eagerly (#11282) by @mattlewis92
- fold `'key' in ns` on namespace imports with statically known exports (#11333) by @danielroe
- inline-common-chunks: inline chunks using `import.meta.hot` in dev mode (#11339) by @hyfdev
- support `experimentalInlineCommonChunks` in dev mode (#11335) by @hyfdev
- use `INVALID_TLA_FORMAT` error for Rollup compatibility (#11266) by @sapphi-red

### 🐛 Bug Fixes

- await bundle.close() in loadConfig and clean up every generated config file (#10347) by @Brooooooklyn
- deps: update mimalloc-safe to 0.1.69 (#11376) by @shulaoda
- transform: don't crash when the working directory has been deleted (#11352) by @shulaoda
- import-glob: follow directory symlinks on the wasm binding (#10624) by @hyfdev
- tree-shaking: preserve exported rest bindings from dynamic imports (#11365) by @shuvroroy
- transform: report `tsconfigFilePaths` for a tsconfig resolved through `TsconfigCache` (#11346) by @cainrus
- tsconfig: don't apply tsconfig when resolving imports from virtual modules (#11089) by @rubas
- code-splitting: handle emitted entries the same as `input` entries when placing the runtime (#11353) by @IWANABETHATGUY
- error: make Diagnostic::add_file idempotent (#10610) by @Nic-Polumeyv
- avoid retaining callable builtin callback owners (#10961) by @IWANABETHATGUY
- code-splitting: only host the runtime in a chunk that every consumer's entries load (#11293) by @IWANABETHATGUY
- code-splitting: keep the source order of chunk imports (#11298) by @IWANABETHATGUY
- dev: don't treat a wrapped module's init as a no-op in dev mode (#11334) by @hyfdev
- treat `cwd` as a literal path in relative glob filters (#11291) by @onmax
- deps: update emnapi to 2.0.0-beta.2 and pin `@napi-rs/wasm-runtime` to 1.2.6 (#11292) by @IWANABETHATGUY
- chunk-import-map: hash stable module ids so keys don't depend on the build folder (#11277) by @mandyheg
- respect CPU limits when sizing native runtime workers (#11280) by @Brooooooklyn
- deconflict the namespace of a module without module syntax (#11256) by @IWANABETHATGUY
- code-splitting: rebuild an absorbed dynamic entry's namespace from what its imports read (#11200) by @mattlewis92
- escape line terminators in debug-info comments (#11258) by @IWANABETHATGUY

### 🚜 Refactor

- extract callable builtin hook wrapper (#10964) by @IWANABETHATGUY

### 📚 Documentation

- add an in-depth explanation for inline common chunks (#11239) by @hyfdev

### ⚡ Performance

- incremental cycle check for `avoidRedundantChunkLoads` (#11320) by @IWANABETHATGUY
- avoid copying module code for `renderedLength` and share `chunk.code` across plugins (#11342) by @IWANABETHATGUY
- count UTF-16 lengths with `simd-utf16-len` (#11259) by @IWANABETHATGUY
- don't load consola when importing rolldown (#11257) by @magurotuna

### 🧪 Testing

- dev: cover hot updates that need modules the tab never received (#9647) by @matthewdavis-oai
- dev: add dynamic import rebuild test (#7123) by @sapphi-red
- code-splitting: import file URLs in fresh-process runtime host tests on Windows (#11354) by @shulaoda
- esbuild: mark loader_data_url_base64_invalid_utf8 as an intentional difference (#10790) by @CoderSerio
- watch: fix flaky `watch buildDelay` (#11175) by @Brooooooklyn

### ⚙️ Miscellaneous Tasks

- install `cmake-core` instead of the `cmake` metapackage on FreeBSD (#11361) by @shulaoda
- deps: update oxc to 0.156.0 (#11326) by @Dunqing
- stop the Discord notification when the metric workflow fails (#11357) by @IWANABETHATGUY
- connect to the Void platform before the docs deploy (#11350) by @shulaoda
- deps: update rust crates (#11297) by @renovate[bot]
- deps: update dependency vite-plus to v1.4.0 (#11288) by @renovate[bot]
- deps: update npm packages (#11296) by @renovate[bot]
- deps: update napi (#11287) by @renovate[bot]
- deps: update rollup submodule for tests to v4.65.1 (#11331) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#11332) by @rolldown-guard[bot]
- deps: update dependency rolldown-plugin-dts to v0.28.8 (#11286) by @renovate[bot]
- deps: bump tokio to 1.53.3 (#11317) by @Brooooooklyn

### ❤️ New Contributors

* @mattlewis92 made their first contribution in [#11282](#11282)
* @shuvroroy made their first contribution in [#11365](#11365)
* @cainrus made their first contribution in [#11346](#11346)
* @matthewdavis-oai made their first contribution in [#9647](#9647)
* @rubas made their first contribution in [#11089](#11089)
* @danielroe made their first contribution in [#11333](#11333)
* @onmax made their first contribution in [#11291](#11291)
* @mandyheg made their first contribution in [#11277](#11277)
* @magurotuna made their first contribution in [#11257](#11257)

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants