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
@@ -16,7 +16,7 @@ const { UsageState } = require("../ExportsInfo");
|
|
16
16
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
17
17
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
18
18
|
|
19
|
-
/** @typedef {Map<TopLevelSymbol, Set<string | TopLevelSymbol> | true>} InnerGraph */
|
19
|
+
/** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true>} InnerGraph */
|
20
20
|
/** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
|
21
21
|
|
22
22
|
/**
|
@@ -75,7 +75,7 @@ exports.isEnabled = parserState => {
|
|
75
75
|
|
76
76
|
/**
|
77
77
|
* @param {ParserState} state parser state
|
78
|
-
* @param {TopLevelSymbol} symbol the symbol
|
78
|
+
* @param {TopLevelSymbol | null} symbol the symbol, or null for all symbols
|
79
79
|
* @param {string | TopLevelSymbol | true} usage usage data
|
80
80
|
* @returns {void}
|
81
81
|
*/
|
@@ -172,6 +172,26 @@ exports.inferDependencyUsage = state => {
|
|
172
172
|
}
|
173
173
|
if (isTerminal) {
|
174
174
|
nonTerminal.delete(key);
|
175
|
+
|
176
|
+
// For the global key, merge with all other keys
|
177
|
+
if (key === null) {
|
178
|
+
const globalValue = innerGraph.get(null);
|
179
|
+
if (globalValue) {
|
180
|
+
for (const [key, value] of innerGraph) {
|
181
|
+
if (key !== null && value !== true) {
|
182
|
+
if (globalValue === true) {
|
183
|
+
innerGraph.set(key, true);
|
184
|
+
} else {
|
185
|
+
const newSet = new Set(value);
|
186
|
+
for (const item of globalValue) {
|
187
|
+
newSet.add(item);
|
188
|
+
}
|
189
|
+
innerGraph.set(key, newSet);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
175
195
|
}
|
176
196
|
}
|
177
197
|
}
|
@@ -39,13 +39,28 @@ const comparator = compareSelect(e => e.name, compareStringsNumeric);
|
|
39
39
|
/**
|
40
40
|
* @param {boolean} deterministic use deterministic names
|
41
41
|
* @param {ExportsInfo} exportsInfo exports info
|
42
|
+
* @param {boolean} isNamespace is namespace object
|
42
43
|
* @returns {void}
|
43
44
|
*/
|
44
|
-
const mangleExportsInfo = (deterministic, exportsInfo) => {
|
45
|
+
const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
45
46
|
if (!canMangle(exportsInfo)) return;
|
46
47
|
const usedNames = new Set();
|
47
48
|
/** @type {ExportInfo[]} */
|
48
49
|
const mangleableExports = [];
|
50
|
+
|
51
|
+
// Avoid to renamed exports that are not provided when
|
52
|
+
// 1. it's not a namespace export: non-provided exports can be found in prototype chain
|
53
|
+
// 2. there are other provided exports and deterministic mode is chosen:
|
54
|
+
// non-provided exports would break the determinism
|
55
|
+
let avoidMangleNonProvided = !isNamespace;
|
56
|
+
if (!avoidMangleNonProvided && deterministic) {
|
57
|
+
for (const exportInfo of exportsInfo.ownedExports) {
|
58
|
+
if (exportInfo.provided !== false) {
|
59
|
+
avoidMangleNonProvided = true;
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
49
64
|
for (const exportInfo of exportsInfo.ownedExports) {
|
50
65
|
const name = exportInfo.name;
|
51
66
|
if (!exportInfo.hasUsedName()) {
|
@@ -59,7 +74,7 @@ const mangleExportsInfo = (deterministic, exportsInfo) => {
|
|
59
74
|
name.length === 2 &&
|
60
75
|
/^[a-zA-Z_$][a-zA-Z0-9_$]|^[1-9][0-9]/.test(name)) ||
|
61
76
|
// Don't rename exports that are not provided
|
62
|
-
exportInfo.provided !== true
|
77
|
+
(avoidMangleNonProvided && exportInfo.provided !== true)
|
63
78
|
) {
|
64
79
|
exportInfo.setUsedName(name);
|
65
80
|
usedNames.add(name);
|
@@ -73,7 +88,7 @@ const mangleExportsInfo = (deterministic, exportsInfo) => {
|
|
73
88
|
used === UsageState.OnlyPropertiesUsed ||
|
74
89
|
used === UsageState.Unused
|
75
90
|
) {
|
76
|
-
mangleExportsInfo(deterministic, exportInfo.exportsInfo);
|
91
|
+
mangleExportsInfo(deterministic, exportInfo.exportsInfo, false);
|
77
92
|
}
|
78
93
|
}
|
79
94
|
}
|
@@ -143,8 +158,10 @@ class MangleExportsPlugin {
|
|
143
158
|
"MangleExportsPlugin",
|
144
159
|
modules => {
|
145
160
|
for (const module of modules) {
|
161
|
+
const isNamespace =
|
162
|
+
module.buildMeta && module.buildMeta.exportsType === "namespace";
|
146
163
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
147
|
-
mangleExportsInfo(deterministic, exportsInfo);
|
164
|
+
mangleExportsInfo(deterministic, exportsInfo, isNamespace);
|
148
165
|
}
|
149
166
|
}
|
150
167
|
);
|
@@ -30,7 +30,7 @@ class RelativeUrlRuntimeModule extends HelperRuntimeModule {
|
|
30
30
|
`values.toString = values.toJSON = ${runtimeTemplate.returningFunction(
|
31
31
|
"url"
|
32
32
|
)};`,
|
33
|
-
"for (var key in values) Object.defineProperty(this, key,
|
33
|
+
"for (var key in values) Object.defineProperty(this, key, { enumerable: true, configurable: true, value: values[key] });"
|
34
34
|
]),
|
35
35
|
"};",
|
36
36
|
`${RuntimeGlobals.relativeUrl}.prototype = URL.prototype;`
|
@@ -311,8 +311,7 @@ class HttpUriPlugin {
|
|
311
311
|
: lockfileLocation + ".data";
|
312
312
|
const upgrade = this._upgrade || false;
|
313
313
|
const frozen = this._frozen || false;
|
314
|
-
const hashFunction =
|
315
|
-
this._hashFunction || compilation.outputOptions.hashFunction;
|
314
|
+
const hashFunction = this._hashFunction || "sha512";
|
316
315
|
const hashDigest =
|
317
316
|
this._hashDigest || compilation.outputOptions.hashDigest;
|
318
317
|
const hashDigestLength =
|
@@ -299,12 +299,21 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
299
299
|
writeU8(STRING_HEADER);
|
300
300
|
writeU32(len);
|
301
301
|
currentBuffer.write(thing, currentPosition);
|
302
|
-
|
302
|
+
currentPosition += len;
|
303
|
+
} else if (len >= 70) {
|
303
304
|
allocate(len + HEADER_SIZE);
|
304
305
|
writeU8(SHORT_STRING_HEADER | len);
|
306
|
+
|
305
307
|
currentBuffer.write(thing, currentPosition, "latin1");
|
308
|
+
currentPosition += len;
|
309
|
+
} else {
|
310
|
+
allocate(len + HEADER_SIZE);
|
311
|
+
writeU8(SHORT_STRING_HEADER | len);
|
312
|
+
|
313
|
+
for (let i = 0; i < len; i++) {
|
314
|
+
currentBuffer[currentPosition++] = thing.charCodeAt(i);
|
315
|
+
}
|
306
316
|
}
|
307
|
-
currentPosition += len;
|
308
317
|
break;
|
309
318
|
}
|
310
319
|
case "number": {
|
@@ -18,6 +18,7 @@ const { dirname, join, mkdirp } = require("../util/fs");
|
|
18
18
|
const memoize = require("../util/memoize");
|
19
19
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
20
20
|
|
21
|
+
/** @typedef {typeof import("../util/Hash")} Hash */
|
21
22
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
22
23
|
/** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
|
23
24
|
|
@@ -39,8 +40,14 @@ Section -> Buffer
|
|
39
40
|
|
40
41
|
// "wpc" + 1 in little-endian
|
41
42
|
const VERSION = 0x01637077;
|
42
|
-
|
43
|
-
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @param {Buffer[]} buffers buffers
|
46
|
+
* @param {string | Hash} hashFunction hash function to use
|
47
|
+
* @returns {string} hash
|
48
|
+
*/
|
49
|
+
const hashForName = (buffers, hashFunction) => {
|
50
|
+
const hash = createHash(hashFunction);
|
44
51
|
for (const buf of buffers) hash.update(buf);
|
45
52
|
return /** @type {string} */ (hash.digest("hex"));
|
46
53
|
};
|
@@ -81,9 +88,16 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE
|
|
81
88
|
* @param {BufferSerializableType[] | Promise<BufferSerializableType[]>} data data to be serialized
|
82
89
|
* @param {string | boolean} name file base name
|
83
90
|
* @param {function(string | false, Buffer[]): Promise<void>} writeFile writes a file
|
91
|
+
* @param {string | Hash} hashFunction hash function to use
|
84
92
|
* @returns {Promise<SerializeResult>} resulting file pointer and promise
|
85
93
|
*/
|
86
|
-
const serialize = async (
|
94
|
+
const serialize = async (
|
95
|
+
middleware,
|
96
|
+
data,
|
97
|
+
name,
|
98
|
+
writeFile,
|
99
|
+
hashFunction = "md4"
|
100
|
+
) => {
|
87
101
|
/** @type {(Buffer[] | Buffer | SerializeResult | Promise<SerializeResult>)[]} */
|
88
102
|
const processedData = [];
|
89
103
|
/** @type {WeakMap<SerializeResult, function(): any | Promise<any>>} */
|
@@ -118,7 +132,8 @@ const serialize = async (middleware, data, name, writeFile) => {
|
|
118
132
|
middleware,
|
119
133
|
content,
|
120
134
|
(options && options.name) || true,
|
121
|
-
writeFile
|
135
|
+
writeFile,
|
136
|
+
hashFunction
|
122
137
|
).then(result => {
|
123
138
|
/** @type {any} */ (item).options.size = result.size;
|
124
139
|
resultToLazy.set(result, item);
|
@@ -195,7 +210,7 @@ const serialize = async (middleware, data, name, writeFile) => {
|
|
195
210
|
}
|
196
211
|
}
|
197
212
|
if (name === true) {
|
198
|
-
name = hashForName(buf);
|
213
|
+
name = hashForName(buf, hashFunction);
|
199
214
|
}
|
200
215
|
backgroundJobs.push(writeFile(name, buf));
|
201
216
|
let size = 0;
|
@@ -386,10 +401,12 @@ const deserialize = async (middleware, name, readFile) => {
|
|
386
401
|
class FileMiddleware extends SerializerMiddleware {
|
387
402
|
/**
|
388
403
|
* @param {IntermediateFileSystem} fs filesystem
|
404
|
+
* @param {string | Hash} hashFunction hash function to use
|
389
405
|
*/
|
390
|
-
constructor(fs) {
|
406
|
+
constructor(fs, hashFunction = "md4") {
|
391
407
|
super();
|
392
408
|
this.fs = fs;
|
409
|
+
this._hashFunction = hashFunction;
|
393
410
|
}
|
394
411
|
/**
|
395
412
|
* @param {DeserializedType} data data
|
@@ -446,7 +463,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
446
463
|
};
|
447
464
|
|
448
465
|
resolve(
|
449
|
-
serialize(this, data, false, writeFile).then(
|
466
|
+
serialize(this, data, false, writeFile, this._hashFunction).then(
|
450
467
|
async ({ backgroundJob }) => {
|
451
468
|
await backgroundJob;
|
452
469
|
|
@@ -15,6 +15,7 @@ const RegExpObjectSerializer = require("./RegExpObjectSerializer");
|
|
15
15
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
16
16
|
const SetObjectSerializer = require("./SetObjectSerializer");
|
17
17
|
|
18
|
+
/** @typedef {typeof import("../util/Hash")} Hash */
|
18
19
|
/** @typedef {import("./types").ComplexSerializableType} ComplexSerializableType */
|
19
20
|
/** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
|
20
21
|
|
@@ -76,8 +77,13 @@ const setMapSize = (map, size) => {
|
|
76
77
|
}
|
77
78
|
};
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
/**
|
81
|
+
* @param {Buffer} buffer buffer
|
82
|
+
* @param {string | Hash} hashFunction hash function to use
|
83
|
+
* @returns {string} hash
|
84
|
+
*/
|
85
|
+
const toHash = (buffer, hashFunction) => {
|
86
|
+
const hash = createHash(hashFunction);
|
81
87
|
hash.update(buffer);
|
82
88
|
return /** @type {string} */ (hash.digest("latin1"));
|
83
89
|
};
|
@@ -149,9 +155,14 @@ const loaders = new Map();
|
|
149
155
|
* @extends {SerializerMiddleware<DeserializedType, SerializedType>}
|
150
156
|
*/
|
151
157
|
class ObjectMiddleware extends SerializerMiddleware {
|
152
|
-
|
158
|
+
/**
|
159
|
+
* @param {function(any): void} extendContext context extensions
|
160
|
+
* @param {string | Hash} hashFunction hash function to use
|
161
|
+
*/
|
162
|
+
constructor(extendContext, hashFunction = "md4") {
|
153
163
|
super();
|
154
164
|
this.extendContext = extendContext;
|
165
|
+
this._hashFunction = hashFunction;
|
155
166
|
}
|
156
167
|
/**
|
157
168
|
* @param {RegExp} regExp RegExp for which the request is tested
|
@@ -275,11 +286,11 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
275
286
|
bufferDedupeMap.set(len, [entry, buf]);
|
276
287
|
return buf;
|
277
288
|
} else {
|
278
|
-
const hash = toHash(entry);
|
289
|
+
const hash = toHash(entry, this._hashFunction);
|
279
290
|
const newMap = new Map();
|
280
291
|
newMap.set(hash, entry);
|
281
292
|
bufferDedupeMap.set(len, newMap);
|
282
|
-
const hashBuf = toHash(buf);
|
293
|
+
const hashBuf = toHash(buf, this._hashFunction);
|
283
294
|
if (hash === hashBuf) {
|
284
295
|
return entry;
|
285
296
|
}
|
@@ -296,10 +307,10 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
296
307
|
return buf;
|
297
308
|
} else {
|
298
309
|
const newMap = new Map();
|
299
|
-
const hash = toHash(buf);
|
310
|
+
const hash = toHash(buf, this._hashFunction);
|
300
311
|
let found;
|
301
312
|
for (const item of entry) {
|
302
|
-
const itemHash = toHash(item);
|
313
|
+
const itemHash = toHash(item, this._hashFunction);
|
303
314
|
newMap.set(itemHash, item);
|
304
315
|
if (found === undefined && itemHash === hash) found = item;
|
305
316
|
}
|
@@ -312,7 +323,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
312
323
|
}
|
313
324
|
}
|
314
325
|
} else {
|
315
|
-
const hash = toHash(buf);
|
326
|
+
const hash = toHash(buf, this._hashFunction);
|
316
327
|
const item = entry.get(hash);
|
317
328
|
if (item !== undefined) {
|
318
329
|
return item;
|
@@ -510,11 +521,11 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
510
521
|
} else if (SerializerMiddleware.isLazy(item, this)) {
|
511
522
|
throw new Error("Not implemented");
|
512
523
|
} else {
|
513
|
-
|
514
|
-
|
515
|
-
this.serialize([data], context)
|
516
|
-
)
|
524
|
+
const data = SerializerMiddleware.serializeLazy(item, data =>
|
525
|
+
this.serialize([data], context)
|
517
526
|
);
|
527
|
+
SerializerMiddleware.setLazySerializedValue(item, data);
|
528
|
+
result.push(data);
|
518
529
|
}
|
519
530
|
} else if (item === undefined) {
|
520
531
|
result.push(ESCAPE, ESCAPE_UNDEFINED);
|
package/lib/util/createHash.js
CHANGED
@@ -125,6 +125,8 @@ class DebugHash extends Hash {
|
|
125
125
|
}
|
126
126
|
|
127
127
|
let crypto = undefined;
|
128
|
+
let createXXHash64 = undefined;
|
129
|
+
let BatchedHash = undefined;
|
128
130
|
|
129
131
|
/**
|
130
132
|
* Creates a hash by name or function
|
@@ -139,6 +141,14 @@ module.exports = algorithm => {
|
|
139
141
|
// TODO add non-cryptographic algorithm here
|
140
142
|
case "debug":
|
141
143
|
return new DebugHash();
|
144
|
+
case "xxhash64":
|
145
|
+
if (createXXHash64 === undefined) {
|
146
|
+
createXXHash64 = require("./hash/xxhash64");
|
147
|
+
if (BatchedHash === undefined) {
|
148
|
+
BatchedHash = require("./hash/BatchedHash");
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return new BatchedHash(createXXHash64());
|
142
152
|
default:
|
143
153
|
if (crypto === undefined) crypto = require("crypto");
|
144
154
|
return new BulkUpdateDecorator(
|
@@ -0,0 +1,65 @@
|
|
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 Hash = require("../Hash");
|
9
|
+
|
10
|
+
const MAX_STRING_LENGTH = 21845;
|
11
|
+
|
12
|
+
class BatchedHash extends Hash {
|
13
|
+
constructor(hash) {
|
14
|
+
super();
|
15
|
+
this.string = undefined;
|
16
|
+
this.encoding = undefined;
|
17
|
+
this.hash = hash;
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
|
22
|
+
* @param {string|Buffer} data data
|
23
|
+
* @param {string=} inputEncoding data encoding
|
24
|
+
* @returns {this} updated hash
|
25
|
+
*/
|
26
|
+
update(data, inputEncoding) {
|
27
|
+
if (this.string !== undefined) {
|
28
|
+
if (
|
29
|
+
typeof data === "string" &&
|
30
|
+
inputEncoding === this.encoding &&
|
31
|
+
this.string.length + data.length < MAX_STRING_LENGTH
|
32
|
+
) {
|
33
|
+
this.string += data;
|
34
|
+
return this;
|
35
|
+
}
|
36
|
+
this.hash.update(this.string, this.encoding);
|
37
|
+
this.string = undefined;
|
38
|
+
}
|
39
|
+
if (typeof data === "string") {
|
40
|
+
if (data.length < MAX_STRING_LENGTH) {
|
41
|
+
this.string = data;
|
42
|
+
this.encoding = inputEncoding;
|
43
|
+
} else {
|
44
|
+
this.hash.update(data, inputEncoding);
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
this.hash.update(data);
|
48
|
+
}
|
49
|
+
return this;
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
|
54
|
+
* @param {string=} encoding encoding of the return value
|
55
|
+
* @returns {string|Buffer} digest
|
56
|
+
*/
|
57
|
+
digest(encoding) {
|
58
|
+
if (this.string !== undefined) {
|
59
|
+
this.hash.update(this.string, this.encoding);
|
60
|
+
}
|
61
|
+
return this.hash.digest(encoding);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
module.exports = BatchedHash;
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
//#region wasm code: xxhash64 (../../../assembly/hash/xxhash64.asm.ts) --initialMemory 1
|
9
|
+
const xxhash64 = new WebAssembly.Module(
|
10
|
+
Buffer.from(
|
11
|
+
// 1180 bytes
|
12
|
+
"AGFzbQEAAAABCAJgAX8AYAAAAwQDAQAABQMBAAEGGgV+AUIAC34BQgALfgFCAAt+AUIAC34BQgALByIEBGluaXQAAAZ1cGRhdGUAAQVmaW5hbAACBm1lbW9yeQIACrwIAzAAQtbrgu7q/Yn14AAkAELP1tO+0ser2UIkAUIAJAJC+erQ0OfJoeThACQDQgAkBAvUAQIBfwR+IABFBEAPCyMEIACtfCQEIwAhAiMBIQMjAiEEIwMhBQNAIAIgASkDAELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiECIAMgASkDCELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiEDIAQgASkDEELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiEEIAUgASkDGELP1tO+0ser2UJ+fEIfiUKHla+vmLbem55/fiEFIAAgAUEgaiIBSw0ACyACJAAgAyQBIAQkAiAFJAMLsgYCAX8EfiMEQgBSBH4jACICQgGJIwEiA0IHiXwjAiIEQgyJfCMDIgVCEol8IAJCz9bTvtLHq9lCfkIfiUKHla+vmLbem55/foVCh5Wvr5i23puef35CnaO16oOxjYr6AH0gA0LP1tO+0ser2UJ+Qh+JQoeVr6+Ytt6bnn9+hUKHla+vmLbem55/fkKdo7Xqg7GNivoAfSAEQs/W077Sx6vZQn5CH4lCh5Wvr5i23puef36FQoeVr6+Ytt6bnn9+Qp2jteqDsY2K+gB9IAVCz9bTvtLHq9lCfkIfiUKHla+vmLbem55/foVCh5Wvr5i23puef35CnaO16oOxjYr6AH0FQsXP2bLx5brqJwsjBCAArXx8IQIDQCABQQhqIABNBEAgAiABKQMAQs/W077Sx6vZQn5CH4lCh5Wvr5i23puef36FQhuJQoeVr6+Ytt6bnn9+Qp2jteqDsY2K+gB9IQIgAUEIaiEBDAELCyABQQRqIABNBEACfyACIAE1AgBCh5Wvr5i23puef36FQheJQs/W077Sx6vZQn5C+fPd8Zn2masWfCECIAFBBGoLIQELA0AgACABRwRAIAIgATEAAELFz9my8eW66id+hUILiUKHla+vmLbem55/fiECIAFBAWohAQwBCwtBACACIAJCIYiFQs/W077Sx6vZQn4iAiACQh2IhUL5893xmfaZqxZ+IgIgAkIgiIUiAjcDAEEAIAJCIIgiA0L//wODQiCGIANCgID8/w+DQhCIhCIDQv+BgIDwH4NCEIYgA0KA/oOAgOA/g0IIiIQiA0KPgLyA8IHAB4NCCIYgA0LwgcCHgJ6A+ACDQgSIhCIDQoaMmLDgwIGDBnxCBIhCgYKEiJCgwIABg0InfiADQrDgwIGDhoyYMIR8NwMAQQggAkL/////D4MiAkL//wODQiCGIAJCgID8/w+DQhCIhCICQv+BgIDwH4NCEIYgAkKA/oOAgOA/g0IIiIQiAkKPgLyA8IHAB4NCCIYgAkLwgcCHgJ6A+ACDQgSIhCICQoaMmLDgwIGDBnxCBIhCgYKEiJCgwIABg0InfiACQrDgwIGDhoyYMIR8NwMACw==",
|
13
|
+
"base64"
|
14
|
+
)
|
15
|
+
);
|
16
|
+
//#endregion
|
17
|
+
|
18
|
+
class XxHash64 {
|
19
|
+
/**
|
20
|
+
* @param {WebAssembly.Instance} instance wasm instance
|
21
|
+
*/
|
22
|
+
constructor(instance) {
|
23
|
+
const exports = /** @type {any} */ (instance.exports);
|
24
|
+
exports.init();
|
25
|
+
this.exports = exports;
|
26
|
+
this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
|
27
|
+
this.buffered = 0;
|
28
|
+
}
|
29
|
+
|
30
|
+
reset() {
|
31
|
+
this.buffered = 0;
|
32
|
+
this.exports.init();
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @param {Buffer | string} data data
|
37
|
+
* @param {BufferEncoding=} encoding encoding
|
38
|
+
* @returns {this} itself
|
39
|
+
*/
|
40
|
+
update(data, encoding) {
|
41
|
+
if (typeof data === "string") {
|
42
|
+
if (data.length < 21845) {
|
43
|
+
this._updateWithShortString(data, encoding);
|
44
|
+
return this;
|
45
|
+
} else {
|
46
|
+
data = Buffer.from(data, encoding);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
this._updateWithBuffer(data);
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @param {string} data data
|
55
|
+
* @param {BufferEncoding=} encoding encoding
|
56
|
+
* @returns {void}
|
57
|
+
*/
|
58
|
+
_updateWithShortString(data, encoding) {
|
59
|
+
const { exports, buffered, mem } = this;
|
60
|
+
let endPos;
|
61
|
+
if (data.length < 70) {
|
62
|
+
if (!encoding || encoding === "utf-8" || encoding === "utf8") {
|
63
|
+
endPos = buffered;
|
64
|
+
for (let i = 0; i < data.length; i++) {
|
65
|
+
const cc = data.charCodeAt(i);
|
66
|
+
if (cc < 0x80) mem[endPos++] = cc;
|
67
|
+
else if (cc < 0x800) {
|
68
|
+
mem[endPos] = (cc >> 6) | 0xc0;
|
69
|
+
mem[endPos + 1] = (cc & 0x3f) | 0x80;
|
70
|
+
endPos += 2;
|
71
|
+
} else {
|
72
|
+
// bail-out for weird chars
|
73
|
+
endPos += mem.write(data.slice(endPos), endPos, encoding);
|
74
|
+
break;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
} else if (encoding === "latin1") {
|
78
|
+
endPos = buffered;
|
79
|
+
for (let i = 0; i < data.length; i++) {
|
80
|
+
const cc = data.charCodeAt(i);
|
81
|
+
mem[endPos++] = cc;
|
82
|
+
}
|
83
|
+
} else {
|
84
|
+
endPos = buffered + mem.write(data, buffered, encoding);
|
85
|
+
}
|
86
|
+
} else {
|
87
|
+
endPos = buffered + mem.write(data, buffered, encoding);
|
88
|
+
}
|
89
|
+
if (endPos < 32) {
|
90
|
+
this.buffered = endPos;
|
91
|
+
} else {
|
92
|
+
const l = (endPos >> 5) << 5;
|
93
|
+
exports.update(l);
|
94
|
+
const newBuffered = endPos - l;
|
95
|
+
this.buffered = newBuffered;
|
96
|
+
if (newBuffered > 0) mem.copyWithin(0, l, endPos);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* @param {Buffer} data data
|
102
|
+
* @returns {void}
|
103
|
+
*/
|
104
|
+
_updateWithBuffer(data) {
|
105
|
+
const { exports, buffered, mem } = this;
|
106
|
+
const length = data.length;
|
107
|
+
if (buffered + length < 32) {
|
108
|
+
data.copy(mem, buffered, 0, length);
|
109
|
+
this.buffered += length;
|
110
|
+
} else {
|
111
|
+
const l = ((buffered + length) >> 5) << 5;
|
112
|
+
if (l > 65536) {
|
113
|
+
let i = 65536 - buffered;
|
114
|
+
data.copy(mem, buffered, 0, i);
|
115
|
+
exports.update(65536);
|
116
|
+
const stop = l - buffered - 65536;
|
117
|
+
while (i < stop) {
|
118
|
+
data.copy(mem, 0, i, i + 65536);
|
119
|
+
exports.update(65536);
|
120
|
+
i += 65536;
|
121
|
+
}
|
122
|
+
data.copy(mem, 0, i, l - buffered);
|
123
|
+
exports.update(l - buffered - i);
|
124
|
+
} else {
|
125
|
+
data.copy(mem, buffered, 0, l - buffered);
|
126
|
+
exports.update(l);
|
127
|
+
}
|
128
|
+
const newBuffered = length + buffered - l;
|
129
|
+
this.buffered = newBuffered;
|
130
|
+
if (newBuffered > 0) data.copy(mem, 0, length - newBuffered, length);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
digest(type) {
|
135
|
+
const { exports, buffered, mem } = this;
|
136
|
+
exports.final(buffered);
|
137
|
+
instancesPool.push(this);
|
138
|
+
return mem.toString("latin1", 0, 16);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
const instancesPool = [];
|
143
|
+
|
144
|
+
const create = () => {
|
145
|
+
if (instancesPool.length > 0) {
|
146
|
+
const old = instancesPool.pop();
|
147
|
+
old.reset();
|
148
|
+
return old;
|
149
|
+
} else {
|
150
|
+
return new XxHash64(new WebAssembly.Instance(xxhash64));
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
module.exports = create;
|
@@ -164,6 +164,7 @@ module.exports = {
|
|
164
164
|
DllModule: () => require("../DllModule"),
|
165
165
|
ExternalModule: () => require("../ExternalModule"),
|
166
166
|
FileSystemInfo: () => require("../FileSystemInfo"),
|
167
|
+
InitFragment: () => require("../InitFragment"),
|
167
168
|
InvalidDependenciesModuleWarning: () =>
|
168
169
|
require("../InvalidDependenciesModuleWarning"),
|
169
170
|
Module: () => require("../Module"),
|
@@ -188,6 +189,7 @@ module.exports = {
|
|
188
189
|
UnsupportedFeatureWarning: () => require("../UnsupportedFeatureWarning"),
|
189
190
|
"util/LazySet": () => require("../util/LazySet"),
|
190
191
|
UnhandledSchemeError: () => require("../UnhandledSchemeError"),
|
192
|
+
NodeStuffInWebError: () => require("../NodeStuffInWebError"),
|
191
193
|
WebpackError: () => require("../WebpackError"),
|
192
194
|
|
193
195
|
"util/registerExternalSerializer": () => {
|
@@ -89,15 +89,15 @@ module.exports = {
|
|
89
89
|
);
|
90
90
|
};
|
91
91
|
}
|
92
|
-
}),
|
92
|
+
}, "md4"),
|
93
93
|
binaryMiddleware
|
94
94
|
]));
|
95
95
|
},
|
96
|
-
createFileSerializer: fs => {
|
96
|
+
createFileSerializer: (fs, hashFunction) => {
|
97
97
|
registerSerializers();
|
98
98
|
const Serializer = getSerializer();
|
99
99
|
const FileMiddleware = require("../serialization/FileMiddleware");
|
100
|
-
const fileMiddleware = new FileMiddleware(fs);
|
100
|
+
const fileMiddleware = new FileMiddleware(fs, hashFunction);
|
101
101
|
const binaryMiddleware = getBinaryMiddlewareInstance();
|
102
102
|
const SerializerMiddleware = getSerializerMiddleware();
|
103
103
|
const SingleItemMiddleware = getSingleItemMiddleware();
|
@@ -111,12 +111,16 @@ module.exports = {
|
|
111
111
|
);
|
112
112
|
};
|
113
113
|
context.writeSeparate = (value, options) => {
|
114
|
-
|
115
|
-
|
114
|
+
const lazy = SerializerMiddleware.createLazy(
|
115
|
+
value,
|
116
|
+
fileMiddleware,
|
117
|
+
options
|
116
118
|
);
|
119
|
+
context.write(lazy);
|
120
|
+
return lazy;
|
117
121
|
};
|
118
122
|
}
|
119
|
-
}),
|
123
|
+
}, hashFunction),
|
120
124
|
binaryMiddleware,
|
121
125
|
fileMiddleware
|
122
126
|
]);
|