webpack 5.102.0 → 5.102.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.
- package/lib/ChunkGraph.js +2 -2
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/Compilation.js +5 -11
- package/lib/ContextModule.js +3 -1
- package/lib/DefinePlugin.js +1 -1
- package/lib/DependencyTemplates.js +1 -1
- package/lib/FileSystemInfo.js +9 -12
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/NormalModule.js +1 -1
- package/lib/NormalModuleFactory.js +75 -4
- package/lib/RuntimeTemplate.js +10 -1
- package/lib/SourceMapDevToolPlugin.js +6 -8
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +2 -3
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +77 -76
- package/lib/config/defaults.js +7 -2
- package/lib/config/target.js +1 -1
- package/lib/css/CssModulesPlugin.js +2 -6
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +1 -3
- package/lib/dependencies/HarmonyImportDependency.js +5 -2
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +1 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +2 -3
- package/lib/javascript/JavascriptParser.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +15 -5
- package/lib/optimize/RealContentHashPlugin.js +5 -3
- 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/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/wasm-async/AsyncWebAssemblyParser.js +0 -9
- package/lib/wasm-sync/WebAssemblyParser.js +0 -9
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/package.json +18 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +16 -3
- 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/types.d.ts +590 -196
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
package/lib/css/walkCssTokens.js
CHANGED
|
@@ -66,7 +66,7 @@ const CC_LOWER_Z = "z".charCodeAt(0);
|
|
|
66
66
|
const CC_UPPER_A = "A".charCodeAt(0);
|
|
67
67
|
const CC_UPPER_F = "F".charCodeAt(0);
|
|
68
68
|
const CC_UPPER_E = "E".charCodeAt(0);
|
|
69
|
-
const CC_UPPER_U = "
|
|
69
|
+
const CC_UPPER_U = "U".charCodeAt(0);
|
|
70
70
|
const CC_UPPER_Z = "Z".charCodeAt(0);
|
|
71
71
|
const CC_0 = "0".charCodeAt(0);
|
|
72
72
|
const CC_9 = "9".charCodeAt(0);
|
|
@@ -68,8 +68,8 @@ class ContextElementDependency extends ModuleDependency {
|
|
|
68
68
|
*/
|
|
69
69
|
getResourceIdentifier() {
|
|
70
70
|
let str = super.getResourceIdentifier();
|
|
71
|
-
if (this.attributes
|
|
72
|
-
str += JSON.stringify(this.attributes)
|
|
71
|
+
if (this.attributes) {
|
|
72
|
+
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
|
73
73
|
}
|
|
74
74
|
return str;
|
|
75
75
|
}
|
|
@@ -64,9 +64,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
|
|
64
64
|
hash.update(local);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const localIdentHash =
|
|
68
|
-
/** @type {string} */
|
|
69
|
-
(hash.digest(hashDigest)).slice(0, hashDigestLength);
|
|
67
|
+
const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength);
|
|
70
68
|
|
|
71
69
|
return runtimeTemplate.compilation
|
|
72
70
|
.getPath(localIdentName, {
|
|
@@ -79,8 +79,11 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
79
79
|
*/
|
|
80
80
|
getResourceIdentifier() {
|
|
81
81
|
let str = super.getResourceIdentifier();
|
|
82
|
-
if (this.
|
|
83
|
-
str +=
|
|
82
|
+
if (this.defer) {
|
|
83
|
+
str += "|defer";
|
|
84
|
+
}
|
|
85
|
+
if (this.attributes) {
|
|
86
|
+
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
|
84
87
|
}
|
|
85
88
|
return str;
|
|
86
89
|
}
|
|
@@ -35,6 +35,19 @@ class ImportContextDependency extends ContextDependency {
|
|
|
35
35
|
return "esm";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @returns {string | null} an identifier to merge equal requests
|
|
40
|
+
*/
|
|
41
|
+
getResourceIdentifier() {
|
|
42
|
+
let str = super.getResourceIdentifier();
|
|
43
|
+
|
|
44
|
+
if (this.options.attributes) {
|
|
45
|
+
str += `|importAttributes${JSON.stringify(this.options.attributes)}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return str;
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
/**
|
|
39
52
|
* @param {ObjectSerializerContext} context context
|
|
40
53
|
*/
|
|
@@ -50,8 +50,8 @@ class ImportDependency extends ModuleDependency {
|
|
|
50
50
|
*/
|
|
51
51
|
getResourceIdentifier() {
|
|
52
52
|
let str = super.getResourceIdentifier();
|
|
53
|
-
if (this.attributes
|
|
54
|
-
str += JSON.stringify(this.attributes)
|
|
53
|
+
if (this.attributes) {
|
|
54
|
+
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
|
55
55
|
}
|
|
56
56
|
return str;
|
|
57
57
|
}
|
|
@@ -115,7 +115,7 @@ class ImportMetaPlugin {
|
|
|
115
115
|
new ModuleDependencyWarning(
|
|
116
116
|
parser.state.module,
|
|
117
117
|
new CriticalDependencyWarning(
|
|
118
|
-
"
|
|
118
|
+
"'import.meta' cannot be used as a standalone expression. For static analysis, its properties must be accessed directly (e.g., 'import.meta.url') or through destructuring."
|
|
119
119
|
),
|
|
120
120
|
/** @type {DependencyLocation} */ (metaProperty.loc)
|
|
121
121
|
)
|
|
@@ -378,9 +378,7 @@ class WorkerPlugin {
|
|
|
378
378
|
)}|${i}`;
|
|
379
379
|
const hash = createHash(compilation.outputOptions.hashFunction);
|
|
380
380
|
hash.update(name);
|
|
381
|
-
const digest =
|
|
382
|
-
/** @type {string} */
|
|
383
|
-
(hash.digest(compilation.outputOptions.hashDigest));
|
|
381
|
+
const digest = hash.digest(compilation.outputOptions.hashDigest);
|
|
384
382
|
entryOptions.runtime = digest.slice(
|
|
385
383
|
0,
|
|
386
384
|
compilation.outputOptions.hashDigestLength
|
|
@@ -16,12 +16,12 @@ const {
|
|
|
16
16
|
getUsedModuleIdsAndModules
|
|
17
17
|
} = require("./IdHelpers");
|
|
18
18
|
|
|
19
|
-
/** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
|
19
|
+
/** @typedef {import("../../declarations/plugins/ids/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
|
20
20
|
/** @typedef {import("../Compiler")} Compiler */
|
|
21
21
|
|
|
22
22
|
const validate = createSchemaValidation(
|
|
23
|
-
require("../../schemas/plugins/HashedModuleIdsPlugin.check"),
|
|
24
|
-
() => require("../../schemas/plugins/HashedModuleIdsPlugin.json"),
|
|
23
|
+
require("../../schemas/plugins/ids/HashedModuleIdsPlugin.check"),
|
|
24
|
+
() => require("../../schemas/plugins/ids/HashedModuleIdsPlugin.json"),
|
|
25
25
|
{
|
|
26
26
|
name: "Hashed Module Ids Plugin",
|
|
27
27
|
baseDataPath: "options"
|
|
@@ -37,7 +37,7 @@ class HashedModuleIdsPlugin {
|
|
|
37
37
|
constructor(options = {}) {
|
|
38
38
|
validate(options);
|
|
39
39
|
|
|
40
|
-
/** @type {HashedModuleIdsPluginOptions} */
|
|
40
|
+
/** @type {Required<Omit<HashedModuleIdsPluginOptions, "context">> & { context?: string | undefined }} */
|
|
41
41
|
this.options = {
|
|
42
42
|
context: undefined,
|
|
43
43
|
hashFunction: DEFAULTS.HASH_FUNCTION,
|
|
@@ -73,9 +73,7 @@ class HashedModuleIdsPlugin {
|
|
|
73
73
|
)
|
|
74
74
|
);
|
|
75
75
|
hash.update(ident || "");
|
|
76
|
-
const hashId =
|
|
77
|
-
hash.digest(options.hashDigest)
|
|
78
|
-
);
|
|
76
|
+
const hashId = hash.digest(options.hashDigest);
|
|
79
77
|
let len = options.hashDigestLength;
|
|
80
78
|
while (usedIds.has(hashId.slice(0, len))) {
|
|
81
79
|
/** @type {number} */ (len)++;
|
package/lib/ids/IdHelpers.js
CHANGED
|
@@ -25,7 +25,7 @@ const numberHash = require("../util/numberHash");
|
|
|
25
25
|
const getHash = (str, len, hashFunction) => {
|
|
26
26
|
const hash = createHash(hashFunction);
|
|
27
27
|
hash.update(str);
|
|
28
|
-
const digest =
|
|
28
|
+
const digest = hash.digest("hex");
|
|
29
29
|
return digest.slice(0, len);
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -503,11 +503,10 @@ class JavascriptModulesPlugin {
|
|
|
503
503
|
}
|
|
504
504
|
xor.updateHash(hash);
|
|
505
505
|
}
|
|
506
|
-
const digest =
|
|
506
|
+
const digest = hash.digest(hashDigest);
|
|
507
507
|
chunk.contentHash.javascript = nonNumericOnlyHash(
|
|
508
508
|
digest,
|
|
509
|
-
|
|
510
|
-
(hashDigestLength)
|
|
509
|
+
hashDigestLength
|
|
511
510
|
);
|
|
512
511
|
});
|
|
513
512
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
|
@@ -106,7 +106,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
|
106
106
|
/** @typedef {Set<DestructuringAssignmentProperty>} DestructuringAssignmentProperties */
|
|
107
107
|
|
|
108
108
|
// TODO remove cast when @types/estree has been updated to import assertions
|
|
109
|
-
/** @typedef {import("estree").ImportExpression & {
|
|
109
|
+
/** @typedef {import("estree").ImportExpression & { phase?: "defer" }} ImportExpression */
|
|
110
110
|
|
|
111
111
|
/** @type {string[]} */
|
|
112
112
|
const EMPTY_ARRAY = [];
|
|
@@ -134,11 +134,21 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
134
134
|
);
|
|
135
135
|
if (used) {
|
|
136
136
|
if (otherUnused || used !== exportInfo.name) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
if (exportInfo.name === "default") {
|
|
138
|
+
// Ideally we should use `module && module.__esModule ? module['default'] : module`
|
|
139
|
+
// But we need to keep compatibility with SystemJS format libraries (they are using `default`) and bundled SystemJS libraries from commonjs format
|
|
140
|
+
instructions.push(
|
|
141
|
+
`${external}${propertyAccess([
|
|
142
|
+
used
|
|
143
|
+
])} = module["default"] || module;`
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
instructions.push(
|
|
147
|
+
`${external}${propertyAccess([
|
|
148
|
+
used
|
|
149
|
+
])} = module${propertyAccess([exportInfo.name])};`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
142
152
|
handledNames.push(exportInfo.name);
|
|
143
153
|
}
|
|
144
154
|
} else {
|
|
@@ -12,6 +12,8 @@ const WebpackError = require("../WebpackError");
|
|
|
12
12
|
const { compareSelect, compareStrings } = require("../util/comparators");
|
|
13
13
|
const createHash = require("../util/createHash");
|
|
14
14
|
|
|
15
|
+
/** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").HashDigest} HashDigest */
|
|
15
17
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
16
18
|
/** @typedef {import("../Cache").Etag} Etag */
|
|
17
19
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
|
@@ -109,8 +111,8 @@ const compilationHooksMap = new WeakMap();
|
|
|
109
111
|
|
|
110
112
|
/**
|
|
111
113
|
* @typedef {object} RealContentHashPluginOptions
|
|
112
|
-
* @property {
|
|
113
|
-
* @property {
|
|
114
|
+
* @property {HashFunction} hashFunction the hash function to use
|
|
115
|
+
* @property {HashDigest} hashDigest the hash digest to use
|
|
114
116
|
*/
|
|
115
117
|
|
|
116
118
|
const PLUGIN_NAME = "RealContentHashPlugin";
|
|
@@ -432,7 +434,7 @@ ${referencingAssets
|
|
|
432
434
|
hash.update(content);
|
|
433
435
|
}
|
|
434
436
|
const digest = hash.digest(this._hashDigest);
|
|
435
|
-
newHash =
|
|
437
|
+
newHash = digest.slice(0, oldHash.length);
|
|
436
438
|
}
|
|
437
439
|
hashToNewHash.set(oldHash, newHash);
|
|
438
440
|
}
|
|
@@ -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");
|
|
@@ -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
|
}
|