webpack 5.37.1 → 5.39.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/bin/webpack.js +20 -5
- package/lib/AsyncDependencyToInitialChunkError.js +0 -2
- package/lib/CaseSensitiveModulesWarning.js +0 -2
- package/lib/Chunk.js +6 -2
- package/lib/ChunkRenderError.js +0 -2
- package/lib/CodeGenerationError.js +0 -2
- package/lib/CommentCompilationWarning.js +0 -2
- package/lib/Compilation.js +43 -28
- package/lib/Compiler.js +3 -0
- package/lib/ConcurrentCompilationError.js +0 -2
- package/lib/ContextModule.js +2 -1
- package/lib/ContextModuleFactory.js +3 -1
- package/lib/DllReferencePlugin.js +0 -2
- package/lib/EntryPlugin.js +3 -3
- package/lib/ExportsInfo.js +20 -13
- package/lib/HarmonyLinkingError.js +0 -2
- package/lib/HookWebpackError.js +0 -1
- package/lib/HotModuleReplacementPlugin.js +7 -2
- package/lib/InvalidDependenciesModuleWarning.js +0 -2
- package/lib/ModuleBuildError.js +0 -2
- package/lib/ModuleDependencyError.js +0 -2
- package/lib/ModuleDependencyWarning.js +0 -2
- package/lib/ModuleError.js +0 -2
- package/lib/ModuleNotFoundError.js +0 -2
- package/lib/ModuleParseError.js +0 -2
- package/lib/ModuleRestoreError.js +0 -2
- package/lib/ModuleStoreError.js +0 -2
- package/lib/ModuleWarning.js +0 -2
- package/lib/NoModeWarning.js +0 -2
- package/lib/NormalModule.js +4 -3
- package/lib/NormalModuleFactory.js +2 -0
- package/lib/UnsupportedFeatureWarning.js +0 -2
- package/lib/WarnDeprecatedOptionPlugin.js +0 -2
- package/lib/Watching.js +21 -14
- package/lib/WebpackError.js +0 -2
- package/lib/asset/AssetGenerator.js +27 -6
- package/lib/asset/AssetModulesPlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +3 -0
- package/lib/config/defaults.js +9 -1
- package/lib/config/normalization.js +1 -0
- package/lib/config/target.js +7 -2
- package/lib/dependencies/ContextElementDependency.js +6 -1
- package/lib/dependencies/CriticalDependencyWarning.js +0 -2
- package/lib/dependencies/ImportParserPlugin.js +1 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +0 -2
- package/lib/dependencies/SystemPlugin.js +0 -2
- package/lib/errors/BuildCycleError.js +0 -1
- package/lib/hmr/LazyCompilationPlugin.js +3 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +9 -0
- package/lib/performance/AssetsOverSizeLimitWarning.js +0 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +0 -2
- package/lib/performance/NoAsyncChunksWarning.js +0 -2
- package/lib/schemes/DataUriPlugin.js +21 -2
- package/lib/serialization/BinaryMiddleware.js +3 -0
- package/lib/serialization/SerializerMiddleware.js +19 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +5 -4
- package/lib/util/ArrayQueue.js +8 -0
- package/lib/util/AsyncQueue.js +9 -0
- package/lib/util/createHash.js +5 -4
- package/lib/util/serialization.js +108 -59
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +0 -2
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +0 -2
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +8 -0
- package/types.d.ts +24 -5
- package/lib/util/DataURI.js +0 -32
package/lib/Watching.js
CHANGED
@@ -90,9 +90,13 @@ class Watching {
|
|
90
90
|
this.running = true;
|
91
91
|
if (this.watcher) {
|
92
92
|
this.pausedWatcher = this.watcher;
|
93
|
+
this.lastWatcherStartTime = Date.now();
|
93
94
|
this.watcher.pause();
|
94
95
|
this.watcher = null;
|
96
|
+
} else if (!this.lastWatcherStartTime) {
|
97
|
+
this.lastWatcherStartTime = Date.now();
|
95
98
|
}
|
99
|
+
this.compiler.fsStartTime = Date.now();
|
96
100
|
this._mergeWithCollected(
|
97
101
|
changedFiles ||
|
98
102
|
(this.pausedWatcher &&
|
@@ -104,6 +108,19 @@ class Watching {
|
|
104
108
|
this.pausedWatcher.getAggregatedRemovals &&
|
105
109
|
this.pausedWatcher.getAggregatedRemovals()))
|
106
110
|
);
|
111
|
+
|
112
|
+
this.compiler.modifiedFiles = this._collectedChangedFiles;
|
113
|
+
this._collectedChangedFiles = undefined;
|
114
|
+
this.compiler.removedFiles = this._collectedRemovedFiles;
|
115
|
+
this._collectedRemovedFiles = undefined;
|
116
|
+
|
117
|
+
this.compiler.fileTimestamps =
|
118
|
+
fileTimeInfoEntries ||
|
119
|
+
(this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
|
120
|
+
this.compiler.contextTimestamps =
|
121
|
+
contextTimeInfoEntries ||
|
122
|
+
(this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
|
123
|
+
|
107
124
|
const run = () => {
|
108
125
|
if (this.compiler.idle) {
|
109
126
|
return this.compiler.cache.endIdle(err => {
|
@@ -120,19 +137,6 @@ class Watching {
|
|
120
137
|
run();
|
121
138
|
});
|
122
139
|
}
|
123
|
-
|
124
|
-
this.compiler.modifiedFiles = this._collectedChangedFiles;
|
125
|
-
this._collectedChangedFiles = undefined;
|
126
|
-
this.compiler.removedFiles = this._collectedRemovedFiles;
|
127
|
-
this._collectedRemovedFiles = undefined;
|
128
|
-
|
129
|
-
this.compiler.fileTimestamps =
|
130
|
-
fileTimeInfoEntries ||
|
131
|
-
(this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
|
132
|
-
this.compiler.contextTimestamps =
|
133
|
-
contextTimeInfoEntries ||
|
134
|
-
(this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
|
135
|
-
|
136
140
|
this.invalid = false;
|
137
141
|
this._invalidReported = false;
|
138
142
|
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
|
@@ -295,7 +299,7 @@ class Watching {
|
|
295
299
|
files,
|
296
300
|
dirs,
|
297
301
|
missing,
|
298
|
-
this.
|
302
|
+
this.lastWatcherStartTime,
|
299
303
|
this.watchOptions,
|
300
304
|
(
|
301
305
|
err,
|
@@ -309,6 +313,7 @@ class Watching {
|
|
309
313
|
this.compiler.removedFiles = undefined;
|
310
314
|
this.compiler.fileTimestamps = undefined;
|
311
315
|
this.compiler.contextTimestamps = undefined;
|
316
|
+
this.compiler.fsStartTime = undefined;
|
312
317
|
return this.handler(err);
|
313
318
|
}
|
314
319
|
this._invalidate(
|
@@ -357,6 +362,7 @@ class Watching {
|
|
357
362
|
}
|
358
363
|
|
359
364
|
if (this.running) {
|
365
|
+
this._mergeWithCollected(changedFiles, removedFiles);
|
360
366
|
this.invalid = true;
|
361
367
|
} else {
|
362
368
|
this._go(
|
@@ -399,6 +405,7 @@ class Watching {
|
|
399
405
|
this.compiler.removedFiles = undefined;
|
400
406
|
this.compiler.fileTimestamps = undefined;
|
401
407
|
this.compiler.contextTimestamps = undefined;
|
408
|
+
this.compiler.fsStartTime = undefined;
|
402
409
|
const shutdown = () => {
|
403
410
|
this.compiler.cache.shutdown(err => {
|
404
411
|
this.compiler.hooks.watchClose.call();
|
package/lib/WebpackError.js
CHANGED
@@ -120,12 +120,33 @@ class AssetGenerator extends Generator {
|
|
120
120
|
}
|
121
121
|
);
|
122
122
|
} else {
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
123
|
+
/** @type {string | false | undefined} */
|
124
|
+
let encoding = this.dataUrlOptions.encoding;
|
125
|
+
if (encoding === undefined) {
|
126
|
+
if (
|
127
|
+
module.resourceResolveData &&
|
128
|
+
module.resourceResolveData.encoding !== undefined
|
129
|
+
) {
|
130
|
+
encoding = module.resourceResolveData.encoding;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
if (encoding === undefined) {
|
134
|
+
encoding = "base64";
|
135
|
+
}
|
136
|
+
let ext;
|
137
|
+
let mimeType = this.dataUrlOptions.mimetype;
|
138
|
+
if (mimeType === undefined) {
|
139
|
+
ext = path.extname(module.nameForCondition());
|
140
|
+
if (
|
141
|
+
module.resourceResolveData &&
|
142
|
+
module.resourceResolveData.mimetype !== undefined
|
143
|
+
) {
|
144
|
+
mimeType = module.resourceResolveData.mimetype;
|
145
|
+
} else if (ext) {
|
146
|
+
mimeType = mimeTypes.lookup(ext);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
if (typeof mimeType !== "string") {
|
129
150
|
throw new Error(
|
130
151
|
"DataUrl can't be generated automatically, " +
|
131
152
|
`because there is no mimetype for "${ext}" in mimetype database. ` +
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const FileSystemInfo = require("../FileSystemInfo");
|
9
9
|
const ProgressPlugin = require("../ProgressPlugin");
|
10
10
|
const { formatSize } = require("../SizeFormatHelpers");
|
11
|
+
const SerializerMiddleware = require("../serialization/SerializerMiddleware");
|
11
12
|
const LazySet = require("../util/LazySet");
|
12
13
|
const makeSerializable = require("../util/makeSerializable");
|
13
14
|
const memoize = require("../util/memoize");
|
@@ -715,6 +716,7 @@ class PackContent {
|
|
715
716
|
this.logger.timeEnd(timeMessage);
|
716
717
|
}
|
717
718
|
this.content = map;
|
719
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
718
720
|
return map.get(identifier);
|
719
721
|
});
|
720
722
|
} else {
|
@@ -723,6 +725,7 @@ class PackContent {
|
|
723
725
|
this.logger.timeEnd(timeMessage);
|
724
726
|
}
|
725
727
|
this.content = map;
|
728
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
726
729
|
return map.get(identifier);
|
727
730
|
}
|
728
731
|
}
|
package/lib/config/defaults.js
CHANGED
@@ -478,7 +478,15 @@ const applyModuleDefaults = (
|
|
478
478
|
},
|
479
479
|
{
|
480
480
|
dependency: "url",
|
481
|
-
|
481
|
+
oneOf: [
|
482
|
+
{
|
483
|
+
scheme: /^data$/,
|
484
|
+
type: "asset/inline"
|
485
|
+
},
|
486
|
+
{
|
487
|
+
type: "asset/resource"
|
488
|
+
}
|
489
|
+
]
|
482
490
|
}
|
483
491
|
];
|
484
492
|
if (asyncWebAssembly) {
|
@@ -129,6 +129,7 @@ const getNormalizedWebpackOptions = config => {
|
|
129
129
|
case "filesystem":
|
130
130
|
return {
|
131
131
|
type: "filesystem",
|
132
|
+
allowCollectingMemory: cache.allowCollectingMemory,
|
132
133
|
maxMemoryGenerations: cache.maxMemoryGenerations,
|
133
134
|
maxAge: cache.maxAge,
|
134
135
|
profile: cache.profile,
|
package/lib/config/target.js
CHANGED
@@ -5,14 +5,18 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const
|
8
|
+
const memoize = require("../util/memoize");
|
9
|
+
|
10
|
+
const getBrowserslistTargetHandler = memoize(() =>
|
11
|
+
require("./browserslistTargetHandler")
|
12
|
+
);
|
9
13
|
|
10
14
|
/**
|
11
15
|
* @param {string} context the context directory
|
12
16
|
* @returns {string} default target
|
13
17
|
*/
|
14
18
|
const getDefaultTarget = context => {
|
15
|
-
const browsers =
|
19
|
+
const browsers = getBrowserslistTargetHandler().load(null, context);
|
16
20
|
return browsers ? "browserslist" : "web";
|
17
21
|
};
|
18
22
|
|
@@ -78,6 +82,7 @@ const TARGETS = [
|
|
78
82
|
"Resolve features from browserslist. Will resolve browserslist config automatically. Only browser or node queries are supported (electron is not supported). Examples: 'browserslist:modern' to use 'modern' environment from browserslist config",
|
79
83
|
/^browserslist(?::(.+))?$/,
|
80
84
|
(rest, context) => {
|
85
|
+
const browserslistTargetHandler = getBrowserslistTargetHandler();
|
81
86
|
const browsers = browserslistTargetHandler.load(
|
82
87
|
rest ? rest.trim() : null,
|
83
88
|
context
|
@@ -14,9 +14,10 @@ const ModuleDependency = require("./ModuleDependency");
|
|
14
14
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
15
15
|
|
16
16
|
class ContextElementDependency extends ModuleDependency {
|
17
|
-
constructor(request, userRequest, category, referencedExports) {
|
17
|
+
constructor(request, userRequest, typePrefix, category, referencedExports) {
|
18
18
|
super(request);
|
19
19
|
this.referencedExports = referencedExports;
|
20
|
+
this._typePrefix = typePrefix;
|
20
21
|
this._category = category;
|
21
22
|
|
22
23
|
if (userRequest) {
|
@@ -25,6 +26,10 @@ class ContextElementDependency extends ModuleDependency {
|
|
25
26
|
}
|
26
27
|
|
27
28
|
get type() {
|
29
|
+
if (this._typePrefix) {
|
30
|
+
return `${this._typePrefix} context element`;
|
31
|
+
}
|
32
|
+
|
28
33
|
return "context element";
|
29
34
|
}
|
30
35
|
|
@@ -350,7 +350,9 @@ class LazyCompilationPlugin {
|
|
350
350
|
resolveData.dependencies.every(
|
351
351
|
dep =>
|
352
352
|
IGNORED_DEPENDENCY_TYPES.has(dep.type) ||
|
353
|
-
(this.imports &&
|
353
|
+
(this.imports &&
|
354
|
+
(dep.type === "import()" ||
|
355
|
+
dep.type === "import() context element")) ||
|
354
356
|
(this.entries && dep.type === "entry")
|
355
357
|
) &&
|
356
358
|
!/webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client/.test(
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const eslintScope = require("eslint-scope");
|
9
|
+
const Referencer = require("eslint-scope/lib/referencer");
|
9
10
|
const {
|
10
11
|
CachedSource,
|
11
12
|
ConcatSource,
|
@@ -58,6 +59,14 @@ const {
|
|
58
59
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
59
60
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
60
61
|
|
62
|
+
// fix eslint-scope to support class properties correctly
|
63
|
+
// cspell:word Referencer
|
64
|
+
const ReferencerClass = Referencer;
|
65
|
+
if (!ReferencerClass.prototype.PropertyDefinition) {
|
66
|
+
ReferencerClass.prototype.PropertyDefinition =
|
67
|
+
ReferencerClass.prototype.Property;
|
68
|
+
}
|
69
|
+
|
61
70
|
/**
|
62
71
|
* @typedef {Object} ReexportInfo
|
63
72
|
* @property {Module} module
|
@@ -6,10 +6,25 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const NormalModule = require("../NormalModule");
|
9
|
-
const { getMimetype, decodeDataURI } = require("../util/DataURI");
|
10
9
|
|
11
10
|
/** @typedef {import("../Compiler")} Compiler */
|
12
11
|
|
12
|
+
// data URL scheme: "data:text/javascript;charset=utf-8;base64,some-string"
|
13
|
+
// http://www.ietf.org/rfc/rfc2397.txt
|
14
|
+
const URIRegEx = /^data:(?:[^;,]+)?(?:(?:;[^;,]+)*?)(;base64)?,(.*)$/i;
|
15
|
+
const URIMetaRegEx = /^data:([^;,]+)?(?:(?:;[^;,]+)*?)(?:;(base64))?,/i;
|
16
|
+
|
17
|
+
const decodeDataURI = uri => {
|
18
|
+
const match = URIRegEx.exec(uri);
|
19
|
+
if (!match) return null;
|
20
|
+
|
21
|
+
const isBase64 = match[1];
|
22
|
+
const body = match[2];
|
23
|
+
return isBase64
|
24
|
+
? Buffer.from(body, "base64")
|
25
|
+
: Buffer.from(decodeURIComponent(body), "ascii");
|
26
|
+
};
|
27
|
+
|
13
28
|
class DataUriPlugin {
|
14
29
|
/**
|
15
30
|
* Apply the plugin
|
@@ -23,7 +38,11 @@ class DataUriPlugin {
|
|
23
38
|
normalModuleFactory.hooks.resolveForScheme
|
24
39
|
.for("data")
|
25
40
|
.tap("DataUriPlugin", resourceData => {
|
26
|
-
|
41
|
+
const match = URIMetaRegEx.exec(resourceData.resource);
|
42
|
+
if (match) {
|
43
|
+
resourceData.data.mimetype = match[1] || "";
|
44
|
+
resourceData.data.encoding = match[2] || false;
|
45
|
+
}
|
27
46
|
});
|
28
47
|
NormalModule.getCompilationHooks(compilation)
|
29
48
|
.readResourceForScheme.for("data")
|
@@ -100,6 +100,9 @@ const F64_SIZE = 8;
|
|
100
100
|
const MEASURE_START_OPERATION = Symbol("MEASURE_START_OPERATION");
|
101
101
|
const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
|
102
102
|
|
103
|
+
/** @typedef {typeof MEASURE_START_OPERATION} MEASURE_START_OPERATION_TYPE */
|
104
|
+
/** @typedef {typeof MEASURE_END_OPERATION} MEASURE_END_OPERATION_TYPE */
|
105
|
+
|
103
106
|
const identifyNumber = n => {
|
104
107
|
if (n === (n | 0)) {
|
105
108
|
if (n <= 127 && n >= -128) return 0;
|
@@ -126,6 +126,25 @@ class SerializerMiddleware {
|
|
126
126
|
fn[LAZY_SERIALIZED_VALUE] = lazy;
|
127
127
|
return fn;
|
128
128
|
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* @param {function(): Promise<any> | any} lazy lazy function
|
132
|
+
* @returns {function(): Promise<any> | any} new lazy
|
133
|
+
*/
|
134
|
+
static unMemoizeLazy(lazy) {
|
135
|
+
if (!SerializerMiddleware.isLazy(lazy)) return lazy;
|
136
|
+
const fn = () => {
|
137
|
+
throw new Error(
|
138
|
+
"A lazy value that has been unmemorized can't be called again"
|
139
|
+
);
|
140
|
+
};
|
141
|
+
fn[LAZY_SERIALIZED_VALUE] = SerializerMiddleware.unMemoizeLazy(
|
142
|
+
lazy[LAZY_SERIALIZED_VALUE]
|
143
|
+
);
|
144
|
+
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
145
|
+
fn.options = /** @type {any} */ (lazy).options;
|
146
|
+
return fn;
|
147
|
+
}
|
129
148
|
}
|
130
149
|
|
131
150
|
module.exports = SerializerMiddleware;
|
@@ -10,7 +10,6 @@ const ModuleDependency = require("../dependencies/ModuleDependency");
|
|
10
10
|
const formatLocation = require("../formatLocation");
|
11
11
|
const { LogType } = require("../logging/Logger");
|
12
12
|
const AggressiveSplittingPlugin = require("../optimize/AggressiveSplittingPlugin");
|
13
|
-
const ConcatenatedModule = require("../optimize/ConcatenatedModule");
|
14
13
|
const SizeLimitsPlugin = require("../performance/SizeLimitsPlugin");
|
15
14
|
const { countIterable } = require("../util/IterableHelpers");
|
16
15
|
const {
|
@@ -1227,11 +1226,13 @@ const SIMPLE_EXTRACTORS = {
|
|
1227
1226
|
},
|
1228
1227
|
nestedModules: (object, module, context, options, factory) => {
|
1229
1228
|
const { type } = context;
|
1230
|
-
|
1231
|
-
|
1229
|
+
const innerModules = /** @type {Module & { modules?: Module[] }} */ (
|
1230
|
+
module
|
1231
|
+
).modules;
|
1232
|
+
if (Array.isArray(innerModules)) {
|
1232
1233
|
const groupedModules = factory.create(
|
1233
1234
|
`${type.slice(0, -8)}.modules`,
|
1234
|
-
|
1235
|
+
innerModules,
|
1235
1236
|
context
|
1236
1237
|
);
|
1237
1238
|
const limited = spaceLimited(
|
package/lib/util/ArrayQueue.js
CHANGED
@@ -27,6 +27,14 @@ class ArrayQueue {
|
|
27
27
|
return this._list.length + this._listReversed.length;
|
28
28
|
}
|
29
29
|
|
30
|
+
/**
|
31
|
+
* Empties the queue.
|
32
|
+
*/
|
33
|
+
clear() {
|
34
|
+
this._list.length = 0;
|
35
|
+
this._listReversed.length = 0;
|
36
|
+
}
|
37
|
+
|
30
38
|
/**
|
31
39
|
* Appends the specified element to this queue.
|
32
40
|
* @param {T} item The element to add.
|
package/lib/util/AsyncQueue.js
CHANGED
@@ -359,6 +359,15 @@ class AsyncQueue {
|
|
359
359
|
inHandleResult--;
|
360
360
|
});
|
361
361
|
}
|
362
|
+
|
363
|
+
clear() {
|
364
|
+
this._entries.clear();
|
365
|
+
this._queued.clear();
|
366
|
+
this._activeTasks = 0;
|
367
|
+
this._willEnsureProcessing = false;
|
368
|
+
this._needProcessing = false;
|
369
|
+
this._stopped = false;
|
370
|
+
}
|
362
371
|
}
|
363
372
|
|
364
373
|
module.exports = AsyncQueue;
|
package/lib/util/createHash.js
CHANGED
@@ -67,6 +67,7 @@ class BulkUpdateDecorator extends Hash {
|
|
67
67
|
*/
|
68
68
|
digest(encoding) {
|
69
69
|
let digestCache;
|
70
|
+
const buffer = this.buffer;
|
70
71
|
if (this.hash === undefined) {
|
71
72
|
// short data for hash, we can use caching
|
72
73
|
const cacheKey = `${this.hashKey}-${encoding}`;
|
@@ -74,18 +75,18 @@ class BulkUpdateDecorator extends Hash {
|
|
74
75
|
if (digestCache === undefined) {
|
75
76
|
digestCache = digestCaches[cacheKey] = new Map();
|
76
77
|
}
|
77
|
-
const cacheEntry = digestCache.get(
|
78
|
+
const cacheEntry = digestCache.get(buffer);
|
78
79
|
if (cacheEntry !== undefined) return cacheEntry;
|
79
80
|
this.hash = this.hashFactory();
|
80
81
|
}
|
81
|
-
if (
|
82
|
-
this.hash.update(
|
82
|
+
if (buffer.length > 0) {
|
83
|
+
this.hash.update(buffer);
|
83
84
|
}
|
84
85
|
const digestResult = this.hash.digest(encoding);
|
85
86
|
const result =
|
86
87
|
typeof digestResult === "string" ? digestResult : digestResult.toString();
|
87
88
|
if (digestCache !== undefined) {
|
88
|
-
digestCache.set(
|
89
|
+
digestCache.set(buffer, result);
|
89
90
|
}
|
90
91
|
return result;
|
91
92
|
}
|