webpack 5.51.2 → 5.54.0
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/AsyncDependenciesBlock.js +9 -2
- package/lib/CacheFacade.js +10 -3
- package/lib/ChunkGraph.js +19 -8
- package/lib/CodeGenerationResults.js +7 -2
- package/lib/Compilation.js +207 -16
- package/lib/Compiler.js +9 -1
- package/lib/DependencyTemplates.js +8 -2
- package/lib/EvalDevToolModulePlugin.js +2 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +36 -18
- package/lib/FileSystemInfo.js +101 -170
- package/lib/FlagDependencyExportsPlugin.js +43 -16
- package/lib/InitFragment.js +23 -0
- package/lib/JavascriptMetaInfoPlugin.js +6 -1
- package/lib/MemCache.js +45 -0
- package/lib/ModuleFilenameHelpers.js +21 -7
- package/lib/NodeStuffInWebError.js +34 -0
- package/lib/NodeStuffPlugin.js +59 -16
- package/lib/NormalModuleFactory.js +7 -4
- package/lib/SourceMapDevToolPlugin.js +7 -3
- package/lib/WebpackOptionsApply.js +20 -4
- package/lib/cache/PackFileCacheStrategy.js +183 -53
- package/lib/cache/getLazyHashedEtag.js +35 -8
- package/lib/config/defaults.js +32 -13
- package/lib/dependencies/CachedConstDependency.js +4 -3
- package/lib/dependencies/ConstDependency.js +12 -4
- package/lib/dependencies/JsonExportsDependency.js +7 -1
- package/lib/dependencies/LoaderPlugin.js +94 -98
- package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
- package/lib/dependencies/ProvidedDependency.js +6 -2
- package/lib/dependencies/PureExpressionDependency.js +5 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
- package/lib/ids/IdHelpers.js +21 -8
- package/lib/ids/NamedChunkIdsPlugin.js +3 -0
- package/lib/ids/NamedModuleIdsPlugin.js +3 -1
- package/lib/index.js +6 -0
- package/lib/javascript/BasicEvaluatedExpression.js +3 -0
- package/lib/javascript/JavascriptParser.js +22 -4
- package/lib/javascript/JavascriptParserHelpers.js +0 -2
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +25 -4
- package/lib/optimize/InnerGraph.js +22 -2
- package/lib/optimize/MangleExportsPlugin.js +21 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/serialization/BinaryMiddleware.js +11 -2
- package/lib/serialization/FileMiddleware.js +24 -7
- package/lib/serialization/ObjectMiddleware.js +23 -12
- package/lib/util/createHash.js +10 -0
- package/lib/util/hash/BatchedHash.js +65 -0
- package/lib/util/hash/xxhash64.js +154 -0
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/serialization.js +10 -6
- package/package.json +13 -9
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -5
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.json +20 -2
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.json +4 -2
- package/types.d.ts +166 -17
package/lib/InitFragment.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
9
|
+
const makeSerializable = require("./util/makeSerializable");
|
9
10
|
|
10
11
|
/** @typedef {import("webpack-sources").Source} Source */
|
11
12
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
@@ -123,8 +124,30 @@ class InitFragment {
|
|
123
124
|
return source;
|
124
125
|
}
|
125
126
|
}
|
127
|
+
|
128
|
+
serialize(context) {
|
129
|
+
const { write } = context;
|
130
|
+
|
131
|
+
write(this.content);
|
132
|
+
write(this.stage);
|
133
|
+
write(this.position);
|
134
|
+
write(this.key);
|
135
|
+
write(this.endContent);
|
136
|
+
}
|
137
|
+
|
138
|
+
deserialize(context) {
|
139
|
+
const { read } = context;
|
140
|
+
|
141
|
+
this.content = read();
|
142
|
+
this.stage = read();
|
143
|
+
this.position = read();
|
144
|
+
this.key = read();
|
145
|
+
this.endContent = read();
|
146
|
+
}
|
126
147
|
}
|
127
148
|
|
149
|
+
makeSerializable(InitFragment, "webpack/lib/InitFragment");
|
150
|
+
|
128
151
|
InitFragment.prototype.merge = undefined;
|
129
152
|
|
130
153
|
InitFragment.STAGE_CONSTANTS = 10;
|
@@ -28,7 +28,12 @@ class JavascriptMetaInfoPlugin {
|
|
28
28
|
parser.hooks.call.for("eval").tap("JavascriptMetaInfoPlugin", () => {
|
29
29
|
parser.state.module.buildInfo.moduleConcatenationBailout = "eval()";
|
30
30
|
parser.state.module.buildInfo.usingEval = true;
|
31
|
-
InnerGraph.
|
31
|
+
const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
|
32
|
+
if (currentSymbol) {
|
33
|
+
InnerGraph.addUsage(parser.state, null, currentSymbol);
|
34
|
+
} else {
|
35
|
+
InnerGraph.bailout(parser.state);
|
36
|
+
}
|
32
37
|
});
|
33
38
|
parser.hooks.finish.tap("JavascriptMetaInfoPlugin", () => {
|
34
39
|
let topLevelDeclarations =
|
package/lib/MemCache.js
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WeakTupleMap = require("./util/WeakTupleMap");
|
9
|
+
|
10
|
+
class MemCache {
|
11
|
+
constructor() {
|
12
|
+
this._cache = new WeakTupleMap();
|
13
|
+
}
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @template {any[]} T
|
17
|
+
* @template V
|
18
|
+
* @param {T} args arguments
|
19
|
+
* @returns {V | undefined} cached value
|
20
|
+
*/
|
21
|
+
get(...args) {
|
22
|
+
return this._cache.get(...args);
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @template {[...any[], any]} T
|
27
|
+
* @param {T} args arguments
|
28
|
+
* @returns {void}
|
29
|
+
*/
|
30
|
+
set(...args) {
|
31
|
+
this._cache.set(...args);
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @template {[...any[], (...args: any[]) => V]} T
|
36
|
+
* @template V
|
37
|
+
* @param {T} args arguments
|
38
|
+
* @returns {V} computed value or cached
|
39
|
+
*/
|
40
|
+
provide(...args) {
|
41
|
+
return this._cache.provide(...args);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
module.exports = MemCache;
|
@@ -8,6 +8,11 @@
|
|
8
8
|
const createHash = require("./util/createHash");
|
9
9
|
const memoize = require("./util/memoize");
|
10
10
|
|
11
|
+
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
12
|
+
/** @typedef {import("./Module")} Module */
|
13
|
+
/** @typedef {import("./RequestShortener")} RequestShortener */
|
14
|
+
/** @typedef {typeof import("./util/Hash")} Hash */
|
15
|
+
|
11
16
|
const ModuleFilenameHelpers = exports;
|
12
17
|
|
13
18
|
// TODO webpack 6: consider removing these
|
@@ -53,9 +58,9 @@ const getBefore = (strFn, token) => {
|
|
53
58
|
};
|
54
59
|
};
|
55
60
|
|
56
|
-
const getHash = strFn => {
|
61
|
+
const getHash = (strFn, hashFunction) => {
|
57
62
|
return () => {
|
58
|
-
const hash = createHash(
|
63
|
+
const hash = createHash(hashFunction);
|
59
64
|
hash.update(strFn());
|
60
65
|
const digest = /** @type {string} */ (hash.digest("hex"));
|
61
66
|
return digest.substr(0, 4);
|
@@ -91,10 +96,20 @@ const lazyObject = obj => {
|
|
91
96
|
|
92
97
|
const REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
93
98
|
|
99
|
+
/**
|
100
|
+
*
|
101
|
+
* @param {Module | string} module the module
|
102
|
+
* @param {TODO} options options
|
103
|
+
* @param {Object} contextInfo context info
|
104
|
+
* @param {RequestShortener} contextInfo.requestShortener requestShortener
|
105
|
+
* @param {ChunkGraph} contextInfo.chunkGraph chunk graph
|
106
|
+
* @param {string | Hash} contextInfo.hashFunction the hash function to use
|
107
|
+
* @returns {string} the filename
|
108
|
+
*/
|
94
109
|
ModuleFilenameHelpers.createFilename = (
|
95
|
-
module,
|
110
|
+
module = "",
|
96
111
|
options,
|
97
|
-
{ requestShortener, chunkGraph }
|
112
|
+
{ requestShortener, chunkGraph, hashFunction = "md4" }
|
98
113
|
) => {
|
99
114
|
const opts = {
|
100
115
|
namespace: "",
|
@@ -111,13 +126,12 @@ ModuleFilenameHelpers.createFilename = (
|
|
111
126
|
let identifier;
|
112
127
|
let moduleId;
|
113
128
|
let shortIdentifier;
|
114
|
-
if (module === undefined) module = "";
|
115
129
|
if (typeof module === "string") {
|
116
130
|
shortIdentifier = memoize(() => requestShortener.shorten(module));
|
117
131
|
identifier = shortIdentifier;
|
118
132
|
moduleId = () => "";
|
119
133
|
absoluteResourcePath = () => module.split("!").pop();
|
120
|
-
hash = getHash(identifier);
|
134
|
+
hash = getHash(identifier, hashFunction);
|
121
135
|
} else {
|
122
136
|
shortIdentifier = memoize(() =>
|
123
137
|
module.readableIdentifier(requestShortener)
|
@@ -125,7 +139,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
125
139
|
identifier = memoize(() => requestShortener.shorten(module.identifier()));
|
126
140
|
moduleId = () => chunkGraph.getModuleId(module);
|
127
141
|
absoluteResourcePath = () => module.identifier().split("!").pop();
|
128
|
-
hash = getHash(identifier);
|
142
|
+
hash = getHash(identifier, hashFunction);
|
129
143
|
}
|
130
144
|
const resource = memoize(() => shortIdentifier().split("!").pop());
|
131
145
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("./WebpackError");
|
9
|
+
const makeSerializable = require("./util/makeSerializable");
|
10
|
+
|
11
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
12
|
+
|
13
|
+
class NodeStuffInWebError extends WebpackError {
|
14
|
+
/**
|
15
|
+
* @param {DependencyLocation} loc loc
|
16
|
+
* @param {string} expression expression
|
17
|
+
* @param {string} description description
|
18
|
+
*/
|
19
|
+
constructor(loc, expression, description) {
|
20
|
+
super(
|
21
|
+
`${JSON.stringify(
|
22
|
+
expression
|
23
|
+
)} has been used, it will be undefined in next major version.
|
24
|
+
${description}`
|
25
|
+
);
|
26
|
+
|
27
|
+
this.name = "NodeStuffInWebError";
|
28
|
+
this.loc = loc;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
makeSerializable(NodeStuffInWebError, "webpack/lib/NodeStuffInWebError");
|
33
|
+
|
34
|
+
module.exports = NodeStuffInWebError;
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const NodeStuffInWebError = require("./NodeStuffInWebError");
|
8
9
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
9
10
|
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
10
11
|
const ConstDependency = require("./dependencies/ConstDependency");
|
@@ -44,7 +45,8 @@ class NodeStuffPlugin {
|
|
44
45
|
localOptions = { ...localOptions, ...parserOptions.node };
|
45
46
|
}
|
46
47
|
|
47
|
-
if (localOptions.global) {
|
48
|
+
if (localOptions.global !== false) {
|
49
|
+
const withWarning = localOptions.global === "warn";
|
48
50
|
parser.hooks.expression
|
49
51
|
.for("global")
|
50
52
|
.tap("NodeStuffPlugin", expr => {
|
@@ -55,10 +57,21 @@ class NodeStuffPlugin {
|
|
55
57
|
);
|
56
58
|
dep.loc = expr.loc;
|
57
59
|
parser.state.module.addPresentationalDependency(dep);
|
60
|
+
|
61
|
+
// TODO webpack 6 remove
|
62
|
+
if (withWarning) {
|
63
|
+
parser.state.module.addWarning(
|
64
|
+
new NodeStuffInWebError(
|
65
|
+
dep.loc,
|
66
|
+
"global",
|
67
|
+
"The global namespace object is Node.js feature and doesn't present in browser."
|
68
|
+
)
|
69
|
+
);
|
70
|
+
}
|
58
71
|
});
|
59
72
|
}
|
60
73
|
|
61
|
-
const setModuleConstant = (expressionName, fn) => {
|
74
|
+
const setModuleConstant = (expressionName, fn, warning) => {
|
62
75
|
parser.hooks.expression
|
63
76
|
.for(expressionName)
|
64
77
|
.tap("NodeStuffPlugin", expr => {
|
@@ -69,22 +82,41 @@ class NodeStuffPlugin {
|
|
69
82
|
);
|
70
83
|
dep.loc = expr.loc;
|
71
84
|
parser.state.module.addPresentationalDependency(dep);
|
85
|
+
|
86
|
+
// TODO webpack 6 remove
|
87
|
+
if (warning) {
|
88
|
+
parser.state.module.addWarning(
|
89
|
+
new NodeStuffInWebError(dep.loc, expressionName, warning)
|
90
|
+
);
|
91
|
+
}
|
92
|
+
|
72
93
|
return true;
|
73
94
|
});
|
74
95
|
};
|
75
96
|
|
76
|
-
const setConstant = (expressionName, value) =>
|
77
|
-
setModuleConstant(expressionName, () => value);
|
97
|
+
const setConstant = (expressionName, value, warning) =>
|
98
|
+
setModuleConstant(expressionName, () => value, warning);
|
78
99
|
|
79
100
|
const context = compiler.context;
|
80
101
|
if (localOptions.__filename) {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
102
|
+
switch (localOptions.__filename) {
|
103
|
+
case "mock":
|
104
|
+
setConstant("__filename", "/index.js");
|
105
|
+
break;
|
106
|
+
case "warn-mock":
|
107
|
+
setConstant(
|
108
|
+
"__filename",
|
109
|
+
"/index.js",
|
110
|
+
"The __filename is Node.js feature and doesn't present in browser."
|
111
|
+
);
|
112
|
+
break;
|
113
|
+
case true:
|
114
|
+
setModuleConstant("__filename", module =>
|
115
|
+
relative(compiler.inputFileSystem, context, module.resource)
|
116
|
+
);
|
117
|
+
break;
|
87
118
|
}
|
119
|
+
|
88
120
|
parser.hooks.evaluateIdentifier
|
89
121
|
.for("__filename")
|
90
122
|
.tap("NodeStuffPlugin", expr => {
|
@@ -94,13 +126,24 @@ class NodeStuffPlugin {
|
|
94
126
|
});
|
95
127
|
}
|
96
128
|
if (localOptions.__dirname) {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
129
|
+
switch (localOptions.__dirname) {
|
130
|
+
case "mock":
|
131
|
+
setConstant("__dirname", "/");
|
132
|
+
break;
|
133
|
+
case "warn-mock":
|
134
|
+
setConstant(
|
135
|
+
"__dirname",
|
136
|
+
"/",
|
137
|
+
"The __dirname is Node.js feature and doesn't present in browser."
|
138
|
+
);
|
139
|
+
break;
|
140
|
+
case true:
|
141
|
+
setModuleConstant("__dirname", module =>
|
142
|
+
relative(compiler.inputFileSystem, context, module.context)
|
143
|
+
);
|
144
|
+
break;
|
103
145
|
}
|
146
|
+
|
104
147
|
parser.hooks.evaluateIdentifier
|
105
148
|
.for("__dirname")
|
106
149
|
.tap("NodeStuffPlugin", expr => {
|
@@ -540,15 +540,18 @@ class NormalModuleFactory extends ModuleFactory {
|
|
540
540
|
for (const loader of preLoaders) allLoaders.push(loader);
|
541
541
|
let type = settings.type;
|
542
542
|
if (!type) {
|
543
|
-
|
544
|
-
(matchResourceData && matchResourceData.resource) ||
|
545
|
-
resourceData.resource;
|
543
|
+
let resource;
|
546
544
|
let match;
|
547
545
|
if (
|
548
|
-
|
546
|
+
matchResourceData &&
|
547
|
+
typeof (resource = matchResourceData.resource) === "string" &&
|
549
548
|
(match = /\.webpack\[([^\]]+)\]$/.exec(resource))
|
550
549
|
) {
|
551
550
|
type = match[1];
|
551
|
+
matchResourceData.resource = matchResourceData.resource.slice(
|
552
|
+
0,
|
553
|
+
-type.length - 10
|
554
|
+
);
|
552
555
|
} else {
|
553
556
|
type = "javascript/auto";
|
554
557
|
}
|
@@ -297,7 +297,8 @@ class SourceMapDevToolPlugin {
|
|
297
297
|
},
|
298
298
|
{
|
299
299
|
requestShortener,
|
300
|
-
chunkGraph
|
300
|
+
chunkGraph,
|
301
|
+
hashFunction: compilation.outputOptions.hashFunction
|
301
302
|
}
|
302
303
|
)
|
303
304
|
);
|
@@ -358,7 +359,8 @@ class SourceMapDevToolPlugin {
|
|
358
359
|
},
|
359
360
|
{
|
360
361
|
requestShortener,
|
361
|
-
chunkGraph
|
362
|
+
chunkGraph,
|
363
|
+
hashFunction: compilation.outputOptions.hashFunction
|
362
364
|
}
|
363
365
|
);
|
364
366
|
hasName = usedNamesSet.has(sourceName);
|
@@ -442,7 +444,9 @@ class SourceMapDevToolPlugin {
|
|
442
444
|
const sourceMapContentHash =
|
443
445
|
usesContentHash &&
|
444
446
|
/** @type {string} */ (
|
445
|
-
createHash(
|
447
|
+
createHash(compilation.outputOptions.hashFunction)
|
448
|
+
.update(sourceMapString)
|
449
|
+
.digest("hex")
|
446
450
|
);
|
447
451
|
const pathParams = {
|
448
452
|
chunk,
|
@@ -305,9 +305,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
305
305
|
new RequireJsStuffPlugin().apply(compiler);
|
306
306
|
}
|
307
307
|
new CommonJsPlugin().apply(compiler);
|
308
|
-
new LoaderPlugin({
|
309
|
-
enableExecuteModule: options.experiments.executeModule
|
310
|
-
}).apply(compiler);
|
308
|
+
new LoaderPlugin({}).apply(compiler);
|
311
309
|
if (options.node !== false) {
|
312
310
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
313
311
|
new NodeStuffPlugin(options.node).apply(compiler);
|
@@ -433,7 +431,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
433
431
|
"hashed",
|
434
432
|
"deterministic"
|
435
433
|
).apply(compiler);
|
436
|
-
new HashedModuleIdsPlugin(
|
434
|
+
new HashedModuleIdsPlugin({
|
435
|
+
hashFunction: options.output.hashFunction
|
436
|
+
}).apply(compiler);
|
437
437
|
break;
|
438
438
|
}
|
439
439
|
case "deterministic": {
|
@@ -544,6 +544,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
544
544
|
const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
|
545
545
|
new MemoryCachePlugin().apply(compiler);
|
546
546
|
}
|
547
|
+
if (cacheOptions.cacheUnaffected) {
|
548
|
+
if (!options.experiments.cacheUnaffected) {
|
549
|
+
throw new Error(
|
550
|
+
"'cache.cacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
551
|
+
);
|
552
|
+
}
|
553
|
+
compiler.moduleMemCaches = new WeakMap();
|
554
|
+
}
|
547
555
|
break;
|
548
556
|
}
|
549
557
|
case "filesystem": {
|
@@ -563,6 +571,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
563
571
|
maxGenerations: cacheOptions.maxMemoryGenerations
|
564
572
|
}).apply(compiler);
|
565
573
|
}
|
574
|
+
if (cacheOptions.memoryCacheUnaffected) {
|
575
|
+
if (!options.experiments.cacheUnaffected) {
|
576
|
+
throw new Error(
|
577
|
+
"'cache.memoryCacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
578
|
+
);
|
579
|
+
}
|
580
|
+
compiler.moduleMemCaches = new WeakMap();
|
581
|
+
}
|
566
582
|
switch (cacheOptions.store) {
|
567
583
|
case "pack": {
|
568
584
|
const IdleFileCachePlugin = require("./cache/IdleFileCachePlugin");
|