Repository navigation
Conversation
build-fallbacks.ts calls esbuild.build() with the options it gave to
bun build, and runs with cfg.jsRuntime. react-refresh.js moves to the
esbuild rule.
Only the sibling fallback files go in external. platform "node" keeps
the builtin modules external by exact name. An external entry also
matches subpaths, so "util" would leave require("util/") unbundled.
Each output file keeps the same require and import specifiers as
before.
There was a problem hiding this comment.
LGTM — a clean step on the documented codegen_bun → codegen migration.
What was reviewed:
esbuild.build()options map 1:1 to the removedbun buildflags;platform: "node"externalizing builtins by exact name (vs.external's subpath match) is the right call for therequire("util/")case.- The new
codegen/esbuildedges match the existing pattern inemitRuntimeJs/emitBunErrorexactly, includingo.rootInstallfor the root-node_modulesesbuild package. - Checked that
cfg.jsRuntimeunder Node handles the script's top-levelawaitandimportfromsrc/node-fallbacks/(itspackage.jsonhas no"type") — Node's module-syntax detection covers it, and theMODULE_TYPELESS_PACKAGE_JSONwarning is already suppressed inresolveToolchain.
Extended reasoning...
Overview
This PR migrates two emitNodeFallbacks build edges off bun-only tooling: build-fallbacks.ts moves from Bun.$-spawned bun build invocations to programmatic esbuild.build() calls and switches from the codegen_bun rule to codegen (so it runs under cfg.jsRuntime, i.e. node or bun); the react-refresh.js bundle moves from bun build to the existing esbuild rule. Both edges gain o.rootInstall as an implicit input since the esbuild package now resolves from the repo-root node_modules. The externals list in build-fallbacks.ts is trimmed to sibling fallback files only, relying on platform: "node" to externalize node builtins by exact name — avoiding esbuild's documented behavior where an external entry like "util" also matches the "util/" subpath (the npm polyfill).
Security risks
None. This is build-graph plumbing that only affects how the browser polyfill bundles are produced during Bun's own build. There is no auth, crypto, untrusted-input parsing, or network handling in the changed code. The define values, entry points, and output paths are all repo-controlled constants.
Level of scrutiny
Low-to-moderate. The change is small and mechanical, and it directly executes on a goal spelled out in scripts/build/CLAUDE.md ("Move a script to the codegen rule once it runs under node, and check that both runtimes write the same output"). The new edges copy the exact shape of neighboring esbuild-rule edges (emitRuntimeJs, emitBunError), including the o.rootInstall implicit input with the same rationale comment already present at line 426. The one thing worth verifying — that the outputs are functionally equivalent — the author addressed head-on: same import/require specifiers, same bundler test results across bundler_browser/bundler_regressions/bundler_loader, same export names from a bundle pulling in all 23 polyfills, with the residual differences (license-comment retention, minor size deltas, assert property enumerability now matching the upstream npm package) called out explicitly. Any regression here would surface as a hard build failure or a bundler-test failure, not silent corruption.
Other factors
No CODEOWNERS entry covers scripts/build/ or src/node-fallbacks/. The bug hunt ran to completion (dry_streak) with no findings and no ruled-out candidates. There are no prior reviews or unresolved threads on the PR. I confirmed the codegen rule's ${cfg.jsRuntime} $args shape accepts [script, outDir, ...] as passed, and that Node's --experimental-strip-types path (with --disable-warning=MODULE_TYPELESS_PACKAGE_JSON already baked into jsRuntime) will treat the script as ESM via syntax detection despite src/node-fallbacks/package.json lacking "type": "module", so the top-level await and import * as esbuild both work. The esbuild package is not in src/node-fallbacks/package.json, so resolution walks up to the root install — which is exactly what the new o.rootInstall implicit dep gates on.
…c7912907/codegen-fallbacks
…c7912907/codegen-fallbacks
…c7912907/codegen-fallbacks
Stacked on #41314. The diff is against that branch.
Problem
build-fallbacks.tsrunsbun buildthroughBun.$for each file insrc/node-fallbacks. Thereact-refresh.jsedge runsbun buildtoo. So both need bun.Fix
build-fallbacks.tscallsesbuild.build()with the same options, and runs withcfg.jsRuntime. The text fix-ups after the build do not change.external.platform: "node"keeps the builtin modules external by exact name. Anexternalentry also matches subpaths, so"util"would leave therequire("util/")of the npm polyfill unbundled.react-refresh.jsmoves to the existingesbuildrule.requireandimportspecifiers as the bun output. Node and bun write the same files, on Linux and on Windows.Background
bun build --target=browserputs in place of node builtins. Release builds embed them, zstd-compressed.Notes
bundler_browser.test.ts(23 pass),bundler_regressions.test.ts(9 pass), andbundler_loader.test.ts(59 pass). These are the same results as with the old files.name,length, andprototypekeys of theassertdefault export are not enumerable now. That matches the npm package.net.jsis smaller (bun folded the regex template strings).timers.jsandstring_decoder.jsare larger (esbuild's CommonJS helpers).