fix(compile): handle CJS and native addons in --bundle (#34529)
Two things to make `compile --bundle` usable with anything beyond pure-ESM trees. First, the bundler's CJS-from-ESM wrapper hardcodes the absolute path of each CJS module it imports. At runtime the VFS is mounted at a temp dir under `$TMPDIR`, so those paths miss. Rewrite each literal in the bundle output to a runtime-relative resolution against `import.meta.url` so it survives the relocation. Second, when those rewritten requires hit something at runtime — either a CJS dep loaded through the wrapper or a `.node` native addon — the npm tree has to ship in the binary. Detect both signals (the rewrite fired; or `find_native_addon_packages` found a package with a `.node` in the resolved snapshot) and embed the full snapshot in that case. Pure-ESM bundles still skip everything npm and stay tiny. Smoke-tested against chalk (pure ESM, ~17 KB user payload), lodash (CJS, full npm), and `@node-rs/crc32` (native addon, full npm; the addon loads and runs). A spec test under `tests/specs/compile/bundle/native_addon/` exercises the addon path against the existing `@denotest/node-addon` fixture, alongside PR 1's basic test.
B
Bartek Iwańczuk committed
152d722fb0f58ecb1773fea0b1ca80a25d3c5757
Parent: 04dc1ec
Committed by GitHub <noreply@github.com>
on 6/1/2026, 11:10:46 AM