Skip to content

docs(bundler): clarify that publicPath does not rewrite external module specifiers - #35577

Open
robobun wants to merge 6 commits into
mainfrom
farm/e9bdf876/onresolve-external-path
Open

docs(bundler): clarify that publicPath does not rewrite external module specifiers#35577
robobun wants to merge 6 commits into
mainfrom
farm/e9bdf876/onresolve-external-path

Conversation

@robobun

@robobun robobun commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Fixes #11652

What was reported

With bun build --external react --public-path https://cdn.example.com/, the emitted bundle still says import react from "react". The publicPath docs listed external modules alongside assets and chunks as cases where the bundle "may contain paths to other files", and both bun build --help and the CLI reference described it as "a prefix to be appended to any import paths", which together read as if --public-path should rewrite external specifiers.

Why this is working as intended

publicPath prefixes paths the bundler itself writes into the bundle: file-loader asset paths, cross-chunk import statements under --splitting, and the sourceMappingURL comment for linked source maps. An external specifier is, by definition, a string the bundler leaves alone so the runtime can resolve it; rewriting it would change which module the runtime loads. esbuild behaves the same way (esbuild --bundle --external:react --public-path=... --format=esm emits import react from "react"), and the bundler comparison page already documents publicPath as having no differences from esbuild. The issue reporter noted a docs clarification would be an acceptable resolution.

Change

  • docs/bundler/index.mdx: the publicPath section now lists the three cases it actually affects and states that external specifiers are emitted unchanged.
  • src/runtime/cli/Arguments.rs, docs/snippets/cli/build.mdx, completions/bun-cli.json: the --public-path description now reads "A prefix for emitted asset, chunk, and source-map paths" (also fixes "appended" for a prefix).
  • test/bundler/cli.test.ts: asserts the --public-path line in bun build --help names asset/chunk/source-map so the description stays accurate.

The mechanism for rewriting an external specifier (an onResolve plugin that returns { path, external: true }) is being fixed separately in #35053. An earlier revision of this PR carried an overlapping code fix for that path, since dropped in favour of #35053.


no test proof · iteration 1 · 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

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 minutes

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: f9efb676-030e-4602-8d87-26bbb4cb44de

📥 Commits

Reviewing files that changed from the base of the PR and between df6c7ee and 2c89c08.

📒 Files selected for processing (5)
  • completions/bun-cli.json
  • docs/bundler/index.mdx
  • docs/snippets/cli/build.mdx
  • src/runtime/cli/Arguments.rs
  • test/bundler/cli.test.ts

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

@robobun

robobun commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 6:06 PM PT - Jul 25th, 2026

@robobun, your commit 2c89c08 has some failures in Build #81176 (All Failures)


🧪   To try this PR locally:

bunx bun-pr 35577

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

bun-35577 --bun

Comment thread src/bundler/bundle_v2.rs Outdated
Comment thread src/bundler/bundle_v2.rs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. bundler: use onResolve-returned path for external imports #35053 - Same fix: preserves the onResolve plugin-returned path when external: true instead of dropping it; references issue implement build api define and loaders #2805 (same underlying bug as Bun build's --public-path option does not prefix external modules #11652)

🤖 Generated with Claude Code

Comment thread src/bundler/bundle_v2.rs Outdated
Comment thread docs/bundler/index.mdx Outdated
@robobun robobun changed the title bundler: keep onResolve plugin path when external: true; clarify publicPath scope docs(bundler): clarify that publicPath does not rewrite external module specifiers Jul 25, 2026

@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 — thanks for dropping the onResolve sentence; the remaining docs-only change is accurate.

Checked: the three publicPath bullets (assets, chunk imports, linked sourcemap URL) match where the bundler actually applies the prefix; the removed "External modules" bullet was the misleading one #11652 reported; the #external anchor resolves to the existing ### external section. No code touched.

One leftover: the PR description still says Fixes #11652 and describes the reverted code fix/tests — worth trimming so the auto-close doesn't surprise anyone, but not blocking.

Extended reasoning...

Overview

After commits 844295c and 9d9bafc, this PR is a pure documentation change to docs/bundler/index.mdx. It rewords the publicPath section to list the three cases where the prefix is actually applied (file-loader asset paths, cross-chunk imports under --splitting, and the //# sourceMappingURL= comment for sourcemap: "linked"), removes the misleading "External modules" bullet, and adds an explicit sentence that external specifiers are emitted unchanged. The earlier revisions of this PR contained a code fix in src/bundler/bundle_v2.rs and bundler tests; those were reverted in favor of the pre-existing #35053, and my prior feedback about the dangling onResolve-workaround sentence was addressed in 9d9bafc.

Security risks

None. This is a prose-only change to an .mdx documentation file with no executable content.

Level of scrutiny

Low. Docs-only, ~10 lines of prose diff. The claims are verifiable against existing behavior: the sourcemap table in the same file already documents that --public-path customizes the linked sourcemap URL, and the external section already states externals are "left as-is, to be resolved at runtime" — this change just cross-references that from the publicPath section where users hit the confusion. esbuild parity (mentioned in the PR description) matches. No CODEOWNERS entry covers docs/.

Other factors

Both of my earlier inline findings on this PR concerned code that has since been removed from the diff (the bundle_v2.rs deferred-rewrite ordering issue, and the docs sentence recommending an onResolve pattern that depends on unlanded #35053). Both threads are resolved and no longer apply to the current revision. CI passed on 844295c and 9d9bafc only deletes one sentence relative to that. The PR description is stale (still describes the code fix and tests, and carries Fixes #11652), but that doesn't affect the correctness of what's being merged.

@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 onResolve sentence that depended on #35053 has been dropped (9d9bafc), and the earlier bundle_v2.rs concern is moot now that the code fix was removed in favour of #35053. What remains is a docs clarification, a help-string reword, and a test pinning the help text.

Checked: the new publicPath bullets (assets, chunks, linked source maps) match what the bundler actually prefixes and are consistent with the existing sourcemap: "linked" docs; the added paragraph no longer recommends any mechanism that isn't shipped; the --help test drains stdout/stderr concurrently and asserts exit code last.

Extended reasoning...

Overview

Four files: docs/bundler/index.mdx rewrites the publicPath section to list the three cases it actually affects (file-loader asset paths, cross-chunk imports under --splitting, and the sourceMappingURL comment for linked source maps) and adds an explicit note that external specifiers are emitted unchanged; src/runtime/cli/Arguments.rs and docs/snippets/cli/build.mdx reword the --public-path description to match; test/bundler/cli.test.ts adds a test asserting the help line names asset/chunk/source-map.

An earlier revision carried a code fix in bundle_v2.rs (preserving the plugin-returned path when external: true). That was dropped in 844295c in favour of #35053, which mooted my earlier 🟡 finding about the deferred-rewrite ordering. My 🔴 finding — that the docs then recommended an onResolve workaround that doesn't work without #35053 — was addressed in 9d9bafc by removing that sentence. The current publicPath paragraph reads only: "publicPath does not rewrite specifiers for external modules. An import marked as external is emitted unchanged so it can be resolved at runtime." — accurate and self-contained.

Security risks

None. Documentation prose, a static help string, and a subprocess-based test that runs bun build --help.

Level of scrutiny

Low. The only compiled change is a string literal in parse_param!. The docs claims were verified against the existing sourcemap section (which already says --public-path customises the linked-map base URL) and the PR's own explanation of esbuild parity. The new test follows harness conventions (await using, bunEnv, concurrent pipe drain, exit-code asserted last).

Other factors

All prior inline threads on this PR are resolved and correspond to code that no longer exists in the diff or feedback that was applied. CI passed on 9d9bafc; c93a39c is a wording-alignment follow-up touching only the same help string and CLI snippet. The PR description still auto-closes #11652 — that's a metadata judgement (the reporter accepted a docs resolution) and doesn't affect the code.

@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 earlier concerns are addressed: the bundle_v2.rs change was dropped (so the deferred-rewrite ordering issue no longer applies here), and 9d9bafc removed the onResolve workaround sentence that depended on unlanded #35053. What remains is a docs clarification plus a one-word help-string change and a test pinning it. The inline nit about completions/bun-cli.json is worth doing but doesn't block.

Extended reasoning...

Overview

The current revision touches four files: docs/bundler/index.mdx (rewrites the publicPath section to enumerate the three cases it actually affects — asset paths, chunk imports, linked source maps — and adds a sentence stating externals are emitted unchanged), docs/snippets/cli/build.mdx and src/runtime/cli/Arguments.rs (align the --public-path help line with the docs), and test/bundler/cli.test.ts (asserts the help line names asset/chunk/source-map). Earlier revisions carried a bundle_v2.rs code fix and an onResolve docs recommendation; both were dropped in 844295c and 9d9bafc respectively in response to prior review comments, and those threads are resolved.

Security risks

None. This is documentation prose plus a static help-text literal inside a parse_param! macro. No parsing, no user input handling, no runtime behavior changes.

Level of scrutiny

Low. The Rust change is a string literal edit with no effect on argument parsing (only the description column of --help output changes). The docs edits are factually accurate — publicPath is applied to file-loader asset URLs, cross-chunk import paths under --splitting, and the sourceMappingURL comment; external specifiers are left as-is by design (esbuild parity). The new test follows harness conventions (await using, bunEnv, concurrent pipe drain, exit-code asserted last).

Other factors

  • Both of my earlier findings targeted code that is no longer in this PR; the author addressed them by removing the offending code/sentence rather than defending it, which is the right call given #35053 owns the code fix.
  • The one remaining nit (stale --public-path description in the checked-in completions/bun-cli.json) is real but has no user-visible effect today — the shipped shell completion scripts don't carry that string, and the JSON will pick up the new text the next time the generator is run. Not a merge blocker.
  • The Fixes #11652 in the description is defensible as a docs-only resolution since the reporter said a clarification would suffice; the actual behavioral change is tracked separately in #35053.

Comment thread src/runtime/cli/Arguments.rs
@robobun
robobun force-pushed the farm/e9bdf876/onresolve-external-path branch from f8f3008 to 2c89c08 Compare July 25, 2026 17:48

@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 — all prior feedback addressed (onResolve sentence dropped in 9d9bafc, completions JSON synced in 2c89c08, code fix deferred to #35053).

What was reviewed:

  • Verified the new publicPath docs accurately describe the three affected cases (assets, chunks, linked source maps) and no longer reference the not-yet-working onResolve workaround.
  • Confirmed the old "appended to any import paths" wording is gone repo-wide; Arguments.rs, build.mdx, and bun-cli.json now agree.
  • Checked the new cli.test.ts help-text assertion — follows harness conventions (drains pipes concurrently, exit code asserted last).
Extended reasoning...

Overview

This PR clarifies that publicPath does not rewrite external module specifiers. It touches five files: docs/bundler/index.mdx (rewrites the publicPath section to enumerate the three cases it actually affects — asset imports, chunk imports under --splitting, and linked source-map URLs — and adds an explicit note that external specifiers are emitted unchanged), src/runtime/cli/Arguments.rs (one-line help-text string change for --public-path), docs/snippets/cli/build.mdx (matching CLI reference wording), completions/bun-cli.json (syncs the generated completions description), and test/bundler/cli.test.ts (a new test asserting the --public-path line in bun build --help mentions asset/chunk/source-map).

Earlier revisions of this PR carried a code fix in bundle_v2.rs for the onResolve { path, external: true } path; that was dropped in 844295c in favour of #35053, and my follow-up feedback about the docs then recommending a not-yet-working mechanism was addressed in 9d9bafc by removing that sentence. The stale completions/bun-cli.json entry I flagged was synced in 2c89c08. All three prior inline comments are resolved and reflected in the current diff.

Security risks

None. This is documentation prose plus a static help-text string. The only executable change is a parse_param! string literal in Arguments.rs that is displayed verbatim in --help output; it does not affect argument parsing, resolution, or any bundler behaviour.

Level of scrutiny

Low. The Rust change is a display string only; the docs changes describe existing behaviour more precisely (and match esbuild's semantics, which the bundler comparison page already claims parity with). The completions JSON is a checked-in artifact derived from the same help string. The new test is additive, hermetic (spawns bun build --help with bunEnv, no filesystem or network), and follows the harness conventions in CLAUDE.md — pipes drained via Promise.all, exit code asserted last, issue URL comment.

Other factors

I grepped for the old wording ("appended to any import paths") repo-wide and found no remaining occurrences, so all copies are now consistent. The sourcemap docs table already stated that --public-path customises the sourceMappingURL base, so the new "Linked source maps" bullet is consistent with existing documentation. No CODEOWNERS cover the touched paths. The PR description still contains Fixes #11652; since the reporter explicitly said a docs clarification would be acceptable, closing that issue with this change is reasonable.

@robobun

robobun commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

CI on this PR is blocked by a Buildkite agent outage, not by the diff: builds #80817 and #81176 both show every build-cpp/build-rust job as Expired across every platform before any tests ran, and main is in the same state (#81275 failed, #81265/#80211/#80184 cancelled). The handful of build jobs that did get an agent on #81176 (linux-x64-build-cpp, linux-aarch64-build-rust, windows-x64-build-cpp, and two more) passed, so the one-line Arguments.rs string change compiles. GitHub-side checks (cargo clippy, Format, Source lints, Lint JavaScript) all pass.

Locally the new --public-path help-text test fails on released Bun and passes on the debug build with this change.

This needs a rebuild once agents are back; no code changes pending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bun build's --public-path option does not prefix external modules

1 participant