Fix ESM <> CJS dual-package hazard determinism bug (#22231)

### What does this PR do?

Originally, we attempted to avoid the "dual package hazard" right before
we enqueue a parse task, but that code gets called in a
non-deterministic order. This meant that some of your modules would use
the right variant and some of them would not.

We have to instead do that in a separate pass, after all the files are
parsed.

The thing to watch out for with this PR is how it impacts the dev
server.

### How did you verify your code works?

Unskipped tests. Plus manual.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2025-08-30 02:50:35 -07:00
committed by GitHub
parent 35e9f3d4a2
commit b93468ca48
10 changed files with 227 additions and 82 deletions

View File

@@ -793,7 +793,7 @@ describe("bundler", () => {
stdout: "main",
},
});
itBundled.skip("packagejson/DualPackageHazardImportAndRequireSameFile", {
itBundled("packagejson/DualPackageHazardImportAndRequireSameFile", {
files: {
"/Users/user/project/src/entry.js": /* js */ `
import value from 'demo-pkg'
@@ -812,7 +812,7 @@ describe("bundler", () => {
stdout: "main main",
},
});
itBundled.skip("packagejson/DualPackageHazardImportAndRequireSeparateFiles", {
itBundled("packagejson/DualPackageHazardImportAndRequireSeparateFiles", {
files: {
"/Users/user/project/src/entry.js": /* js */ `
import './test-main'
@@ -861,7 +861,7 @@ describe("bundler", () => {
stdout: "module\nmodule",
},
});
itBundled.skip("packagejson/DualPackageHazardImportAndRequireImplicitMain", {
itBundled("packagejson/DualPackageHazardImportAndRequireImplicitMain", {
files: {
"/Users/user/project/src/entry.js": /* js */ `
import './test-index'