Repository navigation
Conversation
…unk namer The note under `Multiple files share the same output path` names the naming option to change. The report chose `entry` or `chunk` with its own test. That test differs from the one in `compute_chunks` that chose the template: - The script and the stylesheet of a page printed `entry naming is '<chunk template>'` (since #15940). - A page that only `import()` reaches printed `chunk naming is '<entry template>'` (since #15940). - The entry point of an executable printed `entry naming is './[name]'` (since #41264, and for every collision with it since #41317). No naming option sets that template. - The report kept one template for each option, so a second template under one option replaced the first. `compute_chunks` now has one rule, `takes_entry_naming`. The namer and `chunk_named_by` both call it, and the report matches on the result of `chunk_named_by`. The chunk that `--compile` names after the output file gets no naming note. The report prints one note for each template of an option.
|
Updated 2:17 AM PT - Oct 29th, 2026
❌ @robobun, your commit 78b6cde has 6 failures in
🧪 To try this PR locally: bunx bun-pr 47306That installs a local version of the PR into your bun-47306 --bun |
|
Status: the diff is green. CI is red on lanes this PR does not touch. Stacked on #46655, which must merge first. CI, build #134893: 190 of 196 jobs passed, and the tests of this PR passed on every lane.
How to reproduce (bun 1.4.2, main, and #46655 at 672fc42), in an empty directory: mkdir a b
for d in a b; do
echo '<!doctype html><html><head><script type="module" src="./index.js"></script></head></html>' > $d/index.html
echo "console.log('$d');" > $d/index.js
done
bun build a/index.html b/index.html --outdir=out --chunk-naming='js/[name].[ext]'; echo "exit $?"Before: With this branch the last line is A build with default names reaches the wrong label too. Give each page Tests: |
Stacked on #46655, which must merge first.
Problem
Multiple files share the same output pathnames the option to change. It can name the wrong one: two pages with equal stylesheets and--minifyprintentry naming is './[name]-[hash].[ext]', but only--chunk-namingmoves those files.src/bundler/linker_context/generateChunksInParallel.rs:515).compute_chunkschooses the template with another (computeChunks.rs:653).Fix
computeChunks.rshas one rule,takes_entry_naming, for the namer and the newchunk_named_by. The report matches onchunk_named_by../[name]template.test/bundler/bundler_naming.test.ts, 7 of 8 new rows fail on bundler: add copied assets to the duplicate output path check #46655.cliandbun-build-apipass unedited. Self-reviewed: 14 concerns raised, 13 addressed, see Notes.Background
--entry-namingnames entry points and pages.--chunk-namingnames the other chunks, also a page's script and stylesheet.--compilenames the entry point of the executable after the output file, and marks that chunk with a flag bit.Chunkfield that only a failed build reads.Downsides
--compilepays 1 instruction per build. Other builds pay none..textgrows by 512 bytes.Notes
How it was found. By inspection, while #46655 was checked. No user asked for this fix. Two closed issues show the wrong word in a paste (#17674 and #25330:
entry naming is './chunk-[hash].[ext]'for stylesheet chunks). Those builds fail because two stylesheet chunks with equal bytes get one name. They fail after this PR too, withchunk naming isin the note.Why its own PR, and why stacked. The wrong labels are older than #46655, and only the row
ExecutableAndAssetneeds its asset check. #46655 rewrites the same lines of the report, so a PR on main would edit them twice. Do not merge this PR into its base branch. After #46655 merges:git rebase --onto main 672fc42162.The notes, before and after. "Before" is #46655 at 672fc42. Each row is a row of
naming/CollisionNote.PageChunksnaming.chunk = "js/[name].[ext]"entry naming is './js/[name].[ext]'chunk naming is './js/[name].[ext]'PagesAndPageChunksnaming.entry = "[name].[ext]"entry naming is './js/[name].[ext]'onlyentry naming is './[name].[ext]'andchunk naming is './js/[name].[ext]'ImportedPagesimport()reacheschunk naming is './[name].[ext]'entry naming is './[name].[ext]'ExecutableAndPageChunkapp.js, page script atapp.[ext]entry naming is './[name]'chunk naming is './app.[ext]'ExecutableAndImportedChunkapp,import()chunk atappentry naming is './[name]'andchunk naming is './app'chunk naming is './app'ExecutableAndAssetapp.binthat embedsdata/app.bin,naming.asset = "[name].[ext]"entry naming is './[name]'and the asset noteTwoChunkTemplateslazy.ts,naming.chunk = "js/[name].[ext]"entry naming is './chunk-[hash].[ext]'andchunk naming is './js/[name].[ext]'chunk namingEntryPointAndSharedChunkchunk namingfor the shared chunk. main saysasset naming, #46655 changes that, and no test pinned it.History. #10761 wrote the namer and the report with one condition. #15940 (HTML entry points) changed the condition in the namer only. #41264 (in 1.4.2) added the
./[name]arm to the namer only: the report then saidentry naming is './[name]'when the executable was not the first output at its path. #41317 (in 1.4.3 and 1.4.4) lists the first output too, so that note prints for every collision with the executable.Why a flag bit and an enum. The
--compilearm depends on loop state (the first server-side entry point), so a test on one chunk cannot find it. Bit 3 ofchunk::Flagswas free.NamedByis computed and never stored.takes_entry_namingis private tocomputeChunks.rs, so a caller cannot skip the bit, and thematchin the report does not compile when a variant is added.One note for each template. The report kept one template for each option. With the right labels, the fixed template that
--compilegives the browser chunks (./chunk-[hash].[ext],src/bundler/bundle_v2.rs:2010) lands underchunknext to the user's--chunk-naming, and one replaced the other. The report now sorts the templates of an option and prints one note for each.Measurements. Release builds of 672fc42 and of this commit, same flags.
compute_chunks: 22 instructions for each JS entry chunk before, 22 after (ptrace single-step over the PC ranges of the block, with 1, 21 and 201 entry points, 10 runs each at 1 and 21, 2 runs at 201, all runs equal).--compilearm: 70 -> 71 instructions with 1 entry point, 69 -> 70 with 21.size_of::<Chunk>(): 792 B before and after.size_of::<LinkerOptions>(): 264 B before and after (rustc -Z print-type-sizes)..text: 108,649,993 -> 108,650,505 B (+512)..rodata: +0.compute_chunks: 46,481 -> 46,489 B.generate_chunks_in_parallel::<false>: 40,549 -> 40,828 B (llvm-size -A,llvm-nm).compute_chunksfor the fixtures P0, P1 and P2 of bundler: add copied assets to the duplicate output path check #46655: 29, 2,428 and 70, before and after (ptrace counters on 11 mimalloc entry points). Whole process (gdb counters): P0 12,751 and P2 149,747 on both builds. P1 is 63,964 to 64,045 before and 63,985 to 64,051 after in 8 runs each:mi_heap_mallocon the worker threads differs from run to run.diff -rof 4 builds from both binaries (splitting with default names, three[hash]templates, a--target=bunserver with two pages, two pages): 26 files, 0 differ.EntryPointAndSharedChunkpasses) and on bun 1.4.2 (ExecutableAndImportedChunkpasses). 8 of 8 pass with this commit. Existing note assertions edited: 0.Sites of the same class that this PR does not change.
--outfile:bun build app.ts --outfile=dist/app.js --asset-naming=app.jswith an imported asset printsentry naming is './app.js', consider adding '[hash]'. The CLI turns--outfileinto that entry template. bun build: never derive an output directory from the entry point #41879 removes that rewrite and names the chunk in the./[name]arm.chunk naming is './chunk-[hash].[ext]', and--chunk-namingdoes not change that template. The templates have[hash], so the note is theidentical contentform and gives no remedy.bakeproduction builds set all three templates the same way (src/runtime/bake/config/transpiler.rs:147).bun build --no-bundlehas its own report (Transpiler::reject_duplicate_output_paths). It advises[hash]for a template that has[hash]. That is handed off as a separate fix.--asset-namingof the build. One asset takes its template from the transpiler of its target (bundle_v2.rs:4763).Merge with #41879. #41879 defines a closure
takes_entry_namingwith the same condition insidecompute_chunks, and gives plain--outfilethe./[name]arm. The two branches conflict in one line. The resolution: keep the module function, delete the closure, keepchunk.flags.insert(chunk::Flags::NAMED_BY_OUTFILE)in the arm. Keeping the closure compiles too, and leaves two copies of the rule.Self-review. 14 concerns, 13 addressed:
./[name]note is dated to compile: name the entry point's chunk after the outfile, so other chunks can load it #41264 and bundler: widen[hash]output names when two would collide; add[hashN]#41317.TwoChunkTemplates.--minifyroute: reason above.ExecutableAndPageChunkpassed without the executable: the build of that row now succeeds withoutcompile.[dir]or[name]). The report has no fact for each group to decide that. A follow-up.Suites run. Debug build of this commit:
bundler_naming(41 pass, 2 todo),html-import-manifest, thecompile/AssetNoOverwrite*,compile/AssetSameName*,compile/TextImportSameBasenameandcompile/HelloWorld*rows ofbundler_compile,cli(3--compiletests time out at 5 s there: they write a 1.6 GB debug executable) andbun-build-api(can be called thousands of timestimes out at 180 s there). Release build of this commit:cli,bun-build-api,html-import-manifest,standalone,test/internal/source-lints.[human-review] gate passed · iteration 1 · 4 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 1
evidence per changed file