Skip to content

bun build --no-bundle: write output files when --outdir is set - #35644

Merged
Jarred-Sumner merged 12 commits into
mainfrom
farm/ef7f557a/no-bundle-outdir
Aug 18, 2026
Merged

Jarred-Sumner merged 12 commits into
mainfrom
farm/ef7f557a/no-bundle-outdir

Conversation

@robobun

@robobun robobun commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #9859
Fixes #5206
Fixes #10370

Problem

  • bun build --no-bundle <entries> --outdir=<dir> prints ENOENT: failed to write file '""' for every entry and writes nothing. Single and multiple entry points both fail; only --outfile and stdout work.
  • Transpiler::build_with_resolve_result_eager (src/bundler/transpiler.rs) builds each OutputFile from zero_value() and never sets dest_path, so the write loop in src/runtime/cli/build_command.rs opens "" under the outdir fd.
  • Related: assets in bundle mode wrote [target] as Browser/ (src/bundler/bundle_v2.rs used the enum variant name) while entry points wrote browser/. This is a regression from the Rust port: the old Zig site used @tagName (bundle_v2.zig:1806), so assets came out as browser/ and bun/. It also affects the default [dir]/[target]/[name]-[hash].[ext] asset template that fullstack builds with server HTML imports get without any --asset-naming flag, not just an explicit --asset-naming '[target]/...'.

Fix

  • In the transform path, set dest_path for every transpiled (Value::Buffer) output through the same PathTemplate entry points use in computeChunks: [dir]/[name] from the path relative to --root, [ext] from the loader (css for the css loader, js otherwise, like Content::ext()), [hash] from the output bytes, [target] from the new Target::naming_placeholder(), .. sanitised to _.._, posix separators. So --no-bundle --outdir produces the same file names as bun build --outdir for the same flags, which matters because these names become a compatibility surface once they are written.
  • After the queue is processed, transform() rejects two inputs landing on one dest_path with the same Multiple files share the same output path error (and entry-naming note) bundle mode emits, instead of the second write truncating the first and exiting 0.
  • Target::naming_placeholder() (src/ast/target.rs) replaces the inline match in computeChunks and the IntoStaticStr use in bundle_v2.rs, so [target] spells the same in entry, asset, and --no-bundle output. For assets this restores the pre-port browser / bun spelling; macro and ssr change from the old bun_macro / bake_server_components_ssr to macro / ssr, matching what computeChunks already emits for entry points.
  • OutputFile::write_to_disk now takes only the dir fd: dest_path is always outdir-relative at its callers (build_command asserts this right after the call; bake passes template output), so the relative() branch and its root_dir_path parameter are gone and the Buffer arm is mkdir parent, write. The parent is created unconditionally, which also covers a single entry with --root above it (previously longest_common_path of one path echoed it back and the length gate skipped the mkdir).
  • File-copy loaders (.wasm, .node, ...) are unchanged: copy_to writes to FileOperation.pathname and ignores dest_path, so they keep an empty dest_path as on main. Their output still lands next to the source; that is a separate pre-existing bug and is filed separately.
  • CSS outputs in this path also get size set so the summary does not print 0 B.
  • Verified: test/bundler/cli.test.ts (--no-bundle with --outdir block, 14 tests: single, multiple, nested, single + --root, shared subdir + --root, collision error, [target] x3 via readdir, --entry-naming, [hash], loader-based extensions incl. --loader .pcss:css, outside-root, in-place --outdir .) all fail on the released build and pass with this change; test/bundler/bundler_naming.test.ts gains naming/EntryNamingTarget and naming/AssetNamingTarget (the asset one fails on main); test/bake/dev/production.test.ts passes with the write_to_disk signature change; bundler_string.test.ts and the NoBundle esbuild tests still pass.

Background

  • --no-bundle makes bun build transpile each entry point independently (Transpiler::transform -> process_resolve_queue -> build_with_resolve_result_eager) instead of going through BundleV2; the bundler's linker, which normally computes output paths and writes files, is never involved, so this path has to produce dest_path itself.
  • PathTemplate is the [dir]/[name].[ext]-style template behind --entry-naming / --chunk-naming / --asset-naming. print(.., sanitize_parent_dirs) fills the placeholders and rewrites .. segments so an input outside --root cannot write outside --outdir.
  • OutputFile.dest_path is the outdir-relative path the CLI prints in the summary and passes to openat on the outdir fd; OutputFile.value is either the bytes to write (Buffer), a file to copy (Copy), or already written by the linker (Saved).
  • --root (outbase) is the directory output paths are computed relative to; it defaults to the common ancestor of the entry points.

no test proof · iteration 0 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/bundler/cli.test.ts

@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 12 minutes

Limit details: You’ve used all 1 included review currently available under your plan. You completed 70 included PR reviews in the past 7 days; at that activity level, included reviews refill at 1 review per hour.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: dc21469f-e089-4025-beb0-046e44766210

📥 Commits

Reviewing files that changed from the base of the PR and between c3995e4 and 62647e6.

📒 Files selected for processing (9)
  • src/ast/target.rs
  • src/bundler/OutputFile.rs
  • src/bundler/bundle_v2.rs
  • src/bundler/linker_context/computeChunks.rs
  • src/bundler/transpiler.rs
  • src/runtime/bake/production.rs
  • src/runtime/cli/build_command.rs
  • test/bundler/bundler_naming.test.ts
  • test/bundler/cli.test.ts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Found 2 issues this PR may fix:

  1. bun build with --no-bundle and --outdir causes failed to write file "" error #5206 - Reports the same failed to write file '' ENOENT error when using bun build --no-bundle --outdir
  2. error: failed to write file "" ENOENT: No such file or directory (open()) #10370 - Reports the same empty dest_path ENOENT error when using bun build --no-bundle --outdir

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #5206
Fixes #10370

🤖 Generated with Claude Code

@robobun

robobun commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 12:05 AM PT - Aug 13th, 2026

❌ @robobun, your commit 653b010 has some failures in Build #94060 (All Failures)


🧪   To try this PR locally:

bunx bun-pr 35644

That installs a local version of the PR into your bun-35644 executable, so you can run:

bun-35644 --bun

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. fix(bundler): write transpiled files when using --no-bundle with --outdir #31650 - Also fixes --no-bundle with --outdir failing to write output files (same root cause: dest_path not being set in the transpile-only path)

🤖 Generated with Claude Code

@robobun

robobun commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

Re #31650: same underlying bug, different fix. That PR post-processes the output files in build_command.rs and hardcodes a .js extension for every output, which would rename .css entry points to .js. This PR sets dest_path at the point the OutputFile is constructed in the transpiler and looks up the output extension in options.out_extensions, so CSS stays .css and preserve_extensions is honoured. Happy to defer to whichever approach maintainers prefer.

Comment thread src/bundler/transpiler.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — 02cd1a0 addresses the single-entry + --root edge case I flagged: make_path now runs unconditionally on dirname(rel_path) (guarded against ""/.), and the fourth test locks it in.

What was reviewed:

  • Traced write_to_disk's other callers (build_command.rs, bake/production.rs) — the moved make_path is idempotent mkdir -p and the new != b"." guard only skips a no-op, so full-bundle and bake paths are unaffected.
  • Confirmed build_with_resolve_result_eager is only reached from the transform_only path, so the new dest_path computation doesn't touch the bundler proper.
  • Extension mapping goes through options.out_extensions / preserve_extensions rather than hardcoding .js, so CSS and non-JS loaders keep their extensions.
Extended reasoning...

Overview

Two-part fix for bun build --no-bundle --outdir writing to an empty dest_path (#9859, #5206, #10370):

  1. src/bundler/transpiler.rs: in build_with_resolve_result_eager (the --no-bundle transform-only path), populate output_file.dest_path from relative(root_dir, source_path) with the extension remapped via options.out_extensions. Previously left as Box::default() from zero_value().
  2. src/bundler/OutputFile.rs: in write_to_disk, hoist the dirname + make_path step outside the dest_path.len() > root_dir_path.len() gate so the parent directory is created even when longest_common_path returns the sole path verbatim (single entry + explicit --root). Adds a parent != b"." guard.

Four new tests in test/bundler/cli.test.ts cover single entry, multiple entries, nested structure, and single nested entry with --root=..

Security risks

None. The change constructs an output path from the user's own entry-point path relative to the user's own --root, then mkdir -ps under the user's own --outdir fd via openat-relative operations. No untrusted input.

Level of scrutiny

Medium — this is bundler CLI output-path plumbing, not runtime hot path or memory-sensitive code. The OutputFile.rs change touches a function shared with the full bundler and bake, so I traced those callers: bake/production.rs passes root_dir_path = b".", so any real dest_path already passed the length gate and the behavior there is unchanged (minus the new .-skip, which avoids a redundant mkdirat(fd, ".")). build_command.rs's full-bundle path likewise already hit the gate for typical ./chunk-*.js outputs. make_path = mkdir_recursive_at, which is idempotent, so the newly-covered case (length gate false) is strictly additive.

Other factors

  • My earlier review flagged the single-entry + --root gap; 02cd1a0 implements exactly the first suggested fix (drop the len() gate on make_path, compute dirname on whatever rel_path ended up as) plus the requested fourth test. Verified the trace: for that test, from_path == dest_path == "./src/nested/deep.js", length gate is false, dirname → "./src/nested", make_path creates dist/src/nested/, write succeeds.
  • build_with_resolve_result_eager is only reached from the transform_only = true path (transpiler.rs:2760), so the new dest_path block does not run for normal bun build.
  • Tests follow harness conventions (tempDir, bunEnv, concurrent Promise.all on stdout/stderr/exited, stderr asserted before exitCode, describe.concurrent for independent subprocess tests).
  • There is an open competing PR (#31650) taking a different approach; the author explained why this one is preferable (honours out_extensions/preserve_extensions instead of hardcoding .js). That's a maintainer call at merge time, not a correctness concern with this PR.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — the follow-up commit addresses the single-entry + --root gap I flagged by moving make_path outside the length gate, and the fourth test locks it in.

What was reviewed:

  • dest_path computation in build_with_resolve_result_eager — mirrors the bundler's asset-path logic (relative to root_dir, extension via out_extensions, honours preserve_extensions).
  • Traced the other write_to_disk callers (bake/production.rs passes b".", build_command.rs passes longest_common_path) — moving make_path outside the gate is at worst a no-op mkdir -p for them; the added parent != b"." check avoids the redundant call for flat outputs.
  • Four tests cover single/multi entry, nested structure, and single-nested + --root; all drain pipes concurrently and assert file contents, not just existence.
Extended reasoning...

Overview

Fixes bun build --no-bundle --outdir failing with ENOENT: failed to write file '""' (#9859, #5206, #10370). Two changes:

  1. transpiler.rs (build_with_resolve_result_eager): compute dest_path for the transform-only path — relative to options.root_dir, extension mapped through options.out_extensions (or preserved when preserve_extensions is set), prefixed with ./ to match bundler output-path shape.
  2. OutputFile.rs (write_to_disk): move the make_path(dirname(rel_path)) call outside the dest_path.len() > root_dir_path.len() gate so the parent directory is created even when longest_common_path returns the sole path verbatim (single entry + explicit --root). Added parent != b"." to skip the trivial case.

Four new tests in test/bundler/cli.test.ts.

Security risks

None. This is output-path computation for a build command using paths the user supplied on the CLI; no untrusted input, no auth/crypto/network surface.

Level of scrutiny

Medium. write_to_disk is shared with the full bundler and bake/production.rs, so the second change needed tracing across all callers:

  • bake passes root_dir_path = b".", so dest_path.len() > 1 was always true and the relative() + make_path path already ran — no behavioral change.
  • build_command.rs (full bundler) passes from_path = longest_common_path(all_paths). When the length gate is false (single output), the new code runs dirname on dest_path directly; for a flat ./foo.js that yields . (filtered), and for a nested path it creates the parent — which is exactly the case the original gate was silently skipping. make_path is mkdir -p-style, so re-creating an existing directory is a no-op.

The dest_path computation itself is scoped to build_with_resolve_result_eager, whose only in-tree caller is the --no-bundle transform loop.

Other factors

  • My previous review flagged the single-entry + --root gap; commit 02cd1a0 implemented the suggested fix (option 1: unconditional dirname + make_path in write_to_disk) and added the fourth test. That thread is resolved.
  • Tests follow harness conventions: tempDir, bunEnv/bunExe, describe.concurrent for independent subprocess spawns, concurrent pipe draining, stderr asserted before exitCode, output contents asserted (not just existence), path.join for the nested-path stdout assertion so it holds on Windows.
  • The PR takes the correct-layer approach vs. #31650 (which post-processes in build_command.rs and hardcodes .js, breaking CSS entry points). The author already noted the trade-off in-thread; closing #31650 is a maintainer call outside this review's scope.
  • No bugs surfaced by the bug-hunting pass this run.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beyond the inline [hash] note, I also checked the other three write_to_disk callers (build_command.rs and two in bake/production.rs) for regressions from the new is_absolute gate + unconditional make_path — bundler dest_paths are always relative (enforced by the debug_assert at build_command.rs:1057), so rel_path resolves the same as before and the extra make_path(dirname) is a no-op or idempotent mkdir. The _.._ handling in the escape test is the existing sanitize_parent_dirs=true path in path_template_print, not new logic.

Extended reasoning...

The prior round's single-entry+--root gap was addressed in 02cd1a0/31080d6 by moving make_path outside the length gate and guarding relative() on is_absolute. Since write_to_disk is shared with the full bundler and bake production paths, I traced all four call sites to confirm the refactor is behavior-preserving for relative dest_paths (which the existing debug_assert guarantees for the bundler). Deferring approval given the shared-helper change, the competing approach in #31650 that a maintainer should weigh, and CI not yet green on the latest commit.

Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All five rounds of prior feedback are now addressed (or explicitly declined with reasoning for the collision check). No new issues this round. This isn't a mechanical change though — ~70 lines of new PathTemplate/extension-mapping logic plus a shared-code tweak to OutputFile::write_to_disk — so worth a maintainer glance on the overall approach.

What was reviewed:

  • Traced the write_to_disk change against its other callers (build_command.rs full-bundler path and bake/production.rs with root_dir_path = b".") — both pass relative dest_paths, so the new is_absolute gate is a no-op there and unconditional make_path is strictly safer.
  • Confirmed template.print(_, true) is the sanitize_parent_dirs flag, matching the _.._/ escape test.
  • Verified the CSS-arm size fix and the Value::Copy → op.pathname dest_path both landed as described.
Extended reasoning...

Overview

Fixes bun build --no-bundle --outdir, which previously wrote nothing (ENOENT on an empty dest_path). Two source changes: (1) transpiler.rs gains a ~55-line block after the loader match in build_with_resolve_result_eager that computes dest_path via options::PathTemplate (relative-to-root, out_extensions lookup with .js fallback for JS-emitting loaders / source ext for CSS, [dir]/[name].[ext] or entry_naming, [target]/[hash] placeholders filled, .. sanitised, posix separators); Value::Copy outputs mirror op.pathname instead. The CSS arm now also sets output_file.size. (2) OutputFile::write_to_disk only relativises when dest_path is absolute, and always creates the parent dir when dirname(rel_path) is non-empty/non-.. Eight new tests in test/bundler/cli.test.ts.

Security risks

None. Path handling is confined to build-tool output under a user-supplied --outdir; the sanitize_parent_dirs=true flag on template.print maps .. → _.._ so out-of-root entries land inside --outdir (covered by the last test). No network, auth, or untrusted-input parsing.

Level of scrutiny

Medium. The --no-bundle --outdir path itself was 100% broken before, so there's nothing to regress there. The higher-scrutiny piece is the shared write_to_disk change, which is also reached by the full bundler and by bake/production.rs. I traced both: full-bundler dest_paths come from the same PathTemplate machinery and are always ./… relative, so the new is_absolute gate is false and rel_path stays as-is (previously it went through relative(from_path, dest_path) on two relative paths, which produced an equivalent openat target). bake passes root_dir_path = b".", same analysis. Moving make_path outside the length gate only adds a mkdir where one might previously have been skipped — strictly safer.

Other factors

This PR has been through five iterative review rounds; each finding (single-entry+--root mkdir, [hash] placeholder, data-loader .js extension, Value::Copy dest_path/summary mismatch, CSS size=0) was fixed with a corresponding test. The one declined item — a duplicate-dest_path collision error mirroring generateChunksInParallel.rs:407 — is reasonably scoped out (needs the CLI write loop's view of all outputs, and the pre-PR behaviour was total failure). Deferring rather than approving because the change is not mechanical: it introduces the --no-bundle naming semantics (template reuse, .js fallback for data loaders, ContentHasher for [hash]) and touches a shared write path, which merits a maintainer sign-off on the approach even though I found nothing wrong with it.

@robobun

robobun commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Reproduced with bun build --no-bundle ./src/main.tsx --outdir=dist on main (ENOENT: failed to write file '""', empty dist/). Fix and tests are in this PR; see the description for the current shape after review.

CI on 653b010 (build 94060): every test job that ran passed (the annotated tests are unrelated retries that went green). The build is marked failed only because two darwin 26 aarch64 test shards expired waiting for an agent.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new findings this run — the earlier review rounds have all been addressed. I'm not auto-approving because this adds ~60 lines of new output-path logic plus a behaviour change to the shared OutputFile::write_to_disk (also used by bake production and the full-bundler write loop), and there's a competing approach in #31650; a maintainer should confirm which one lands.

What was reviewed:

  • write_to_disk change is safe for the other two callers — bake/production.rs passes root_dir_path = b"." and relative dest_paths, so is_absolute is false and make_path still runs; mkdir_recursive_at is idempotent so the now-unconditional make_path for full-bundler outputs is at worst a redundant syscall.
  • .. sanitisation via PathTemplate::print(_, true) keeps out-of-root entries under _.._/ inside --outdir (covered by the last test).
  • The one item left open is the duplicate-dest_path collision check, which the author declined as a separate change.
Extended reasoning...

Overview

Fixes bun build --no-bundle <files> --outdir=<dir>, which previously failed with ENOENT: failed to write file '""' because the transform-only path never populated OutputFile::dest_path. The change computes dest_path in Transpiler::build_with_resolve_result_eager via the same options::PathTemplate machinery the full bundler uses (honouring --entry-naming, [hash], [target], out_extensions, preserve_extensions, and ..→_.._ sanitisation), and reworks OutputFile::write_to_disk so it only relativises absolute dest_paths and always creates the parent directory when the relative path has one. Eight tests added in test/bundler/cli.test.ts.

Security risks

The one path-safety concern — an entry point outside --root producing a ../ component that escapes --outdir — is handled by PathTemplate::print(&mut v, true), which sanitises .. to _.._; the "does not escape --outdir" test asserts the file lands under dist/_.._/other/ and that other/b.js was not written outside dist/. make_path runs relative to the outdir fd via openat, so the mkdir cannot escape the output directory either. No auth/crypto/network surface touched.

Level of scrutiny

Moderate-to-high. The --no-bundle code path itself was completely broken before, so the new transpiler.rs block cannot regress existing behaviour there. But write_to_disk is shared with the full bundler (build_command.rs:1065) and bake production (production.rs:711/722/802). I traced all three: bake passes b"." as root_dir_path with relative dest_paths, so the new is_absolute guard is false and behaviour is unchanged aside from make_path now running unconditionally (idempotent mkdir -p). The full-bundler CLI path likewise sees relative dest_paths (the field is documented /// Relative), so rel_path is used verbatim as before, plus the extra make_path. CI on 6511b57 passed the eight new tests on debian aarch64, alpine x64, windows x64, and ubuntu aarch64.

Other factors

This PR has been through five prior review rounds from me; each finding (single-entry + --root mkdir gap, [hash] unfilled, data-loader extensions, Value::Copy display path, CSS size = 0) was fixed with a corresponding test. The one declined item — a duplicate-dest_path collision check mirroring generateChunksInParallel.rs:407 — is a reasonable follow-up and not a regression. There is a competing PR #31650 taking a different approach (post-processing in build_command.rs with a hardcoded .js extension); a maintainer should decide which lands. Given the non-trivial new path-computation logic and the shared-function change, deferring rather than auto-approving.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed this across five iterations and every finding I raised has been addressed (or reasonably scoped out — the duplicate-dest_path collision check). This pass found nothing new. Given the shared write_to_disk change also feeds bake/production.rs and build_command.rs, and there's a competing approach in #31650, a maintainer sign-off would still be worthwhile.

What was reviewed:

  • write_to_disk refactor: verified both other callers (build_command.rs:1068, bake/production.rs:706/717/797) pass relative dest_paths (asserted at build_command.rs:1078), so gating relative() on is_absolute and unconditionally make_pathing the parent is a behaviour-preserving tightening for them.
  • .. sanitisation via template.print(_, true) — the out-of-root test asserts _.._/other/b.js lands under dist/ and other/b.js is not written outside it.
  • [hash]/[target] placeholders, data-loader extension mapping, CSS .size, and Value::Copy dest_path — each now covered by a test.
Extended reasoning...

Overview

Fixes #9859/#5206/#10370: bun build --no-bundle --outdir was completely broken (ENOENT on "") because the transform-only path never set OutputFile::dest_path. The fix computes dest_path in build_with_resolve_result_eager via the same PathTemplate machinery the full bundler uses, and reworks the make_path gating in OutputFile::write_to_disk so the parent directory is always created for relative outputs. ~60 LOC of Rust logic across two files, plus nine new subprocess tests in test/bundler/cli.test.ts.

Security risks

The only security-adjacent surface is path handling: an entry point outside --root produces a ../-prefixed relative path. PathTemplate::print(_, true) sanitises .. to _.._, and the eighth test asserts the output lands under dist/_.._/other/ and does not appear at ../other/b.js. platform_to_posix_in_place normalises separators so Windows \ in the template output can't bypass the dirname computation. No auth/crypto/network surface.

Level of scrutiny

Moderate. The transpiler.rs addition is confined to a code path that was 100% broken before, so regression risk there is nil. The write_to_disk change is shared with the full-bundler CLI write loop and bake/production.rs; I traced both — build_command.rs:1078 debug-asserts dest_path is never absolute, and bake passes root_dir_path = b".", so both hit the new else branch and get identical open/mkdir behaviour to before (the old relative(from_path, dest_path) on an already-relative dest_path was a no-op in practice). CI on 60c2dc4 passed on all bundler-relevant lanes including Windows and ASAN.

Other factors

This PR has been through five automated review rounds; each of the single-entry+--root, [hash], data-loader-extension, Value::Copy display-path, and CSS-size findings was addressed with a follow-up commit and a test. The one declined item (cross-file dest_path collision detection) is a reasonable scope cut — it needs the full output_files list in the CLI write loop, not per-file in the transpiler. There's a competing PR (#31650) taking a different approach (post-processing in build_command.rs with a hardcoded .js extension); this PR's approach is more complete (honours out_extensions/preserve_extensions/CSS/--entry-naming), but the choice between them is a maintainer call. Not approving on that basis plus the shared-path change, not because of any outstanding correctness concern.

@robobun

robobun commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

Consolidation: #31650 is closed in favor of this PR. Merged main into the branch (cab2016, no conflicts) and added the --outdir . in-place case from #31650, which is the exact command in #5206 (603b835, co-authored by @Tatlatat). bun bd test test/bundler/cli.test.ts: 28 pass, 0 fail (2 pre-existing skips); the new test fails on the release binary with ENOENT: failed to write file '""'. Description updated.

@alii alii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. The names this produces differ from bundle mode in a few places, and once --no-bundle --outdir starts writing files those names are hard to change.

  • two entries that map to the same output file overwrite each other and exit 0; bundle mode errors
  • [target] comes out as Browser here and browser in bundle mode
  • the out_extensions / preserve_extensions block is dead, and the one thing it does (keep the source ext for a css loader) is not what bundle mode does
  • the Copy arm still writes next to the source; the "./" + absolute path only feeds the summary line and keeps the assert in build_command quiet
    The relative() branch left in write_to_disk is unreachable, delete it instead of narrowing it.

Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/OutputFile.rs Resolved
Comment thread src/ast/target.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
@robobun

robobun commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the review in c52de81 (plus 653b010 for comment length); each thread has the specifics, summary:

  • duplicate dest_path is now an error with the bundle-mode message; test snapshots the stderr
  • [target] goes through a new Target::naming_placeholder() shared by computeChunks, the asset site in bundle_v2.rs (which had the same Browser/ bug in bundle mode), and the transform path; tests check the directory name via readdir in both modes
  • extension comes from the loader (css / js); the out_extensions / preserve_extensions block is gone; --loader .pcss:css now lands as .css
  • Value::Copy outputs are left with the empty dest_path they have on main; the copy loaders writing beside the source is filed as its own bug
  • write_to_disk lost the root_dir_path parameter and the relative() branch; added the shared-subdirectory-under---root test; bake production tests pass locally

PR description rewritten to match.

@alii alii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ready to merge from this side. Checked the five items from the last round against the new head (duplicate dest_path error, [target] spelling shared by all three sites, loader-based extension, Copy left alone, write_to_disk signature) plus the interdiff and the new tests by reading; nothing new turned up. Tests not run here. The touched files have not moved on main since the merge-base.

Comment thread src/bundler/bundle_v2.rs Resolved
robobun and others added 12 commits August 17, 2026 01:39
Previously `bun build --no-bundle <files> --outdir=dist` failed with
`ENOENT: failed to write file '""'` because the transform-only path
in the transpiler created OutputFile values with an empty dest_path.
The CLI's write_to_disk step then tried to open an empty path relative
to the outdir.

Compute dest_path the same way the bundler does for entry points:
relative to root_dir with the output extension from the out_extensions
map, so e.g. src/main.tsx lands as dist/main.js and nested directory
structure is preserved.

Fixes #9859
For a single --no-bundle entry point with --root pointing above the
entry's directory, longest_common_path returns the sole dest_path
verbatim, so the len()-gated relativize branch is skipped and the
parent directory under --outdir is never created. Move make_path
outside that gate so the parent is created whenever the relative
output path has a directory component.
…ive paths

Route the --no-bundle output path through options::PathTemplate the same
way the bundler computes entry-point paths, so --entry-naming is
honoured, .. segments are sanitized to _.._ (cannot escape --outdir),
and separators are normalised to / on every platform. In write_to_disk,
only run resolve_path::relative when dest_path is absolute; a relative
dest_path is already the path to open under the outdir fd.
Move the dest_path template computation to after the loader match so the
output bytes are available to hash when --entry-naming contains [hash],
matching the bundler's ContentHasher. Without this, two entries with a
[hash]-only template collided on the same empty-hash filename.
For --no-bundle entry points that go through a JS-emitting loader
(.toml, .yaml, .jsonc, .json5, .txt, .md) but have no entry in
out_extensions, fall back to .js instead of the source extension so the
output filename matches the output content and the full bundler. For
file-copy loaders the output is written to the hashed pathname computed
by build_copied_file_output, so set dest_path from that pathname so the
CLI summary matches what is on disk.
This is the command from #5206: entry points in the current directory
transpiled in place. Adapted from the tests in #31650.

Co-authored-by: Tatlatat <hungdotmn@gmail.com>
…aths

- Error on two entry points rendering to the same dest_path, with the
  same message bundle mode prints, instead of letting the second write
  truncate the first and exiting 0.
- Add Target::naming_placeholder() and use it for every [target]
  expansion. The transform path and the asset path in bundle_v2 were
  using the IntoStaticStr variant name, so [target] printed "Browser"
  where computeChunks prints "browser".
- Pick the output extension from the loader (css or js), the same way
  chunk content does. out_extensions maps every key to .js and
  preserve_extensions is never set, so the lookup was dead, and it kept
  the source extension for a css loader on a non-.css file.
- Leave dest_path empty for file-copy loaders: copy_to writes to
  FileOperation.pathname and ignores dest_path, so setting it only
  changed the summary line.
- write_to_disk: dest_path is always relative here, so drop the
  root_dir_path parameter and the relative() branch that used it.
@Jarred-Sumner
Jarred-Sumner force-pushed the farm/ef7f557a/no-bundle-outdir branch from 653b010 to 62647e6 Compare August 17, 2026 01:54
@Jarred-Sumner
Jarred-Sumner merged commit 2a707c0 into main Aug 18, 2026
10 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the farm/ef7f557a/no-bundle-outdir branch August 18, 2026 03:26
robobun added a commit that referenced this pull request Aug 18, 2026
p.rs: the import list loses FunctionKind (removed on main) and LOC_MODULE_SCOPE
(removed on this branch). jsc_hooks.rs: #39327 deleted the resolve hook this
branch had converted, so it is gone. Three sites main added against the old Loc
follow the branch: bun pm diff (#39229) sorts scope members by Option<Loc>, with
a member that has no location first as the -1 sentinel used to sort, and its
synthesized block has no close brace location; the duplicate output path error
in transpiler.rs (#35644) carries no location.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

4 participants