Skip to content

docs, completions: update the loader name lists for bunfig [loader] and --loader - #38266

Open
robobun wants to merge 4 commits into
mainfrom
farm/08a927d9/bunfig-loader-list
Open

robobun wants to merge 4 commits into
mainfrom
farm/08a927d9/bunfig-loader-list

Conversation

@robobun

@robobun robobun commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • docs/runtime/bunfig.mdx, section loader, lists the loader names a [loader] entry accepts as jsx, js, ts, tsx, css, file, json, toml, wasm, napi, base64, dataurl, text. docs/snippets/cli/run.mdx repeats the list (minus css) for --loader, and completions/bun.zsh carries the same --loader sentence four times (these scripts are embedded in the binary and printed by bun completions).
  • These lists predate the yaml, json5, xml, md, html and sqlite loaders. Mapping an extension to any of them from bunfig or --loader works today (checked on the current build, table below), but none of them is documented as a valid value.
  • base64 and dataurl are listed but not implemented: the name is accepted, then the bundler emits a module whose default export is "" and the runtime falls back to the file loader (returns the path). docs/bundler/esbuild.mdx already describes them as not implemented.

Fix

  • Replace the list in both docs pages and in the four zsh descriptions with the loaders that work when mapped from bunfig or --loader: js, jsx, ts, tsx, json, toml, yaml, json5, xml, text, md, css, html, wasm, napi, sqlite, file. Same names, same order, in every copy.
  • This is correct because bunfig [loader] and --loader (bun run, bun build, bun test) resolve the value through the same code, bun_ast::Loader::from_string followed by to_api() (src/bunfig/bunfig.rs, loader_resolver in src/runtime/cli/Arguments.rs), and each of the 17 names maps to a loader that does what the name says on both the runtime and bun build paths (table below). The bunfig page now says "The available loaders are" rather than claiming these are the only accepted spellings: aliases such as mjs, node or txt are accepted too, they are just not listed, as before.
  • Left out on purpose:
  • Sibling copies of the same list that this PR deliberately does not touch:
    • src/runtime/cli/Arguments.rs:137, the --help text: cli: list every working loader name in the --loader help text #38270 changes it to this exact list and adds a test that --help prints it and that every listed name works via --loader. That test's array is the natural place to also assert the docs and zsh copies match, so the cross-check lives in one file once both PRs are in; this PR stays free of source changes.
    • completions/bun.bash: its --loader branch only runs when : has been removed from COMP_WORDBREAKS (bash splits .ext:name at the colon by default, so prev is : and the branch is skipped; checked by driving _bun_completions directly), and completions: generate fish/bash from bun-cli.json #35443 turns the file into generated output of misctools/generate-shell-completions.ts. The longer list belongs in that generator. An earlier revision of this PR changed the file; reverted.
    • The dataurl example under loader in docs/bundler/index.mdx is being replaced separately.
  • Verified by mapping a made-up extension to every name in LOADER_NAMES (src/ast/loader.rs) from a bunfig.toml, importing one fixture per extension at runtime and bundling one entry per extension with bun build --target bun, then repeating the runtime run with --loader flags under bun run and bun test. Without any mapping every fixture imports as a path, so the results are attributable to the mapping. prettier --check passes on both docs pages.

Background

  • A loader is the parser Bun picks for a file based on its extension (json parses JSON into an object, text returns the contents as a string, file returns the path, and so on). [loader] in bunfig.toml and bun --loader .ext:name override the extension to loader mapping, for the runtime and for bun build.
  • LOADER_NAMES in src/ast/loader.rs is the table of spellings these settings accept (29 entries, including aliases). The chosen loader is converted with to_api() into the enum the bundler consumes, which is where jsonc, sqlite_embedded and sh currently collapse into json, sqlite and file. The documented list is the subset of that table that behaves as named.
Per-name results on the current build (each row is a fixture mapped to that loader name from bunfig.toml)

import() at runtime:

js               ok      string "ok-js"
jsx              ok      Object {"type":"div",...}
ts               ok      string "ok-ts"
tsx              ok      Object {"type":"span",...}
css              ok      Object {}                       (same as importing a real .css file)
file             ok      string "/.../fixture.l_file"
json             ok      Object {"kind":"json"}
jsonc            throws  SyntaxError: JSON Parse error: Unrecognized token '/'
toml             ok      Object {"kind":"toml"}
yaml             ok      Object {"kind":"yaml"}
json5            ok      Object {"kind":"json5"}
xml              ok      Object {"root":{"kind":"xml"}}
wasm             ok      string "/.../fixture.l_wasm"     (same as importing a real .wasm file)
napi             throws  TypeError: To load Node-API modules, use require() or process.dlopen instead of import.
base64           ok      string "/.../fixture.l_base64"   (file loader fallback)
dataurl          ok      string "/.../fixture.l_dataurl"  (file loader fallback)
text             ok      string "hello text"
sh               ok      string "/.../fixture.l_sh"       (file loader)
sqlite           ok      Database {"filename":"/.../fixture.l_sqlite"}
sqlite_embedded  ok      Database {"filename":"/.../fixture.l_sqlite_embedded"}
html             ok      [object HTMLBundle]             (same as importing a real .html file)
md               ok      string "<h1>Title</h1>\n<p>some <em>md</em></p>\n"

bun build --target bun, then running the output:

base64           built    string ""                       (bundle contains: var fixture_default = "";)
dataurl          built    string ""                       (same)
css              built    emits entry.css
file             built    string "./fixture-qpmg3she.l_file"
html             built    Object {"index":"./fixture.html","files":[...]}
json / json5 / toml / yaml / xml      built, parsed object
jsonc            BUILD FAILS  error: JSON does not support comments
md               built    string "<h1>Title</h1>..."
napi             built    copied as a file (documented behavior for the bundler)
sh               built    string "./fixture-z278whqb.l_sh" (file loader)
sqlite / sqlite_embedded              built, Database instance
text             built    string "hello text"
wasm             built    string "./fixture-4swqeqke.l_wasm" (copied, same as a real .wasm)

The same runtime import with --loader .l_<name>:<name> flags instead of the bunfig gives the same results for every name, under both bun run and bun test.

Earlier revision

The first revision also expanded the candidate list in completions/bun.bash from six names to the same seventeen. Reverted for the two reasons given above (the branch is unreachable with the default COMP_WORDBREAKS, and #35443 regenerates the file from a template that still carries the six-name list).

The list of accepted loader names in the bunfig [loader] section and in
the --loader flag reference predates the yaml, json5, xml, md, html and
sqlite loaders, all of which work when mapped from either place. It also
listed base64 and dataurl, which currently produce an empty module in the
bundler and fall back to the file loader at runtime, so they are removed
until they are implemented.

jsonc is left out on purpose: a bunfig or --loader mapping to it is
currently parsed as plain json.
@coderabbitai

coderabbitai Bot commented Aug 13, 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: 29 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: e40635b3-5626-4dc9-90d6-eaf7de63c51a

📥 Commits

Reviewing files that changed from the base of the PR and between c080470 and 0749b07.

📒 Files selected for processing (3)
  • completions/bun.zsh
  • docs/runtime/bunfig.mdx
  • docs/snippets/cli/run.mdx

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

@robobun

robobun commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 4:55 AM PT - Aug 14th, 2026

❌ @robobun, your commit 0749b07 has 3 failures in Build #95574 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 38266

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

bun-38266 --bun

@robobun

robobun commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. Diff is docs/runtime/bunfig.mdx, docs/snippets/cli/run.mdx and the four --loader descriptions in completions/bun.zsh; no source changes.

How the stale entries were confirmed: mapped a made-up extension to every name in LOADER_NAMES from a bunfig.toml, imported one fixture per extension at runtime and bundled one entry per extension with bun build --target bun, then repeated the runtime run with --loader flags under bun run and bun test. yaml, json5, xml, md, html and sqlite work from every one of those places; base64 and dataurl produce an empty module in the bundler and fall back to the file loader at runtime. Per-name table in the PR description.

Related PRs, so the lists can be kept in step: #38270 updates the matching --help string and tests it; #38247 makes jsonc and sqlite_embedded work (add both to these lists when it lands); #36327 / #36334 implement base64 and dataurl (same); #35443 owns completions/bun.bash, whose --loader branch is unreachable with the default COMP_WORDBREAKS and whose generator template still carries the old six-name list.

CI: the only red tests across the two runs so far (test/js/third_party/astro/astro-post.test.js and test/integration/vite-build/vite-build.test.ts on macOS aarch64, test/bake/deinitialization.test.ts on Windows x64) are crashes that also occur on main (build 95095) and do not involve anything this PR touches; they have been reported separately.

@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 — docs-only update, the new loader list matches LOADER_NAMES in src/ast/loader.rs and the exclusions (jsonc, sqlite_embedded, sh, base64, dataurl, aliases) are each justified in the PR description. The inline nit about Arguments.rs / bun.zsh is a worthwhile follow-up but non-blocking; the two files touched here are strictly more accurate than before.

Extended reasoning...

Overview

This PR updates two hand-maintained copies of the "valid loader names" list in the docs: docs/runtime/bunfig.mdx (the [loader] section) and docs/snippets/cli/run.mdx (the --loader flag). It replaces a stale 10–13 name list with 17 names that are actually accepted and functional today, and drops base64/dataurl which are accepted but stubbed. No source, test, or type-declaration files are touched.

Security risks

None. Pure documentation prose changes to two .mdx files.

Level of scrutiny

Low. Docs-only, no runtime behavior change, CI green. The main correctness question is whether the new list matches what the code accepts — I cross-checked it against LOADER_NAMES in src/ast/loader.rs:73-103 and every name in the new list is present there and maps to a distinct, working loader. The PR description's per-name verification table and its rationale for each excluded name (jsonc/sqlite_embedded collapse via to_api(), sh maps to file, base64/dataurl are stubs, mjs/cjs/etc. are aliases) all check out against the source.

Other factors

One nit was surfaced: the same stale 10-name list also lives in src/runtime/cli/Arguments.rs:137 (the bun --help text) and four sites in completions/bun.zsh. That's a valid "fix the whole class" observation per REVIEW.md, but it's explicitly a nit — the docs pages this PR touches are strictly correct after the change, and leaving --help stale is no worse than the status quo. It's fine as a follow-up. No prior human reviews or outstanding comments to address.

Comment thread docs/snippets/cli/run.mdx
The zsh descriptions for --loader/-l carried the same stale "Valid
loaders" list as the docs, and the bash completion only offered six of
the names. Both now use the same list as docs/runtime/bunfig.mdx.
@robobun robobun changed the title docs: update the loader name lists for bunfig [loader] and --loader docs, completions: update the loader name lists for bunfig [loader] and --loader Aug 13, 2026
@robobun

robobun commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the review nit in 3ee536a: the four --loader descriptions in completions/bun.zsh and the candidate list in completions/bun.bash now use the same 17 names as the docs. The help string in src/runtime/cli/Arguments.rs is deliberately left to a separate PR (it needs a build and a help-output test); the PR description says so. PR title and description updated to match the current scope.

@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 picking up the zsh and bash completions too. The remaining Arguments.rs help string is noted as a separate follow-up, which is fine for a docs-scoped PR.

What was reviewed:

  • Confirmed the 17-name list matches across all four files and lines up with LOADER_NAMES per the PR's verification table.
  • Checked the bash compgen -W refactor — the loop builds the same word-list shape as before, just longer; leading space is harmless.
  • Verified bun.fish, spec.yaml, and bun-cli.json carry no loader list, so no other completion sites are missed.
Extended reasoning...

Overview

Docs + shell-completion update to the list of valid --loader / bunfig [loader] names. Four files touched: two .mdx docs pages, completions/bun.zsh (four identical description-string substitutions), and completions/bun.bash (the -l|--loader compgen wordlist expanded from 6 to 17 names via a small for-loop). No runtime, bundler, or test code is changed.

Security risks

None. The changes are prose in docs and static word lists in completion scripts; nothing here reaches parsing, evaluation, or the network.

Level of scrutiny

Low. This is a documentation correction backed by empirical verification (the PR description tabulates the runtime and bun build behavior for every name in LOADER_NAMES). The completion-script edits are mechanical string replacements plus a trivial bash loop that produces the same ext:loader word-list shape the old one-liner did.

Other factors

My previous review flagged the stale list in completions/bun.zsh and src/runtime/cli/Arguments.rs. The author responded by updating both zsh and bash completions in commit 3ee536a2, and had already stated that Arguments.rs is being handled separately — reasonable scoping for a PR titled docs: since that file ships in the binary and needs a build. I grepped the remaining completion files (bun.fish, spec.yaml, bun-cli.json) and none carry a loader list, so nothing else is left behind in completions/. No CODEOWNERS entries cover docs/ or completions/.

@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 pulling in the zsh and bash completion sites in 3ee536a.

What was reviewed:

  • Cross-checked all 17 names against LOADER_NAMES in src/ast/loader.rs; each maps to a distinct Loader variant, and the omissions (jsonc, sqlite_embedded, sh, base64, dataurl, aliases) match the stated reasons.
  • Bash --loader completion: the for loop + compgen -W builds the same 17 candidates as before with the wider set; leading space in loaders is harmless to word-splitting.
  • Confirmed no other --loader list lives under completions/ (no fish entry); the remaining Arguments.rs help string is called out for a follow-up PR.
Extended reasoning...

Overview

Docs + shell-completion update to the list of loader names accepted by bunfig.toml [loader] and --loader. Four files touched: docs/runtime/bunfig.mdx (bullet list expanded from 13 → 17 entries, base64/dataurl removed), docs/snippets/cli/run.mdx (inline <code> list for --loader), completions/bun.zsh (four _arguments description strings), and completions/bun.bash (the -l|--loader candidate list rewritten from a hardcoded 6-entry string to a for loop over 17 names). No src/ changes.

Security risks

None. Pure documentation prose and shell-completion metadata; nothing executes with untrusted input, and the loader resolution code path itself is untouched.

Level of scrutiny

Low. The changes are mechanical string-list updates. I verified each of the 17 names against the LOADER_NAMES table in src/ast/loader.rs:73-103 — every listed name is present and maps to a distinct Loader variant. The zsh edits are description text inside [...] (no _arguments syntax change). The bash edit is a straightforward for loop building a whitespace-separated word list for compgen -W; the author reports sourcing the file and driving _bun_completions directly to confirm 17 candidates and correct prefix narrowing.

Other factors

A prior review pass flagged the sibling zsh/bash sites and Arguments.rs; the author addressed the completion files in 3ee536a and explicitly deferred the Arguments.rs help string to a separate PR (it ships in the binary and needs a build + help-output test), which is a reasonable split for a docs-only change. I grepped completions/ for any remaining loader list — nothing else carries one. The bug-hunting system found no issues on this revision.

@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

The in-binary copy of this list (the --loader help string in src/runtime/cli/Arguments.rs) is #38270, with the same 17 names in the same order.

The bash --loader branch only runs when ':' has been removed from
COMP_WORDBREAKS (bash splits ".ext:name" at the colon by default, so prev
is ":" rather than --loader), and completions/bun.bash is about to become
generated output, so the list belongs in that generator instead.

The bunfig list is described as the available loaders rather than the
only accepted values: aliases such as mjs or txt are accepted too, they
are just not listed.
@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Scope update after another pass over the siblings of this list: reverted the completions/bun.bash change in 0749b07. Bash splits .ext:name at the colon with the default COMP_WORDBREAKS, so that branch is never reached unless the user has customised their shell, and #35443 is turning the file into generated output whose template still has the six-name list, which is where the longer list belongs. Also reworded the bunfig sentence to "The available loaders are" since aliases like mjs are accepted too. The PR description now lists every other copy of this list and which PR owns it (#38270 for the --help string, #38247 for adding jsonc and sqlite_embedded once they work).

@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 — docs and zsh-completion description strings only; the 17 loader names match LOADER_NAMES in src/ast/loader.rs, and the earlier sibling-site nit was addressed (zsh in 3ee536a, Arguments.rs split out to #38270). The one remaining nit is prose in the PR description, not the diff.

Extended reasoning...

Overview

Updates three hand-maintained copies of the "valid loader names" list to reflect loaders added since the list was last touched (yaml, json5, xml, md, html, sqlite) and removes two stubs (base64, dataurl) that don't do what their names say today:

  • docs/runtime/bunfig.mdx — the [loader] section's bulleted list
  • docs/snippets/cli/run.mdx — the --loader flag description
  • completions/bun.zsh — four --loader/-l description strings (inside [...] — display text only, not completion candidates)

No source, no runtime code, no tests changed. I cross-checked all 17 names against LOADER_NAMES in src/ast/loader.rs:73-103; every one is present, and the deliberate exclusions (jsonc, sqlite_embedded, sh, base64, dataurl, aliases) each have a stated reason in the PR body tied to how to_api() collapses them.

Security risks

None. Documentation prose and zsh help strings; nothing executable, nothing user-input-driven.

Level of scrutiny

Low. The zsh edits sit entirely inside _arguments description brackets, so they can't change what completes — only what the help line reads. The mdx changes are prose lists. No CODEOWNERS entry covers docs/ or completions/. The single CI failure (test/bake/deinitialization.test.ts segfault on Windows x64) has no plausible connection to a docs+completions change.

Other factors

This is my second pass. My earlier nit (same stale list in completions/bun.zsh and Arguments.rs) was addressed: the four zsh sites were updated in 3ee536a, and Arguments.rs was intentionally split out to #38270 with the reason stated in the description. 0749b07 then dropped the completions/bun.bash hunk (per its commit message, the branch only fires with a non-default COMP_WORDBREAKS and the file is about to become generated). The one finding this run is that the PR description still mentions the reverted bash change — that's description prose, not the diff, and doesn't affect what merges.

Comment thread completions/bun.zsh

This branch has not been deployed

No deployments
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.

1 participant