Skip to content

Commit 07242be

Browse files
authored
Merge branch 'main' into fix-12408
2 parents bfd057c + a9aa422 commit 07242be

33 files changed

+231
-48
lines changed

lib/Compilation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
14361436
* @returns {void}
14371437
*/
14381438
_processModuleDependencies(module, callback) {
1439-
/** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], originModule: Module|null}>} */
1439+
/** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], context: string|undefined, originModule: Module|null}>} */
14401440
const sortedDependencies = [];
14411441

14421442
/** @type {DependenciesBlock} */
@@ -1668,6 +1668,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
16681668
sortedDependencies.push({
16691669
factory: factoryCacheKey2,
16701670
dependencies: list,
1671+
context: dep.getContext(),
16711672
originModule: module
16721673
});
16731674
}

lib/Compiler.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,21 @@ class Compiler {
545545
*/
546546
runAsChild(callback) {
547547
const startTime = Date.now();
548+
549+
const finalCallback = (err, entries, compilation) => {
550+
try {
551+
callback(err, entries, compilation);
552+
} catch (e) {
553+
const err = new WebpackError(
554+
`compiler.runAsChild callback error: ${e}`
555+
);
556+
err.details = e.stack;
557+
this.parentCompilation.errors.push(err);
558+
}
559+
};
560+
548561
this.compile((err, compilation) => {
549-
if (err) return callback(err);
562+
if (err) return finalCallback(err);
550563

551564
this.parentCompilation.children.push(compilation);
552565
for (const { name, source, info } of compilation.getAssets()) {
@@ -561,7 +574,7 @@ class Compiler {
561574
compilation.startTime = startTime;
562575
compilation.endTime = Date.now();
563576

564-
return callback(null, entries, compilation);
577+
return finalCallback(null, entries, compilation);
565578
});
566579
}
567580

lib/ContextModule.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,13 @@ module.exports = webpackEmptyAsyncContext;`;
11041104
)
11051105
);
11061106
const set = new Set();
1107-
const allDeps = /** @type {ContextElementDependency[]} */ (
1108-
this.dependencies.concat(this.blocks.map(b => b.dependencies[0]))
1109-
);
1107+
const allDeps =
1108+
this.dependencies.length > 0
1109+
? /** @type {ContextElementDependency[]} */ (this.dependencies).slice()
1110+
: [];
1111+
for (const block of this.blocks)
1112+
for (const dep of block.dependencies)
1113+
allDeps.push(/** @type {ContextElementDependency} */ (dep));
11101114
set.add(RuntimeGlobals.module);
11111115
set.add(RuntimeGlobals.hasOwnProperty);
11121116
if (allDeps.length > 0) {

lib/ContextModuleFactory.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
292292
} = options;
293293
if (!regExp || !resource) return callback(null, []);
294294

295-
let severalContexts = false;
296295
const addDirectoryChecked = (ctx, directory, visited, callback) => {
297296
fs.realpath(directory, (err, realPath) => {
298297
if (err) return callback(err);
@@ -359,15 +358,13 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
359358
alternatives = alternatives
360359
.filter(obj => regExp.test(obj.request))
361360
.map(obj => {
362-
const request = severalContexts
363-
? join(fs, obj.context, obj.request)
364-
: obj.request;
365361
const dep = new ContextElementDependency(
366-
request + resourceQuery + resourceFragment,
362+
`${obj.request}${resourceQuery}${resourceFragment}`,
367363
obj.request,
368364
typePrefix,
369365
category,
370-
referencedExports
366+
referencedExports,
367+
obj.context
371368
);
372369
dep.optional = true;
373370
return dep;
@@ -414,7 +411,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
414411
if (typeof resource === "string") {
415412
visitResource(resource, callback);
416413
} else {
417-
severalContexts = true;
418414
asyncLib.map(resource, visitResource, (err, result) => {
419415
if (err) return callback(err);
420416

lib/Dependency.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ class Dependency {
182182
this._loc = undefined;
183183
}
184184

185+
/**
186+
* @returns {string | undefined} a request context
187+
*/
188+
getContext() {
189+
return undefined;
190+
}
191+
185192
/**
186193
* @returns {string | null} an identifier to merge equal requests
187194
*/

lib/FileSystemInfo.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"use strict";
77

88
const { create: createResolver } = require("enhanced-resolve");
9+
const nodeModule = require("module");
910
const asyncLib = require("neo-async");
1011
const AsyncQueue = require("./util/AsyncQueue");
1112
const StackedCacheMap = require("./util/StackedCacheMap");
@@ -22,6 +23,8 @@ const processAsyncTree = require("./util/processAsyncTree");
2223

2324
const supportsEsm = +process.versions.modules >= 83;
2425

26+
const builtinModules = new Set(nodeModule.builtinModules);
27+
2528
let FS_ACCURACY = 2000;
2629

2730
const EMPTY_SET = new Set();
@@ -1673,6 +1676,11 @@ class FileSystemInfo {
16731676
// e.g. import.meta
16741677
continue;
16751678
}
1679+
1680+
// we should not track Node.js build dependencies
1681+
if (dependency.startsWith("node:")) continue;
1682+
if (builtinModules.has(dependency)) continue;
1683+
16761684
push({
16771685
type: RBDT_RESOLVE_ESM_FILE,
16781686
context,

lib/cache/PackFileCacheStrategy.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,14 @@ class PackContentItems {
639639
} catch (e) {
640640
rollback(s);
641641
if (e === NOT_SERIALIZABLE) continue;
642-
logger.warn(
643-
`Skipped not serializable cache item '${key}': ${e.message}`
644-
);
645-
logger.debug(e.stack);
642+
const msg = "Skipped not serializable cache item";
643+
if (e.message.includes("ModuleBuildError")) {
644+
logger.log(`${msg} (in build error): ${e.message}`);
645+
logger.debug(`${msg} '${key}' (in build error): ${e.stack}`);
646+
} else {
647+
logger.warn(`${msg}: ${e.message}`);
648+
logger.debug(`${msg} '${key}': ${e.stack}`);
649+
}
646650
}
647651
}
648652
write(null);

lib/dependencies/ContextElementDependency.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,27 @@ const ModuleDependency = require("./ModuleDependency");
1414
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
1515

1616
class ContextElementDependency extends ModuleDependency {
17-
constructor(request, userRequest, typePrefix, category, referencedExports) {
17+
/**
18+
* @param {string} request request
19+
* @param {string|undefined} userRequest user request
20+
* @param {string} typePrefix type prefix
21+
* @param {string} category category
22+
* @param {string[][]=} referencedExports referenced exports
23+
* @param {string=} context context
24+
*/
25+
constructor(
26+
request,
27+
userRequest,
28+
typePrefix,
29+
category,
30+
referencedExports,
31+
context
32+
) {
1833
super(request);
1934
this.referencedExports = referencedExports;
2035
this._typePrefix = typePrefix;
2136
this._category = category;
37+
this._context = context || undefined;
2238

2339
if (userRequest) {
2440
this.userRequest = userRequest;
@@ -33,6 +49,20 @@ class ContextElementDependency extends ModuleDependency {
3349
return "context element";
3450
}
3551

52+
/**
53+
* @returns {string | undefined} a request context
54+
*/
55+
getContext() {
56+
return this._context;
57+
}
58+
59+
/**
60+
* @returns {string | null} an identifier to merge equal requests
61+
*/
62+
getResourceIdentifier() {
63+
return `context${this._context || ""}|${super.getResourceIdentifier()}`;
64+
}
65+
3666
get category() {
3767
return this._category;
3868
}
@@ -56,6 +86,7 @@ class ContextElementDependency extends ModuleDependency {
5686
const { write } = context;
5787
write(this._typePrefix);
5888
write(this._category);
89+
write(this._context);
5990
write(this.referencedExports);
6091
super.serialize(context);
6192
}
@@ -64,6 +95,7 @@ class ContextElementDependency extends ModuleDependency {
6495
const { read } = context;
6596
this._typePrefix = read();
6697
this._category = read();
98+
this._context = read();
6799
this.referencedExports = read();
68100
super.deserialize(context);
69101
}

lib/hmr/HotModuleReplacement.runtime.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module.exports = function () {
2828
var currentStatus = "idle";
2929

3030
// while downloading
31-
var blockingPromises;
31+
var blockingPromises = 0;
32+
var blockingPromisesWaiting = [];
3233

3334
// The update info
3435
var currentUpdateApplyHandlers;
@@ -218,29 +219,40 @@ module.exports = function () {
218219
return Promise.all(results);
219220
}
220221

222+
function unblock() {
223+
if (--blockingPromises === 0) {
224+
setStatus("ready").then(function () {
225+
if (blockingPromises === 0) {
226+
var list = blockingPromisesWaiting;
227+
blockingPromisesWaiting = [];
228+
for (var i = 0; i < list.length; i++) {
229+
list[i]();
230+
}
231+
}
232+
});
233+
}
234+
}
235+
221236
function trackBlockingPromise(promise) {
222237
switch (currentStatus) {
223238
case "ready":
224239
setStatus("prepare");
225-
blockingPromises.push(promise);
226-
waitForBlockingPromises(function () {
227-
return setStatus("ready");
228-
});
229-
return promise;
240+
/* fallthrough */
230241
case "prepare":
231-
blockingPromises.push(promise);
242+
blockingPromises++;
243+
promise.then(unblock, unblock);
232244
return promise;
233245
default:
234246
return promise;
235247
}
236248
}
237249

238250
function waitForBlockingPromises(fn) {
239-
if (blockingPromises.length === 0) return fn();
240-
var blocker = blockingPromises;
241-
blockingPromises = [];
242-
return Promise.all(blocker).then(function () {
243-
return waitForBlockingPromises(fn);
251+
if (blockingPromises === 0) return fn();
252+
return new Promise(function (resolve) {
253+
blockingPromisesWaiting.push(function () {
254+
resolve(fn());
255+
});
244256
});
245257
}
246258

@@ -261,7 +273,6 @@ module.exports = function () {
261273

262274
return setStatus("prepare").then(function () {
263275
var updatedModules = [];
264-
blockingPromises = [];
265276
currentUpdateApplyHandlers = [];
266277

267278
return Promise.all(
@@ -298,7 +309,11 @@ module.exports = function () {
298309
function hotApply(options) {
299310
if (currentStatus !== "ready") {
300311
return Promise.resolve().then(function () {
301-
throw new Error("apply() is only allowed in ready status");
312+
throw new Error(
313+
"apply() is only allowed in ready status (state: " +
314+
currentStatus +
315+
")"
316+
);
302317
});
303318
}
304319
return internalApply(options);

lib/hmr/JavascriptHotModuleReplacement.runtime.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,16 @@ module.exports = function () {
443443
) {
444444
promises.push($loadUpdateChunk$(chunkId, updatedModulesList));
445445
currentUpdateChunks[chunkId] = true;
446+
} else {
447+
currentUpdateChunks[chunkId] = false;
446448
}
447449
});
448450
if ($ensureChunkHandlers$) {
449451
$ensureChunkHandlers$.$key$Hmr = function (chunkId, promises) {
450452
if (
451453
currentUpdateChunks &&
452-
!$hasOwnProperty$(currentUpdateChunks, chunkId) &&
453-
$hasOwnProperty$($installedChunks$, chunkId) &&
454-
$installedChunks$[chunkId] !== undefined
454+
$hasOwnProperty$(currentUpdateChunks, chunkId) &&
455+
!currentUpdateChunks[chunkId]
455456
) {
456457
promises.push($loadUpdateChunk$(chunkId));
457458
currentUpdateChunks[chunkId] = true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy