webpack 5.26.1 → 5.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/lib/MultiCompiler.js +54 -13
- package/lib/NormalModule.js +26 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/Template.js +3 -1
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +19 -3
- package/lib/javascript/CommonJsChunkFormatPlugin.js +8 -1
- package/lib/javascript/JavascriptModulesPlugin.js +1 -1
- package/lib/javascript/StartupHelpers.js +26 -5
- package/package.json +1 -1
- package/types.d.ts +1 -0
package/lib/MultiCompiler.js
CHANGED
@@ -318,7 +318,18 @@ module.exports = class MultiCompiler {
|
|
318
318
|
* @returns {SetupResult[]} result of setup
|
319
319
|
*/
|
320
320
|
_runGraph(setup, run, callback) {
|
321
|
-
/** @typedef {{ compiler: Compiler, result: Stats, state: "blocked" | "queued" | "running" | "done", children: Node[], parents: Node[] }} Node */
|
321
|
+
/** @typedef {{ compiler: Compiler, result: Stats, state: "pending" | "blocked" | "queued" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
|
322
|
+
|
323
|
+
// State transitions for nodes:
|
324
|
+
// -> blocked (initial)
|
325
|
+
// blocked -> queued [add to queue] (when all parents done)
|
326
|
+
// queued -> running [running++] (when processing the queue)
|
327
|
+
// running -> done [running--] (when compilation is done)
|
328
|
+
// done -> pending (when invalidated from file change)
|
329
|
+
// pending -> blocked (when invalidated from aggregated changes)
|
330
|
+
// done -> blocked (when invalidated, from parent invalidation)
|
331
|
+
// running -> running-outdated (when invalidated, either from change or parent invalidation)
|
332
|
+
// running-outdated -> blocked [running--] (when compilation is done)
|
322
333
|
|
323
334
|
/** @type {Node[]} */
|
324
335
|
const nodes = this.compilers.map(compiler => ({
|
@@ -376,13 +387,12 @@ module.exports = class MultiCompiler {
|
|
376
387
|
running--;
|
377
388
|
if (node.state === "running") {
|
378
389
|
node.state = "done";
|
379
|
-
|
380
|
-
|
381
|
-
if (child.state !== "blocked") continue;
|
382
|
-
if (child.parents.every(p => p.state === "done")) {
|
383
|
-
child.state = "queued";
|
384
|
-
queue.enqueue(child);
|
390
|
+
for (const child of node.children) {
|
391
|
+
checkUnblocked(child);
|
385
392
|
}
|
393
|
+
} else if (node.state === "running-outdated") {
|
394
|
+
node.state = "blocked";
|
395
|
+
checkUnblocked(node);
|
386
396
|
}
|
387
397
|
process.nextTick(processQueue);
|
388
398
|
};
|
@@ -390,12 +400,28 @@ module.exports = class MultiCompiler {
|
|
390
400
|
* @param {Node} node node
|
391
401
|
* @returns {void}
|
392
402
|
*/
|
393
|
-
const
|
394
|
-
if (node.state === "done"
|
403
|
+
const nodeInvalidFromParent = node => {
|
404
|
+
if (node.state === "done") {
|
395
405
|
node.state = "blocked";
|
406
|
+
} else if (node.state === "running") {
|
407
|
+
node.state = "running-outdated";
|
396
408
|
}
|
397
409
|
for (const child of node.children) {
|
398
|
-
|
410
|
+
nodeInvalidFromParent(child);
|
411
|
+
}
|
412
|
+
};
|
413
|
+
/**
|
414
|
+
* @param {Node} node node
|
415
|
+
* @returns {void}
|
416
|
+
*/
|
417
|
+
const nodeInvalid = node => {
|
418
|
+
if (node.state === "done") {
|
419
|
+
node.state = "pending";
|
420
|
+
} else if (node.state === "running") {
|
421
|
+
node.state = "running-outdated";
|
422
|
+
}
|
423
|
+
for (const child of node.children) {
|
424
|
+
nodeInvalidFromParent(child);
|
399
425
|
}
|
400
426
|
};
|
401
427
|
/**
|
@@ -404,15 +430,26 @@ module.exports = class MultiCompiler {
|
|
404
430
|
*/
|
405
431
|
const nodeChange = node => {
|
406
432
|
nodeInvalid(node);
|
433
|
+
if (node.state === "pending") {
|
434
|
+
node.state = "blocked";
|
435
|
+
}
|
436
|
+
checkUnblocked(node);
|
437
|
+
processQueue();
|
438
|
+
};
|
439
|
+
/**
|
440
|
+
* @param {Node} node node
|
441
|
+
* @returns {void}
|
442
|
+
*/
|
443
|
+
const checkUnblocked = node => {
|
407
444
|
if (
|
408
445
|
node.state === "blocked" &&
|
409
446
|
node.parents.every(p => p.state === "done")
|
410
447
|
) {
|
411
448
|
node.state = "queued";
|
412
449
|
queue.enqueue(node);
|
413
|
-
processQueue();
|
414
450
|
}
|
415
451
|
};
|
452
|
+
|
416
453
|
const setupResults = [];
|
417
454
|
nodes.forEach((node, i) => {
|
418
455
|
setupResults.push(
|
@@ -420,7 +457,7 @@ module.exports = class MultiCompiler {
|
|
420
457
|
node.compiler,
|
421
458
|
i,
|
422
459
|
nodeDone.bind(null, node),
|
423
|
-
() => node.state
|
460
|
+
() => node.state !== "done" && node.state !== "running",
|
424
461
|
() => nodeChange(node),
|
425
462
|
() => nodeInvalid(node)
|
426
463
|
)
|
@@ -434,7 +471,11 @@ module.exports = class MultiCompiler {
|
|
434
471
|
node.state = "running";
|
435
472
|
run(node.compiler, nodeDone.bind(null, node));
|
436
473
|
}
|
437
|
-
if (
|
474
|
+
if (
|
475
|
+
!errored &&
|
476
|
+
running === 0 &&
|
477
|
+
nodes.every(node => node.state === "done")
|
478
|
+
) {
|
438
479
|
const stats = [];
|
439
480
|
for (const node of nodes) {
|
440
481
|
const result = node.result;
|
package/lib/NormalModule.js
CHANGED
@@ -37,7 +37,7 @@ const {
|
|
37
37
|
} = require("./util/comparators");
|
38
38
|
const createHash = require("./util/createHash");
|
39
39
|
const { join } = require("./util/fs");
|
40
|
-
const { contextify } = require("./util/identifier");
|
40
|
+
const { contextify, absolutify } = require("./util/identifier");
|
41
41
|
const makeSerializable = require("./util/makeSerializable");
|
42
42
|
const memoize = require("./util/memoize");
|
43
43
|
|
@@ -441,6 +441,30 @@ class NormalModule extends Module {
|
|
441
441
|
}
|
442
442
|
};
|
443
443
|
};
|
444
|
+
const getAbsolutify = memoize(() =>
|
445
|
+
absolutify.bindCache(compilation.compiler.root)
|
446
|
+
);
|
447
|
+
const getAbsolutifyInContext = memoize(() =>
|
448
|
+
absolutify.bindContextCache(this.context, compilation.compiler.root)
|
449
|
+
);
|
450
|
+
const getContextify = memoize(() =>
|
451
|
+
contextify.bindCache(compilation.compiler.root)
|
452
|
+
);
|
453
|
+
const getContextifyInContext = memoize(() =>
|
454
|
+
contextify.bindContextCache(this.context, compilation.compiler.root)
|
455
|
+
);
|
456
|
+
const utils = {
|
457
|
+
absolutify: (context, request) => {
|
458
|
+
return context === this.context
|
459
|
+
? getAbsolutifyInContext()(request)
|
460
|
+
: getAbsolutify()(context, request);
|
461
|
+
},
|
462
|
+
contextify: (context, request) => {
|
463
|
+
return context === this.context
|
464
|
+
? getContextifyInContext()(request)
|
465
|
+
: getContextify()(context, request);
|
466
|
+
}
|
467
|
+
};
|
444
468
|
const loaderContext = {
|
445
469
|
version: 2,
|
446
470
|
getOptions: schema => {
|
@@ -553,6 +577,7 @@ class NormalModule extends Module {
|
|
553
577
|
}
|
554
578
|
this.buildInfo.buildDependencies.add(dep);
|
555
579
|
},
|
580
|
+
utils,
|
556
581
|
rootContext: options.context,
|
557
582
|
webpack: true,
|
558
583
|
sourceMap: !!this.useSourceMap,
|
@@ -597,7 +597,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
597
597
|
}
|
598
598
|
|
599
599
|
// resource without scheme and without path
|
600
|
-
else if (/^(
|
600
|
+
else if (/^($|\?)/.test(unresolvedResource)) {
|
601
601
|
resourceData = {
|
602
602
|
resource: unresolvedResource,
|
603
603
|
data: {},
|
package/lib/RecordIdsPlugin.js
CHANGED
@@ -213,6 +213,7 @@ class RecordIdsPlugin {
|
|
213
213
|
}
|
214
214
|
if (records.chunks.bySource) {
|
215
215
|
for (const chunk of chunks) {
|
216
|
+
if (chunk.id !== null) continue;
|
216
217
|
const sources = getChunkSources(chunk);
|
217
218
|
for (const source of sources) {
|
218
219
|
const id = records.chunks.bySource[source];
|
package/lib/Template.js
CHANGED
@@ -349,7 +349,7 @@ class Template {
|
|
349
349
|
|
350
350
|
/**
|
351
351
|
* @param {RuntimeModule[]} runtimeModules array of runtime modules in order
|
352
|
-
* @param {RenderContext & { codeGenerationResults?: CodeGenerationResults }} renderContext render context
|
352
|
+
* @param {RenderContext & { codeGenerationResults?: CodeGenerationResults, useStrict?: boolean }} renderContext render context
|
353
353
|
* @returns {Source} rendered runtime modules in a Source object
|
354
354
|
*/
|
355
355
|
static renderRuntimeModules(runtimeModules, renderContext) {
|
@@ -380,10 +380,12 @@ class Template {
|
|
380
380
|
source.add(runtimeSource);
|
381
381
|
} else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
|
382
382
|
source.add("(() => {\n");
|
383
|
+
if (renderContext.useStrict) source.add('\t"use strict";\n');
|
383
384
|
source.add(new PrefixSource("\t", runtimeSource));
|
384
385
|
source.add("\n})();\n\n");
|
385
386
|
} else {
|
386
387
|
source.add("!function() {\n");
|
388
|
+
if (renderContext.useStrict) source.add('\t"use strict";\n');
|
387
389
|
source.add(new PrefixSource("\t", runtimeSource));
|
388
390
|
source.add("\n}();\n\n");
|
389
391
|
}
|
@@ -10,7 +10,10 @@ const { RuntimeGlobals } = require("..");
|
|
10
10
|
const HotUpdateChunk = require("../HotUpdateChunk");
|
11
11
|
const Template = require("../Template");
|
12
12
|
const { getCompilationHooks } = require("./JavascriptModulesPlugin");
|
13
|
-
const {
|
13
|
+
const {
|
14
|
+
generateEntryStartup,
|
15
|
+
updateHashForEntryStartup
|
16
|
+
} = require("./StartupHelpers");
|
14
17
|
|
15
18
|
/** @typedef {import("../Compiler")} Compiler */
|
16
19
|
|
@@ -80,16 +83,25 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
80
83
|
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
81
84
|
);
|
82
85
|
if (runtimeModules.length > 0 || entries.length > 0) {
|
86
|
+
const strictBailout = hooks.strictRuntimeBailout.call(
|
87
|
+
renderContext
|
88
|
+
);
|
83
89
|
const runtime = new ConcatSource(
|
84
90
|
(runtimeTemplate.supportsArrowFunction()
|
85
91
|
? "__webpack_require__ =>"
|
86
92
|
: "function(__webpack_require__)") +
|
87
93
|
" { // webpackRuntimeModules\n",
|
88
|
-
|
94
|
+
strictBailout
|
95
|
+
? `// runtime can't be in strict mode because ${strictBailout}.\n\n`
|
96
|
+
: '"use strict";\n\n'
|
89
97
|
);
|
90
98
|
if (runtimeModules.length > 0) {
|
91
99
|
runtime.add(
|
92
|
-
Template.renderRuntimeModules(runtimeModules,
|
100
|
+
Template.renderRuntimeModules(runtimeModules, {
|
101
|
+
...renderContext,
|
102
|
+
codeGenerationResults: compilation.codeGenerationResults,
|
103
|
+
useStrict: !!strictBailout
|
104
|
+
})
|
93
105
|
);
|
94
106
|
}
|
95
107
|
if (entries.length > 0) {
|
@@ -131,6 +143,10 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
131
143
|
hash.update(`${runtimeTemplate.outputOptions.chunkLoadingGlobal}`);
|
132
144
|
hash.update(`${runtimeTemplate.outputOptions.hotUpdateGlobal}`);
|
133
145
|
hash.update(`${runtimeTemplate.outputOptions.globalObject}`);
|
146
|
+
const entries = Array.from(
|
147
|
+
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
148
|
+
);
|
149
|
+
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
134
150
|
}
|
135
151
|
);
|
136
152
|
}
|
@@ -12,7 +12,10 @@ const {
|
|
12
12
|
getChunkFilenameTemplate,
|
13
13
|
getCompilationHooks
|
14
14
|
} = require("./JavascriptModulesPlugin");
|
15
|
-
const {
|
15
|
+
const {
|
16
|
+
generateEntryStartup,
|
17
|
+
updateHashForEntryStartup
|
18
|
+
} = require("./StartupHelpers");
|
16
19
|
|
17
20
|
/** @typedef {import("../Compiler")} Compiler */
|
18
21
|
|
@@ -156,6 +159,10 @@ class CommonJsChunkFormatPlugin {
|
|
156
159
|
if (chunk.hasRuntime()) return;
|
157
160
|
hash.update("CommonJsChunkFormatPlugin");
|
158
161
|
hash.update("1");
|
162
|
+
const entries = Array.from(
|
163
|
+
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
164
|
+
);
|
165
|
+
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
159
166
|
}
|
160
167
|
);
|
161
168
|
}
|
@@ -583,7 +583,7 @@ class JavascriptModulesPlugin {
|
|
583
583
|
if (strictBailout) {
|
584
584
|
source.add(
|
585
585
|
prefix +
|
586
|
-
`// runtime can't be in strict mode because ${strictBailout}
|
586
|
+
`// runtime can't be in strict mode because ${strictBailout}.\n`
|
587
587
|
);
|
588
588
|
} else {
|
589
589
|
allStrict = true;
|
@@ -11,6 +11,7 @@ const Template = require("../Template");
|
|
11
11
|
const { isSubset } = require("../util/SetHelpers");
|
12
12
|
const { chunkHasJs } = require("./JavascriptModulesPlugin");
|
13
13
|
|
14
|
+
/** @typedef {import("../util/Hash")} Hash */
|
14
15
|
/** @typedef {import("../Chunk")} Chunk */
|
15
16
|
/** @typedef {import("../Compilation")} Compilation */
|
16
17
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
@@ -71,21 +72,24 @@ exports.generateEntryStartup = (
|
|
71
72
|
return `__webpack_exec__(${JSON.stringify(id)})`;
|
72
73
|
};
|
73
74
|
const outputCombination = (chunks, moduleIds, final) => {
|
74
|
-
const old = final ? "undefined" : "0";
|
75
|
-
const prefix = final ? EXPORT_PREFIX : "";
|
76
75
|
if (chunks.size === 0) {
|
77
|
-
runtime.push(
|
76
|
+
runtime.push(
|
77
|
+
`${final ? EXPORT_PREFIX : ""}(${moduleIds.map(runModule).join(", ")});`
|
78
|
+
);
|
78
79
|
} else {
|
79
80
|
const fn = runtimeTemplate.returningFunction(
|
80
81
|
moduleIds.map(runModule).join(", ")
|
81
82
|
);
|
82
83
|
runtime.push(
|
83
|
-
`${
|
84
|
+
`${final && !passive ? EXPORT_PREFIX : ""}${
|
84
85
|
passive
|
85
86
|
? RuntimeGlobals.onChunksLoaded
|
86
87
|
: RuntimeGlobals.startupEntrypoint
|
87
|
-
}(
|
88
|
+
}(0, ${JSON.stringify(Array.from(chunks, c => c.id))}, ${fn});`
|
88
89
|
);
|
90
|
+
if (final && passive) {
|
91
|
+
runtime.push(`${EXPORT_PREFIX}${RuntimeGlobals.onChunksLoaded}();`);
|
92
|
+
}
|
89
93
|
}
|
90
94
|
};
|
91
95
|
|
@@ -119,6 +123,23 @@ exports.generateEntryStartup = (
|
|
119
123
|
return Template.asString(runtime);
|
120
124
|
};
|
121
125
|
|
126
|
+
/**
|
127
|
+
* @param {Hash} hash the hash to update
|
128
|
+
* @param {ChunkGraph} chunkGraph chunkGraph
|
129
|
+
* @param {import("../ChunkGraph").EntryModuleWithChunkGroup[]} entries entries
|
130
|
+
* @param {Chunk} chunk chunk
|
131
|
+
* @returns {void}
|
132
|
+
*/
|
133
|
+
exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
|
134
|
+
for (const [module, entrypoint] of entries) {
|
135
|
+
const runtimeChunk = entrypoint.getRuntimeChunk();
|
136
|
+
const moduleId = chunkGraph.getModuleId(module);
|
137
|
+
hash.update(`${moduleId}`);
|
138
|
+
for (const c of getAllChunks(entrypoint, chunk, runtimeChunk))
|
139
|
+
hash.update(`${c.id}`);
|
140
|
+
}
|
141
|
+
};
|
142
|
+
|
122
143
|
/**
|
123
144
|
* @param {Chunk} chunk the chunk
|
124
145
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.27.1",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
package/types.d.ts
CHANGED
@@ -10620,6 +10620,7 @@ declare class Template {
|
|
10620
10620
|
runtimeModules: RuntimeModule[],
|
10621
10621
|
renderContext: RenderContextModuleTemplate & {
|
10622
10622
|
codeGenerationResults?: CodeGenerationResults;
|
10623
|
+
useStrict?: boolean;
|
10623
10624
|
}
|
10624
10625
|
): Source;
|
10625
10626
|
static renderChunkRuntimeModules(
|