Skip to content

Commit b2f8440

Browse files
fix: observe every async entry together, and gate the cases on Node.js 14.8
Awaiting the entries one by one leaves the rest unobserved once one rejects, so a second failing entry became an unhandled rejection. Await them in a single `Promise.all`. The two cases need top-level await, which the runner's `vm.SourceTextModule` cannot parse before Node.js 14.8, and both fixtures now settle on a task so they fail when startup returns too early.
1 parent d5a4fca commit b2f8440

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎lib/javascript/JavascriptModulesPlugin.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,9 +1872,12 @@ class JavascriptModulesPlugin {
18721872
`${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});`
18731873
);
18741874
}
1875-
// After the loop, so entries still start in parallel.
1876-
for (const target of awaitedEntries) {
1877-
buf2.push(`${target} = await ${target};`);
1875+
// One `Promise.all` so an entry rejecting first still leaves the
1876+
// others observed, and they all start before anything is awaited.
1877+
if (awaitedEntries.length > 0) {
1878+
buf2.push(
1879+
`[${awaitedEntries.join(", ")}] = await Promise.all([${awaitedEntries.join(", ")}]);`
1880+
);
18781881
}
18791882
if (
18801883
runtimeRequirements.has(RuntimeGlobals.startup) ||
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
globalThis.__firstEntryValue = await Promise.resolve("first");
1+
globalThis.__firstEntryValue = await new Promise((resolve) => {
2+
setTimeout(() => resolve("first"), 0);
3+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
// The entry and the generated startup both use top-level `await`, which the
4+
// runner's `vm.SourceTextModule` cannot parse before Node.js 14.8.
5+
module.exports = function filter() {
6+
const [major, minor] = process.versions.node.split(".").map(Number);
7+
return major > 14 || (major === 14 && minor >= 8);
8+
};

‎test/configCases/module/async-entry-await/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const value = await Promise.resolve(42);
1+
const value = await new Promise((resolve) => {
2+
setTimeout(() => resolve(42), 0);
3+
});
24

35
it("should settle the bundle only after the async entry finished", () => {
46
expect(value).toBe(42);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
// The entry and the generated startup both use top-level `await`, which the
4+
// runner's `vm.SourceTextModule` cannot parse before Node.js 14.8.
5+
module.exports = function filter() {
6+
const [major, minor] = process.versions.node.split(".").map(Number);
7+
return major > 14 || (major === 14 && minor >= 8);
8+
};

0 commit comments

Comments
 (0)