webpack 5.49.0 → 5.51.2
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/README.md +4 -16
- package/bin/webpack.js +0 -0
- package/lib/ChunkGraph.js +75 -1
- package/lib/CompatibilityPlugin.js +21 -4
- package/lib/Compilation.js +10 -1
- package/lib/Compiler.js +7 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/FileSystemInfo.js +660 -191
- package/lib/HotModuleReplacementPlugin.js +14 -0
- package/lib/NormalModule.js +13 -3
- package/lib/Parser.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +2 -1
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/Watching.js +8 -10
- package/lib/config/defaults.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -1
- package/lib/javascript/JavascriptParser.js +2 -0
- package/lib/library/ModuleLibraryPlugin.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -1
- package/lib/optimize/ConcatenatedModule.js +3 -3
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -0
- package/lib/serialization/BinaryMiddleware.js +293 -265
- package/lib/util/fs.js +40 -0
- package/lib/util/identifier.js +26 -8
- package/lib/util/propertyAccess.js +54 -1
- package/lib/wasm-async/{AsyncWasmChunkLoadingRuntimeModule.js → AsyncWasmLoadingRuntimeModule.js} +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -2
- package/lib/web/FetchCompileWasmPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +7 -1
- package/package.json +2 -1
- package/schemas/WebpackOptions.json +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
- package/types.d.ts +63 -9
@@ -495,6 +495,7 @@ class HotModuleReplacementPlugin {
|
|
495
495
|
let newModules;
|
496
496
|
let newRuntimeModules;
|
497
497
|
let newFullHashModules;
|
498
|
+
let newDependentHashModules;
|
498
499
|
let newRuntime;
|
499
500
|
let removedFromRuntime;
|
500
501
|
const currentChunk = find(
|
@@ -521,6 +522,13 @@ class HotModuleReplacementPlugin {
|
|
521
522
|
Array.from(fullHashModules).filter(module =>
|
522
523
|
updatedModules.has(module, currentChunk)
|
523
524
|
);
|
525
|
+
const dependentHashModules =
|
526
|
+
chunkGraph.getChunkDependentHashModulesIterable(currentChunk);
|
527
|
+
newDependentHashModules =
|
528
|
+
dependentHashModules &&
|
529
|
+
Array.from(dependentHashModules).filter(module =>
|
530
|
+
updatedModules.has(module, currentChunk)
|
531
|
+
);
|
524
532
|
removedFromRuntime = subtractRuntime(oldRuntime, newRuntime);
|
525
533
|
} else {
|
526
534
|
// chunk has completely removed
|
@@ -607,6 +615,12 @@ class HotModuleReplacementPlugin {
|
|
607
615
|
newFullHashModules
|
608
616
|
);
|
609
617
|
}
|
618
|
+
if (newDependentHashModules) {
|
619
|
+
chunkGraph.attachDependentHashModules(
|
620
|
+
hotUpdateChunk,
|
621
|
+
newDependentHashModules
|
622
|
+
);
|
623
|
+
}
|
610
624
|
const renderManifest = compilation.getRenderManifest({
|
611
625
|
chunk: hotUpdateChunk,
|
612
626
|
hash: records.hash,
|
package/lib/NormalModule.js
CHANGED
@@ -38,7 +38,11 @@ const {
|
|
38
38
|
} = require("./util/comparators");
|
39
39
|
const createHash = require("./util/createHash");
|
40
40
|
const { join } = require("./util/fs");
|
41
|
-
const {
|
41
|
+
const {
|
42
|
+
contextify,
|
43
|
+
absolutify,
|
44
|
+
makePathsRelative
|
45
|
+
} = require("./util/identifier");
|
42
46
|
const makeSerializable = require("./util/makeSerializable");
|
43
47
|
const memoize = require("./util/memoize");
|
44
48
|
|
@@ -102,7 +106,11 @@ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
|
|
102
106
|
*/
|
103
107
|
const contextifySourceUrl = (context, source, associatedObjectForCache) => {
|
104
108
|
if (source.startsWith("webpack://")) return source;
|
105
|
-
return `webpack://${
|
109
|
+
return `webpack://${makePathsRelative(
|
110
|
+
context,
|
111
|
+
source,
|
112
|
+
associatedObjectForCache
|
113
|
+
)}`;
|
106
114
|
};
|
107
115
|
|
108
116
|
/**
|
@@ -1025,7 +1033,9 @@ class NormalModule extends Module {
|
|
1025
1033
|
|
1026
1034
|
let result;
|
1027
1035
|
try {
|
1028
|
-
|
1036
|
+
const source = this._source.source();
|
1037
|
+
result = this.parser.parse(this._ast || source, {
|
1038
|
+
source,
|
1029
1039
|
current: this,
|
1030
1040
|
module: this,
|
1031
1041
|
compilation: compilation,
|
package/lib/Parser.js
CHANGED
package/lib/RuntimeGlobals.js
CHANGED
@@ -297,6 +297,11 @@ exports.hmrModuleData = "__webpack_require__.hmrD";
|
|
297
297
|
*/
|
298
298
|
exports.hmrInvalidateModuleHandlers = "__webpack_require__.hmrI";
|
299
299
|
|
300
|
+
/**
|
301
|
+
* the prefix for storing state of runtime modules when hmr is enabled
|
302
|
+
*/
|
303
|
+
exports.hmrRuntimeStatePrefix = "__webpack_require__.hmrS";
|
304
|
+
|
300
305
|
/**
|
301
306
|
* the AMD define function
|
302
307
|
*/
|
package/lib/RuntimeModule.js
CHANGED
@@ -44,6 +44,7 @@ class RuntimeModule extends Module {
|
|
44
44
|
/** @type {ChunkGraph} */
|
45
45
|
this.chunkGraph = undefined;
|
46
46
|
this.fullHash = false;
|
47
|
+
this.dependentHash = false;
|
47
48
|
/** @type {string} */
|
48
49
|
this._cachedGeneratedCode = undefined;
|
49
50
|
}
|
@@ -107,7 +108,7 @@ class RuntimeModule extends Module {
|
|
107
108
|
hash.update(this.name);
|
108
109
|
hash.update(`${this.stage}`);
|
109
110
|
try {
|
110
|
-
if (this.fullHash) {
|
111
|
+
if (this.fullHash || this.dependentHash) {
|
111
112
|
// Do not use getGeneratedCode here, because i. e. compilation hash might be not
|
112
113
|
// ready at this point. We will cache it later instead.
|
113
114
|
hash.update(this.generate());
|
@@ -14,7 +14,7 @@ const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOpt
|
|
14
14
|
const createSchemaValidation = require("./util/create-schema-validation");
|
15
15
|
const createHash = require("./util/createHash");
|
16
16
|
const { relative, dirname } = require("./util/fs");
|
17
|
-
const {
|
17
|
+
const { makePathsAbsolute } = require("./util/identifier");
|
18
18
|
|
19
19
|
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
20
20
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -91,7 +91,7 @@ const getTaskForFile = (
|
|
91
91
|
if (!sourceMap || typeof source !== "string") return;
|
92
92
|
const context = compilation.options.context;
|
93
93
|
const root = compilation.compiler.root;
|
94
|
-
const cachedAbsolutify =
|
94
|
+
const cachedAbsolutify = makePathsAbsolute.bindContextCache(context, root);
|
95
95
|
const modules = sourceMap.sources.map(source => {
|
96
96
|
if (!source.startsWith("webpack://")) return source;
|
97
97
|
source = cachedAbsolutify(source.slice(10));
|
package/lib/Watching.js
CHANGED
@@ -419,26 +419,24 @@ class Watching {
|
|
419
419
|
this.compiler.fileTimestamps = undefined;
|
420
420
|
this.compiler.contextTimestamps = undefined;
|
421
421
|
this.compiler.fsStartTime = undefined;
|
422
|
-
const shutdown =
|
423
|
-
this.compiler.
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
for (const cb of closeCallbacks) cb(err);
|
428
|
-
});
|
422
|
+
const shutdown = err => {
|
423
|
+
this.compiler.hooks.watchClose.call();
|
424
|
+
const closeCallbacks = this._closeCallbacks;
|
425
|
+
this._closeCallbacks = undefined;
|
426
|
+
for (const cb of closeCallbacks) cb(err);
|
429
427
|
};
|
430
428
|
if (compilation) {
|
431
429
|
const logger = compilation.getLogger("webpack.Watching");
|
432
430
|
logger.time("storeBuildDependencies");
|
433
431
|
this.compiler.cache.storeBuildDependencies(
|
434
432
|
compilation.buildDependencies,
|
435
|
-
|
433
|
+
err2 => {
|
436
434
|
logger.timeEnd("storeBuildDependencies");
|
437
|
-
shutdown();
|
435
|
+
shutdown(err || err2);
|
438
436
|
}
|
439
437
|
);
|
440
438
|
} else {
|
441
|
-
shutdown();
|
439
|
+
shutdown(err);
|
442
440
|
}
|
443
441
|
};
|
444
442
|
|
package/lib/config/defaults.js
CHANGED
@@ -314,7 +314,7 @@ const applyCacheDefaults = (cache, { name, mode, development }) => {
|
|
314
314
|
);
|
315
315
|
D(cache, "hashAlgorithm", "md4");
|
316
316
|
D(cache, "store", "pack");
|
317
|
-
D(cache, "compression",
|
317
|
+
D(cache, "compression", false);
|
318
318
|
D(cache, "profile", false);
|
319
319
|
D(cache, "idleTimeout", 60000);
|
320
320
|
D(cache, "idleTimeoutForInitialStore", 5000);
|
@@ -1039,7 +1039,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1039
1039
|
ids,
|
1040
1040
|
runtimeRequirements
|
1041
1041
|
),
|
1042
|
-
|
1042
|
+
moduleGraph.isAsync(importedModule)
|
1043
|
+
? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
|
1044
|
+
: InitFragment.STAGE_HARMONY_IMPORTS,
|
1043
1045
|
dep.sourceOrder
|
1044
1046
|
)
|
1045
1047
|
);
|
@@ -1100,7 +1102,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1100
1102
|
initFragments.push(
|
1101
1103
|
new InitFragment(
|
1102
1104
|
`${content}\n/* harmony reexport (unknown) */ ${RuntimeGlobals.definePropertyGetters}(${exportsName}, __WEBPACK_REEXPORT_OBJECT__);\n`,
|
1103
|
-
|
1105
|
+
moduleGraph.isAsync(importedModule)
|
1106
|
+
? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
|
1107
|
+
: InitFragment.STAGE_HARMONY_IMPORTS,
|
1104
1108
|
dep.sourceOrder
|
1105
1109
|
)
|
1106
1110
|
);
|
@@ -76,6 +76,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
76
76
|
const withOnChunkLoad = this._runtimeRequirements.has(
|
77
77
|
RuntimeGlobals.onChunksLoaded
|
78
78
|
);
|
79
|
+
const withHmr = this._runtimeRequirements.has(
|
80
|
+
RuntimeGlobals.hmrDownloadUpdateHandlers
|
81
|
+
);
|
79
82
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
80
83
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
81
84
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
|
@@ -93,6 +96,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
93
96
|
true
|
94
97
|
);
|
95
98
|
|
99
|
+
const stateExpression = withHmr
|
100
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_module`
|
101
|
+
: undefined;
|
102
|
+
|
96
103
|
return Template.asString([
|
97
104
|
withBaseURI
|
98
105
|
? Template.asString([
|
@@ -105,7 +112,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
105
112
|
"// object to store loaded and loading chunks",
|
106
113
|
"// undefined = chunk not loaded, null = chunk preloaded/prefetched",
|
107
114
|
"// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded",
|
108
|
-
|
115
|
+
`var installedChunks = ${
|
116
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
117
|
+
}{`,
|
109
118
|
Template.indent(
|
110
119
|
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 0`).join(
|
111
120
|
",\n"
|
@@ -78,6 +78,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
78
78
|
const result = new ConcatSource(source);
|
79
79
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
80
80
|
const exports = [];
|
81
|
+
const isAsync = moduleGraph.isAsync(module);
|
82
|
+
if (isAsync) {
|
83
|
+
result.add(`__webpack_exports__ = await __webpack_exports__;\n`);
|
84
|
+
}
|
81
85
|
for (const exportInfo of exportsInfo.orderedExports) {
|
82
86
|
if (!exportInfo.provided) continue;
|
83
87
|
const varName = `__webpack_exports__${Template.toIdentifier(
|
@@ -61,6 +61,10 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
61
61
|
false
|
62
62
|
);
|
63
63
|
|
64
|
+
const stateExpression = withHmr
|
65
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`
|
66
|
+
: undefined;
|
67
|
+
|
64
68
|
return Template.asString([
|
65
69
|
withBaseURI
|
66
70
|
? Template.asString([
|
@@ -74,7 +78,9 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
74
78
|
"",
|
75
79
|
"// object to store loaded chunks",
|
76
80
|
'// "0" means "already loaded", Promise means loading',
|
77
|
-
|
81
|
+
`var installedChunks = ${
|
82
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
83
|
+
}{`,
|
78
84
|
Template.indent(
|
79
85
|
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 0`).join(
|
80
86
|
",\n"
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
9
|
const Template = require("../Template");
|
10
|
-
const
|
10
|
+
const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
|
11
11
|
|
12
12
|
/** @typedef {import("../Compiler")} Compiler */
|
13
13
|
|
@@ -93,7 +93,7 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
93
93
|
set.add(RuntimeGlobals.publicPath);
|
94
94
|
compilation.addRuntimeModule(
|
95
95
|
chunk,
|
96
|
-
new
|
96
|
+
new AsyncWasmLoadingRuntimeModule({
|
97
97
|
generateLoadBinaryCode,
|
98
98
|
supportsStreaming: false
|
99
99
|
})
|
@@ -80,7 +80,8 @@ class ReadFileCompileWasmPlugin {
|
|
80
80
|
new WasmChunkLoadingRuntimeModule({
|
81
81
|
generateLoadBinaryCode,
|
82
82
|
supportsStreaming: false,
|
83
|
-
mangleImports: this.options.mangleImports
|
83
|
+
mangleImports: this.options.mangleImports,
|
84
|
+
runtimeRequirements: set
|
84
85
|
})
|
85
86
|
);
|
86
87
|
});
|
@@ -61,6 +61,10 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
61
61
|
true
|
62
62
|
);
|
63
63
|
|
64
|
+
const stateExpression = withHmr
|
65
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_require`
|
66
|
+
: undefined;
|
67
|
+
|
64
68
|
return Template.asString([
|
65
69
|
withBaseURI
|
66
70
|
? Template.asString([
|
@@ -74,7 +78,9 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
74
78
|
"",
|
75
79
|
"// object to store loaded chunks",
|
76
80
|
'// "1" means "loaded", otherwise not loaded yet',
|
77
|
-
|
81
|
+
`var installedChunks = ${
|
82
|
+
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
83
|
+
}{`,
|
78
84
|
Template.indent(
|
79
85
|
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 1`).join(
|
80
86
|
",\n"
|
@@ -23,7 +23,7 @@ const { equals } = require("../util/ArrayHelpers");
|
|
23
23
|
const LazySet = require("../util/LazySet");
|
24
24
|
const { concatComparators, keepOriginalOrder } = require("../util/comparators");
|
25
25
|
const createHash = require("../util/createHash");
|
26
|
-
const
|
26
|
+
const { makePathsRelative } = require("../util/identifier");
|
27
27
|
const makeSerializable = require("../util/makeSerializable");
|
28
28
|
const propertyAccess = require("../util/propertyAccess");
|
29
29
|
const {
|
@@ -1011,13 +1011,13 @@ class ConcatenatedModule extends Module {
|
|
1011
1011
|
}
|
1012
1012
|
|
1013
1013
|
static _createIdentifier(rootModule, modules, associatedObjectForCache) {
|
1014
|
-
const
|
1014
|
+
const cachedMakePathsRelative = makePathsRelative.bindContextCache(
|
1015
1015
|
rootModule.context,
|
1016
1016
|
associatedObjectForCache
|
1017
1017
|
);
|
1018
1018
|
let identifiers = [];
|
1019
1019
|
for (const module of modules) {
|
1020
|
-
identifiers.push(
|
1020
|
+
identifiers.push(cachedMakePathsRelative(module.identifier()));
|
1021
1021
|
}
|
1022
1022
|
identifiers.sort();
|
1023
1023
|
const hash = createHash("md4");
|
@@ -1073,7 +1073,7 @@ module.exports = class SplitChunksPlugin {
|
|
1073
1073
|
"SplitChunksPlugin\n" +
|
1074
1074
|
`Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
|
1075
1075
|
`Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` +
|
1076
|
-
"Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via
|
1076
|
+
"Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependOn).\n" +
|
1077
1077
|
'HINT: You can omit "name" to automatically create a name.\n' +
|
1078
1078
|
"BREAKING CHANGE: webpack < 5 used to allow to use an entrypoint as splitChunk. " +
|
1079
1079
|
"This is no longer allowed when the entrypoint is not a parent of the selected modules.\n" +
|