webpack 5.102.0 → 5.103.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.
- package/README.md +121 -134
- package/lib/ChunkGraph.js +2 -2
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +30 -13
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +3 -1
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +12 -12
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DotenvPlugin.js +457 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +20 -28
- package/lib/ExternalModuleFactoryPlugin.js +10 -8
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +9 -12
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +0 -6
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +419 -121
- package/lib/NormalModule.js +18 -17
- package/lib/NormalModuleFactory.js +75 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +125 -57
- package/lib/SourceMapDevToolPlugin.js +26 -8
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +2 -1
- package/lib/asset/AssetGenerator.js +3 -5
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +82 -76
- package/lib/config/defaults.js +105 -20
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +7 -1
- package/lib/css/CssGenerator.js +283 -57
- package/lib/css/CssLoadingRuntimeModule.js +2 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +86 -40
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +98 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssIcssExportDependency.js +247 -8
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
- package/lib/dependencies/CssIcssImportDependency.js +60 -54
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
- package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
- package/lib/dependencies/CssImportDependency.js +15 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
- package/lib/dependencies/HarmonyImportDependency.js +27 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +10 -4
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +98 -10
- package/lib/dependencies/ImportParserPlugin.js +19 -21
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +1 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +5 -2
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +101 -101
- package/lib/javascript/JavascriptModulesPlugin.js +25 -16
- package/lib/javascript/JavascriptParser.js +143 -39
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +19 -5
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +161 -135
- package/lib/optimize/RealContentHashPlugin.js +5 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/serialization/FileMiddleware.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
- package/lib/util/Hash.js +35 -5
- package/lib/util/comparators.js +4 -3
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +85 -15
- package/lib/util/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- package/lib/util/internalSerializables.js +4 -4
- package/lib/util/jsonParseEvenBetterErrors.js +10 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
- package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/wasm-sync/WebAssemblyParser.js +0 -9
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +28 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +110 -15
- package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +788 -127
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
|
@@ -8,8 +8,12 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
8
8
|
const Template = require("../Template");
|
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
10
10
|
|
|
11
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
12
|
+
/** @typedef {import("../Module").ExportsType} ExportsType */
|
|
13
|
+
/** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
|
-
* @param {
|
|
16
|
+
* @param {ExportsType} exportsType exports type
|
|
13
17
|
* @returns {string} mode
|
|
14
18
|
*/
|
|
15
19
|
function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
|
|
@@ -19,61 +23,81 @@ function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
|
|
|
19
23
|
if (exportsType === "dynamic") return `/* ${exportsType} */ 3`;
|
|
20
24
|
return "";
|
|
21
25
|
}
|
|
26
|
+
|
|
22
27
|
/**
|
|
23
|
-
* @param {import("../ModuleTemplate").RuntimeTemplate} _runtimeTemplate runtimeTemplate
|
|
24
|
-
* @param {import("../Module").ExportsType} exportsType exportsType
|
|
25
28
|
* @param {string} moduleId moduleId
|
|
26
|
-
* @param {
|
|
27
|
-
* @
|
|
29
|
+
* @param {ExportsType} exportsType exportsType
|
|
30
|
+
* @param {(ModuleId | null)[]} asyncDepsIds asyncDepsIds
|
|
31
|
+
* @param {RuntimeRequirements} runtimeRequirements runtime requirements
|
|
32
|
+
* @returns {string} call make optimized deferred namespace object
|
|
28
33
|
*/
|
|
29
34
|
function getOptimizedDeferredModule(
|
|
30
|
-
_runtimeTemplate,
|
|
31
|
-
exportsType,
|
|
32
35
|
moduleId,
|
|
33
|
-
|
|
36
|
+
exportsType,
|
|
37
|
+
asyncDepsIds,
|
|
38
|
+
runtimeRequirements
|
|
34
39
|
) {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`/* ${exportsType} */ get a() {`,
|
|
41
|
-
// if exportsType is "namespace" we can generate the most optimized code,
|
|
42
|
-
// on the second access, we can avoid trigger the getter.
|
|
43
|
-
// we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
|
|
44
|
-
exportsType === "namespace" || exportsType === "dynamic"
|
|
45
|
-
? Template.indent([
|
|
46
|
-
`var exports = ${init};`,
|
|
47
|
-
`${
|
|
48
|
-
exportsType === "dynamic" ? "if (exports.__esModule) " : ""
|
|
49
|
-
}Object.defineProperty(this, "a", { value: exports });`,
|
|
50
|
-
"return exports;"
|
|
51
|
-
])
|
|
52
|
-
: Template.indent([`return ${init};`]),
|
|
53
|
-
isAsync ? "}," : "}",
|
|
54
|
-
isAsync
|
|
55
|
-
? `[${
|
|
56
|
-
RuntimeGlobals.makeDeferredNamespaceObjectSymbol
|
|
57
|
-
}]: ${JSON.stringify(asyncDepsIds.filter((x) => x !== null))}`
|
|
40
|
+
runtimeRequirements.add(RuntimeGlobals.makeOptimizedDeferredNamespaceObject);
|
|
41
|
+
const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
42
|
+
return `${RuntimeGlobals.makeOptimizedDeferredNamespaceObject}(${moduleId}, ${mode}${
|
|
43
|
+
asyncDepsIds.length > 0
|
|
44
|
+
? `, ${JSON.stringify(asyncDepsIds.filter((x) => x !== null))}`
|
|
58
45
|
: ""
|
|
59
|
-
|
|
60
|
-
return Template.asString(["{", Template.indent(props), "}"]);
|
|
46
|
+
})`;
|
|
61
47
|
}
|
|
62
48
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
49
|
+
class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
50
|
+
/**
|
|
51
|
+
* @param {boolean} hasAsyncRuntime if async module is used.
|
|
52
|
+
*/
|
|
53
|
+
constructor(hasAsyncRuntime) {
|
|
54
|
+
super("make optimized deferred namespace object");
|
|
55
|
+
this.hasAsyncRuntime = hasAsyncRuntime;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @returns {string | null} runtime code
|
|
60
|
+
*/
|
|
61
|
+
generate() {
|
|
62
|
+
if (!this.compilation) return null;
|
|
63
|
+
const fn = RuntimeGlobals.makeOptimizedDeferredNamespaceObject;
|
|
64
|
+
const hasAsync = this.hasAsyncRuntime;
|
|
65
|
+
return Template.asString([
|
|
66
|
+
// Note: must be a function (not arrow), because this is used in body!
|
|
67
|
+
`${fn} = function(moduleId, mode${hasAsync ? ", asyncDeps" : ""}) {`,
|
|
68
|
+
Template.indent([
|
|
69
|
+
"// mode: 0 => namespace (esm)",
|
|
70
|
+
"// mode: 1 => default-only (esm strict cjs)",
|
|
71
|
+
"// mode: 2 => default-with-named (esm-cjs compat)",
|
|
72
|
+
"// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
|
|
73
|
+
"var r = this;",
|
|
74
|
+
hasAsync ? "var isAsync = asyncDeps && asyncDeps.length;" : "",
|
|
75
|
+
"var obj = {",
|
|
76
|
+
Template.indent([
|
|
77
|
+
"get a() {",
|
|
78
|
+
Template.indent([
|
|
79
|
+
"var exports = r(moduleId);",
|
|
80
|
+
hasAsync
|
|
81
|
+
? `if(isAsync) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
|
|
82
|
+
: "",
|
|
83
|
+
// if exportsType is "namespace" we can generate the most optimized code,
|
|
84
|
+
// on the second access, we can avoid trigger the getter.
|
|
85
|
+
// we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
|
|
86
|
+
'if(mode == 0 || (mode == 3 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
|
|
87
|
+
"return exports;"
|
|
88
|
+
]),
|
|
89
|
+
"}"
|
|
90
|
+
]),
|
|
91
|
+
"};",
|
|
92
|
+
hasAsync
|
|
93
|
+
? `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps;`
|
|
94
|
+
: "",
|
|
95
|
+
"return obj;"
|
|
96
|
+
]),
|
|
97
|
+
"};"
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
77
101
|
|
|
78
102
|
class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
79
103
|
/**
|
|
@@ -92,8 +116,6 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
92
116
|
const { runtimeTemplate } = this.compilation;
|
|
93
117
|
const fn = RuntimeGlobals.makeDeferredNamespaceObject;
|
|
94
118
|
const hasAsync = this.hasAsyncRuntime;
|
|
95
|
-
const strictError =
|
|
96
|
-
this.compilation.options.output.strictModuleErrorHandling;
|
|
97
119
|
const init = runtimeTemplate.supportsOptionalChaining()
|
|
98
120
|
? "init?.();"
|
|
99
121
|
: "if (init) init();";
|
|
@@ -104,7 +126,18 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
104
126
|
"// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
|
|
105
127
|
"",
|
|
106
128
|
"var cachedModule = __webpack_module_cache__[moduleId];",
|
|
107
|
-
|
|
129
|
+
"if (cachedModule && cachedModule.error === undefined) {",
|
|
130
|
+
Template.indent([
|
|
131
|
+
"var exports = cachedModule.exports;",
|
|
132
|
+
hasAsync
|
|
133
|
+
? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
|
|
134
|
+
: "",
|
|
135
|
+
"if (mode == 0) return exports;",
|
|
136
|
+
`if (mode == 1) return ${RuntimeGlobals.createFakeNamespaceObject}(exports);`,
|
|
137
|
+
`if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
|
|
138
|
+
`if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
|
|
139
|
+
]),
|
|
140
|
+
"}",
|
|
108
141
|
"",
|
|
109
142
|
`var init = ${runtimeTemplate.basicFunction("", [
|
|
110
143
|
`ns = ${RuntimeGlobals.require}(moduleId);`,
|
|
@@ -137,9 +170,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
137
170
|
"}"
|
|
138
171
|
])};`,
|
|
139
172
|
"",
|
|
140
|
-
|
|
141
|
-
strictError ? "" : "cachedModule && cachedModule.exports || "
|
|
142
|
-
}__webpack_module_deferred_exports__[moduleId] || (__webpack_module_deferred_exports__[moduleId] = { __proto__: null });`,
|
|
173
|
+
"var ns = __webpack_module_deferred_exports__[moduleId] || (__webpack_module_deferred_exports__[moduleId] = { __proto__: null });",
|
|
143
174
|
"var handler = {",
|
|
144
175
|
Template.indent([
|
|
145
176
|
"__proto__: null,",
|
|
@@ -161,7 +192,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
161
192
|
'case "__esModule":',
|
|
162
193
|
"case Symbol.toStringTag:",
|
|
163
194
|
hasAsync
|
|
164
|
-
? `case ${RuntimeGlobals.
|
|
195
|
+
? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
|
|
165
196
|
: "",
|
|
166
197
|
Template.indent("return true;"),
|
|
167
198
|
'case "then":',
|
|
@@ -208,7 +239,10 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
208
239
|
}
|
|
209
240
|
}
|
|
210
241
|
|
|
211
|
-
module.exports =
|
|
242
|
+
module.exports.MakeDeferredNamespaceObjectRuntimeModule =
|
|
243
|
+
MakeDeferredNamespaceObjectRuntimeModule;
|
|
244
|
+
module.exports.MakeOptimizedDeferredNamespaceObjectRuntimeModule =
|
|
245
|
+
MakeOptimizedDeferredNamespaceObjectRuntimeModule;
|
|
212
246
|
module.exports.getMakeDeferredNamespaceModeFromExportsType =
|
|
213
247
|
getMakeDeferredNamespaceModeFromExportsType;
|
|
214
248
|
module.exports.getOptimizedDeferredModule = getOptimizedDeferredModule;
|
|
@@ -55,7 +55,7 @@ const WRITE_LIMIT_CHUNK = 511 * 1024 * 1024;
|
|
|
55
55
|
const hashForName = (buffers, hashFunction) => {
|
|
56
56
|
const hash = createHash(hashFunction);
|
|
57
57
|
for (const buf of buffers) hash.update(buf);
|
|
58
|
-
return
|
|
58
|
+
return hash.digest("hex");
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
const COMPRESSION_CHUNK_SIZE = 100 * 1024 * 1024;
|
|
@@ -117,7 +117,7 @@ const setMapSize = (map, size) => {
|
|
|
117
117
|
const toHash = (buffer, hashFunction) => {
|
|
118
118
|
const hash = createHash(hashFunction);
|
|
119
119
|
hash.update(buffer);
|
|
120
|
-
return
|
|
120
|
+
return hash.digest("latin1");
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
const ESCAPE = null;
|
|
@@ -722,7 +722,7 @@ const SIMPLE_EXTRACTORS = {
|
|
|
722
722
|
}
|
|
723
723
|
},
|
|
724
724
|
hash: (object, compilation) => {
|
|
725
|
-
object.hash =
|
|
725
|
+
object.hash = compilation.hash;
|
|
726
726
|
},
|
|
727
727
|
version: (object) => {
|
|
728
728
|
object.version = require("../../package.json").version;
|
package/lib/util/Hash.js
CHANGED
|
@@ -5,14 +5,31 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
/** @typedef {import("../../declarations/WebpackOptions").HashDigest} Encoding */
|
|
9
|
+
|
|
8
10
|
class Hash {
|
|
9
11
|
/* istanbul ignore next */
|
|
10
12
|
/**
|
|
11
13
|
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
12
14
|
* @abstract
|
|
13
|
-
* @
|
|
14
|
-
* @param {string
|
|
15
|
-
* @returns {
|
|
15
|
+
* @overload
|
|
16
|
+
* @param {string | Buffer} data data
|
|
17
|
+
* @returns {Hash} updated hash
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
21
|
+
* @abstract
|
|
22
|
+
* @overload
|
|
23
|
+
* @param {string} data data
|
|
24
|
+
* @param {Encoding} inputEncoding data encoding
|
|
25
|
+
* @returns {Hash} updated hash
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
29
|
+
* @abstract
|
|
30
|
+
* @param {string | Buffer} data data
|
|
31
|
+
* @param {Encoding=} inputEncoding data encoding
|
|
32
|
+
* @returns {Hash} updated hash
|
|
16
33
|
*/
|
|
17
34
|
update(data, inputEncoding) {
|
|
18
35
|
const AbstractMethodError = require("../AbstractMethodError");
|
|
@@ -24,8 +41,21 @@ class Hash {
|
|
|
24
41
|
/**
|
|
25
42
|
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
26
43
|
* @abstract
|
|
27
|
-
* @
|
|
28
|
-
* @returns {
|
|
44
|
+
* @overload
|
|
45
|
+
* @returns {Buffer} digest
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
49
|
+
* @abstract
|
|
50
|
+
* @overload
|
|
51
|
+
* @param {Encoding} encoding encoding of the return value
|
|
52
|
+
* @returns {string} digest
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
56
|
+
* @abstract
|
|
57
|
+
* @param {Encoding=} encoding encoding of the return value
|
|
58
|
+
* @returns {string | Buffer} digest
|
|
29
59
|
*/
|
|
30
60
|
digest(encoding) {
|
|
31
61
|
const AbstractMethodError = require("../AbstractMethodError");
|
package/lib/util/comparators.js
CHANGED
|
@@ -19,6 +19,7 @@ const { compareRuntime } = require("./runtime");
|
|
|
19
19
|
/** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
|
|
20
20
|
/** @typedef {import("../Module")} Module */
|
|
21
21
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
22
|
+
/** @typedef {import("../dependencies/ModuleDependency")} ModuleDependency */
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @typedef {object} DependencySourceOrder
|
|
@@ -524,9 +525,9 @@ const sortWithSourceOrder = (dependencies, dependencySourceOrderMap) => {
|
|
|
524
525
|
);
|
|
525
526
|
return main;
|
|
526
527
|
}
|
|
527
|
-
return /** @type {
|
|
528
|
-
dep
|
|
529
|
-
)
|
|
528
|
+
return /** @type {number} */ (
|
|
529
|
+
/** @type {ModuleDependency} */ (dep).sourceOrder
|
|
530
|
+
);
|
|
530
531
|
};
|
|
531
532
|
|
|
532
533
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const memoize = require("./memoize");
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("schema-utils").Schema} Schema */
|
|
11
|
-
/** @typedef {import("schema-utils
|
|
11
|
+
/** @typedef {import("schema-utils").ValidationErrorConfiguration} ValidationErrorConfiguration */
|
|
12
12
|
|
|
13
13
|
const getValidate = memoize(() => require("schema-utils").validate);
|
|
14
14
|
|
package/lib/util/createHash.js
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
const Hash = require("./Hash");
|
|
9
9
|
|
|
10
|
+
/** @typedef {import("../../declarations/WebpackOptions").HashDigest} Encoding */
|
|
10
11
|
/** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
11
12
|
|
|
12
|
-
const BULK_SIZE =
|
|
13
|
+
const BULK_SIZE = 3;
|
|
13
14
|
|
|
14
15
|
// We are using an object instead of a Map as this will stay static during the runtime
|
|
15
16
|
// so access to it can be optimized by v8
|
|
@@ -38,9 +39,22 @@ class BulkUpdateDecorator extends Hash {
|
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
41
|
-
* @
|
|
42
|
-
* @param {string
|
|
43
|
-
* @returns {
|
|
42
|
+
* @overload
|
|
43
|
+
* @param {string | Buffer} data data
|
|
44
|
+
* @returns {Hash} updated hash
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
48
|
+
* @overload
|
|
49
|
+
* @param {string} data data
|
|
50
|
+
* @param {Encoding} inputEncoding data encoding
|
|
51
|
+
* @returns {Hash} updated hash
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
55
|
+
* @param {string | Buffer} data data
|
|
56
|
+
* @param {Encoding=} inputEncoding data encoding
|
|
57
|
+
* @returns {Hash} updated hash
|
|
44
58
|
*/
|
|
45
59
|
update(data, inputEncoding) {
|
|
46
60
|
if (
|
|
@@ -55,7 +69,11 @@ class BulkUpdateDecorator extends Hash {
|
|
|
55
69
|
this.hash.update(this.buffer);
|
|
56
70
|
this.buffer = "";
|
|
57
71
|
}
|
|
58
|
-
|
|
72
|
+
if (typeof data === "string" && inputEncoding) {
|
|
73
|
+
this.hash.update(data, inputEncoding);
|
|
74
|
+
} else {
|
|
75
|
+
this.hash.update(data);
|
|
76
|
+
}
|
|
59
77
|
} else {
|
|
60
78
|
this.buffer += data;
|
|
61
79
|
if (this.buffer.length > BULK_SIZE) {
|
|
@@ -71,8 +89,19 @@ class BulkUpdateDecorator extends Hash {
|
|
|
71
89
|
|
|
72
90
|
/**
|
|
73
91
|
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
74
|
-
* @
|
|
75
|
-
* @returns {
|
|
92
|
+
* @overload
|
|
93
|
+
* @returns {Buffer} digest
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
97
|
+
* @overload
|
|
98
|
+
* @param {Encoding} encoding encoding of the return value
|
|
99
|
+
* @returns {string} digest
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
103
|
+
* @param {Encoding=} encoding encoding of the return value
|
|
104
|
+
* @returns {string | Buffer} digest
|
|
76
105
|
*/
|
|
77
106
|
digest(encoding) {
|
|
78
107
|
let digestCache;
|
|
@@ -91,9 +120,19 @@ class BulkUpdateDecorator extends Hash {
|
|
|
91
120
|
if (buffer.length > 0) {
|
|
92
121
|
this.hash.update(buffer);
|
|
93
122
|
}
|
|
123
|
+
if (!encoding) {
|
|
124
|
+
const result = this.hash.digest();
|
|
125
|
+
if (digestCache !== undefined) {
|
|
126
|
+
digestCache.set(buffer, result);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
94
130
|
const digestResult = this.hash.digest(encoding);
|
|
131
|
+
// Compatibility with the old hash library
|
|
95
132
|
const result =
|
|
96
|
-
typeof digestResult === "string"
|
|
133
|
+
typeof digestResult === "string"
|
|
134
|
+
? digestResult
|
|
135
|
+
: /** @type {NodeJS.TypedArray} */ (digestResult).toString();
|
|
97
136
|
if (digestCache !== undefined) {
|
|
98
137
|
digestCache.set(buffer, result);
|
|
99
138
|
}
|
|
@@ -110,9 +149,22 @@ class DebugHash extends Hash {
|
|
|
110
149
|
|
|
111
150
|
/**
|
|
112
151
|
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
113
|
-
* @
|
|
114
|
-
* @param {string
|
|
115
|
-
* @returns {
|
|
152
|
+
* @overload
|
|
153
|
+
* @param {string | Buffer} data data
|
|
154
|
+
* @returns {Hash} updated hash
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
158
|
+
* @overload
|
|
159
|
+
* @param {string} data data
|
|
160
|
+
* @param {Encoding} inputEncoding data encoding
|
|
161
|
+
* @returns {Hash} updated hash
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
165
|
+
* @param {string | Buffer} data data
|
|
166
|
+
* @param {Encoding=} inputEncoding data encoding
|
|
167
|
+
* @returns {Hash} updated hash
|
|
116
168
|
*/
|
|
117
169
|
update(data, inputEncoding) {
|
|
118
170
|
if (typeof data !== "string") data = data.toString("utf8");
|
|
@@ -132,8 +184,19 @@ class DebugHash extends Hash {
|
|
|
132
184
|
|
|
133
185
|
/**
|
|
134
186
|
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
135
|
-
* @
|
|
136
|
-
* @returns {
|
|
187
|
+
* @overload
|
|
188
|
+
* @returns {Buffer} digest
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
192
|
+
* @overload
|
|
193
|
+
* @param {Encoding} encoding encoding of the return value
|
|
194
|
+
* @returns {string} digest
|
|
195
|
+
*/
|
|
196
|
+
/**
|
|
197
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
198
|
+
* @param {Encoding=} encoding encoding of the return value
|
|
199
|
+
* @returns {string | Buffer} digest
|
|
137
200
|
*/
|
|
138
201
|
digest(encoding) {
|
|
139
202
|
return Buffer.from(`@webpack-debug-digest@${this.string}`).toString("hex");
|
|
@@ -186,14 +249,21 @@ module.exports = (algorithm) => {
|
|
|
186
249
|
case "native-md4":
|
|
187
250
|
if (crypto === undefined) crypto = require("crypto");
|
|
188
251
|
return new BulkUpdateDecorator(
|
|
189
|
-
() =>
|
|
252
|
+
() =>
|
|
253
|
+
/** @type {Hash} */ (
|
|
254
|
+
/** @type {typeof import("crypto")} */
|
|
255
|
+
(crypto).createHash("md4")
|
|
256
|
+
),
|
|
190
257
|
"md4"
|
|
191
258
|
);
|
|
192
259
|
default:
|
|
193
260
|
if (crypto === undefined) crypto = require("crypto");
|
|
194
261
|
return new BulkUpdateDecorator(
|
|
195
262
|
() =>
|
|
196
|
-
/** @type {
|
|
263
|
+
/** @type {Hash} */ (
|
|
264
|
+
/** @type {typeof import("crypto")} */
|
|
265
|
+
(crypto).createHash(algorithm)
|
|
266
|
+
),
|
|
197
267
|
algorithm
|
|
198
268
|
);
|
|
199
269
|
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
const Hash = require("../Hash");
|
|
9
9
|
const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
|
|
10
10
|
|
|
11
|
+
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
|
|
12
|
+
|
|
11
13
|
class BatchedHash extends Hash {
|
|
12
14
|
/**
|
|
13
15
|
* @param {Hash} hash hash
|
|
@@ -21,9 +23,22 @@ class BatchedHash extends Hash {
|
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
24
|
-
* @
|
|
25
|
-
* @param {string
|
|
26
|
-
* @returns {
|
|
26
|
+
* @overload
|
|
27
|
+
* @param {string | Buffer} data data
|
|
28
|
+
* @returns {Hash} updated hash
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
32
|
+
* @overload
|
|
33
|
+
* @param {string} data data
|
|
34
|
+
* @param {Encoding} inputEncoding data encoding
|
|
35
|
+
* @returns {Hash} updated hash
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
|
39
|
+
* @param {string | Buffer} data data
|
|
40
|
+
* @param {Encoding=} inputEncoding data encoding
|
|
41
|
+
* @returns {Hash} updated hash
|
|
27
42
|
*/
|
|
28
43
|
update(data, inputEncoding) {
|
|
29
44
|
if (this.string !== undefined) {
|
|
@@ -35,7 +50,11 @@ class BatchedHash extends Hash {
|
|
|
35
50
|
this.string += data;
|
|
36
51
|
return this;
|
|
37
52
|
}
|
|
38
|
-
|
|
53
|
+
if (this.encoding) {
|
|
54
|
+
this.hash.update(this.string, this.encoding);
|
|
55
|
+
} else {
|
|
56
|
+
this.hash.update(this.string);
|
|
57
|
+
}
|
|
39
58
|
this.string = undefined;
|
|
40
59
|
}
|
|
41
60
|
if (typeof data === "string") {
|
|
@@ -46,8 +65,10 @@ class BatchedHash extends Hash {
|
|
|
46
65
|
) {
|
|
47
66
|
this.string = data;
|
|
48
67
|
this.encoding = inputEncoding;
|
|
49
|
-
} else {
|
|
68
|
+
} else if (inputEncoding) {
|
|
50
69
|
this.hash.update(data, inputEncoding);
|
|
70
|
+
} else {
|
|
71
|
+
this.hash.update(data);
|
|
51
72
|
}
|
|
52
73
|
} else {
|
|
53
74
|
this.hash.update(data);
|
|
@@ -57,12 +78,30 @@ class BatchedHash extends Hash {
|
|
|
57
78
|
|
|
58
79
|
/**
|
|
59
80
|
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
60
|
-
* @
|
|
61
|
-
* @returns {
|
|
81
|
+
* @overload
|
|
82
|
+
* @returns {Buffer} digest
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
86
|
+
* @overload
|
|
87
|
+
* @param {Encoding} encoding encoding of the return value
|
|
88
|
+
* @returns {string} digest
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
|
92
|
+
* @param {Encoding=} encoding encoding of the return value
|
|
93
|
+
* @returns {string | Buffer} digest
|
|
62
94
|
*/
|
|
63
95
|
digest(encoding) {
|
|
64
96
|
if (this.string !== undefined) {
|
|
65
|
-
|
|
97
|
+
if (this.encoding) {
|
|
98
|
+
this.hash.update(this.string, this.encoding);
|
|
99
|
+
} else {
|
|
100
|
+
this.hash.update(this.string);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!encoding) {
|
|
104
|
+
return this.hash.digest();
|
|
66
105
|
}
|
|
67
106
|
return this.hash.digest(encoding);
|
|
68
107
|
}
|