Repository navigation
Conversation
Sort importers by reverse exec order (entries first) instead of discovery order, so first Import vs Require promotion of ExportsKind::None is stable across async load completion. Tie-break by stable id. Validation: cargo test exports_kind_stable_across_discovery_order fail-before 101 (Esm vs Cjs mismatch) / pass-after 0 (byte-equal, setup-once x4 via node, swapped entry); cjs_compat 53 passed, 0 failed.
Validation: current-main deterministic regression passed, 56 CJS compatibility checks passed, cargo fmt --all --check passed.
Move the load-hook constant before statements for pedantic Clippy. Reverse execution order deterministically visits the require entry before static import entries in the mixed exportless-module fixture; record the resulting CommonJS wrapper and namespace interop instead of stale ESM shim warnings. Validation: discovery-order regression passed with byte equality and setup-once for both entry orders; 56 CJS compatibility cases passed; affected fixture passed without snapshot updates; focused integration Clippy and cargo fmt passed. Fresh source binding public barrier probe produced identical 899-byte bundles with one setup execution. Executed affected fixture output: one initialization, shared default exports, missing x/y undefined, invalid function calls throw TypeError.
Validation: regenerated and passed the affected esbuild fixture on main e3355e0 plus the existing fix. Existing discovery-order regression is being checked before push. No promotion algorithm changes.
Member
|
In your Since #11271, that choice also decides its top-level #11633 makes such a module CommonJS whenever it is required, as esbuild does, and keeps your load-order test in a shorter form. Closing this in favor of #11633. Thanks for working on this! |
hyfdev
added a commit
that referenced
this pull request
Nov 11, 2026
…orted and required (#11633) A file without module syntax that is both imported and required was ESM in some builds and CommonJS in others. This PR makes it CommonJS in every build, as esbuild does. ```js // main.js import './umd.js' import { value } from './reader.js' // reader.js exports.value = require('./umd.js').value // umd.js ;(function (root) { root.value = 1 })(this) ``` Before, this bundle threw `TypeError: Cannot set properties of undefined`, because `umd.js` became ESM and its top-level `this` was `undefined`. After, `umd.js` is CommonJS and `this` is its exports object, as in Node. The link stage classified such a file by the first importer it visited: `import` made it ESM, `require()` made it CommonJS. That order follows load completion, so it can change between builds: in a fixture whose two importers load in parallel, 98 of 200 builds gave ESM. Now every such file that is required, or loaded by `import()` with code splitting disabled, becomes CommonJS before that walk. Two snapshots change to the CommonJS wrapper. In the esbuild-ported `import_missing_neither_es6_nor_common_js`, esbuild also makes `foo.js` CommonJS. The test that forces both load orders comes from #11225. Co-authored-by: Nate Wienert <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Async module discovery can change which importer first promotes an exportless module. An ESM import and a CommonJS require can then produce different wrappers for identical inputs.
Order importers by reverse deterministic execution order, with stable module IDs breaking ties. The Notify regression forces opposite discovery orders without sleeps, asserts raw byte equality, and executes each bundle to check setup runs once. It repeats with swapped source import order.
This also changes the existing
import_missing_neither_es6_nor_common_jsfixture: reverse execution order visits its require entry before its static import entries, promoting the exportless module to CommonJS. The updated snapshot records a memoized CommonJS wrapper and namespace interop, replacing the former ESM shim warnings. Its actual emitted output was executed: initialization runs once, require returns an empty object, static and dynamic namespaces share that default object, missing x/y remain undefined, and the fixture's invalid function calls throw TypeError. This observable namespace classification change needs maintainer review before merge.Validation on the PR source plus CI repairs:
NAPI_RS_NATIVE_LIBRARY_PATH.The repair preserves the existing bot commit and does not change the promotion algorithm further. Full CI remains with the CI owner; current-source independent review and broader downstream qualification remain pending. This is separate from #11206 and #11227. No downstream dependency or package publication is included.
AI assistance was used to implement and qualify this change. This PR remains a draft.
Maintenance update: merged current main e3355e0 with a normal merge, preserving the existing fix and history. Regenerated the owning fixture for the current output-comment format. The fixture passes with
INSTA_UPDATE=no, andcargo test -p rolldown --test integration exports_kind_stable_across_discovery_order -- --nocapturepasses, including byte equality, one setup execution, and the swapped-entry control. No promotion algorithm changes. AI assistance was used for this maintenance.