webpack 5.52.1 → 5.55.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/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 +586 -143
- package/lib/Compiler.js +13 -4
- package/lib/Dependency.js +11 -0
- package/lib/DependencyTemplates.js +8 -2
- package/lib/EvalDevToolModulePlugin.js +2 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +18 -9
- package/lib/FileSystemInfo.js +101 -170
- package/lib/FlagDependencyExportsPlugin.js +25 -16
- package/lib/JavascriptMetaInfoPlugin.js +6 -1
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleFilenameHelpers.js +21 -7
- package/lib/ModuleGraph.js +90 -21
- package/lib/NodeStuffInWebError.js +34 -0
- package/lib/NodeStuffPlugin.js +59 -16
- package/lib/NormalModuleFactory.js +8 -43
- package/lib/SourceMapDevToolPlugin.js +7 -3
- package/lib/WebpackOptionsApply.js +19 -1
- package/lib/cache/PackFileCacheStrategy.js +11 -1
- package/lib/cache/getLazyHashedEtag.js +35 -8
- package/lib/config/defaults.js +32 -12
- package/lib/dependencies/CachedConstDependency.js +4 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
- package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
- package/lib/dependencies/ConstDependency.js +12 -4
- package/lib/dependencies/ContextDependency.js +8 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
- package/lib/dependencies/HarmonyImportDependency.js +4 -1
- package/lib/dependencies/JsonExportsDependency.js +7 -1
- package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
- package/lib/dependencies/ModuleDependency.js +8 -0
- package/lib/dependencies/NullDependency.js +8 -4
- package/lib/dependencies/ProvidedDependency.js +6 -2
- package/lib/dependencies/PureExpressionDependency.js +5 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
- 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/ModuleConcatenationPlugin.js +2 -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 +19 -8
- package/lib/util/WeakTupleMap.js +95 -92
- 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 +1 -0
- package/lib/util/serialization.js +4 -4
- package/package.json +11 -7
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +19 -3
- 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 +215 -25
@@ -15,6 +15,7 @@ const { countIterable } = require("../util/IterableHelpers");
|
|
15
15
|
const { first, combine } = require("../util/SetHelpers");
|
16
16
|
const makeSerializable = require("../util/makeSerializable");
|
17
17
|
const propertyAccess = require("../util/propertyAccess");
|
18
|
+
const { getRuntimeKey, keyToRuntime } = require("../util/runtime");
|
18
19
|
const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
19
20
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
20
21
|
const processExportInfo = require("./processExportInfo");
|
@@ -23,6 +24,7 @@ const processExportInfo = require("./processExportInfo");
|
|
23
24
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
24
25
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
25
26
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
27
|
+
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
26
28
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
27
29
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
28
30
|
/** @typedef {import("../ExportsInfo")} ExportsInfo */
|
@@ -149,6 +151,172 @@ const findDependencyForName = (
|
|
149
151
|
return undefined;
|
150
152
|
};
|
151
153
|
|
154
|
+
/**
|
155
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
156
|
+
* @param {HarmonyExportImportedSpecifierDependency} dep the dependency
|
157
|
+
* @param {string} runtimeKey the runtime key
|
158
|
+
* @returns {ExportMode} the export mode
|
159
|
+
*/
|
160
|
+
const getMode = (moduleGraph, dep, runtimeKey) => {
|
161
|
+
const importedModule = moduleGraph.getModule(dep);
|
162
|
+
|
163
|
+
if (!importedModule) {
|
164
|
+
const mode = new ExportMode("missing");
|
165
|
+
|
166
|
+
mode.userRequest = dep.userRequest;
|
167
|
+
|
168
|
+
return mode;
|
169
|
+
}
|
170
|
+
|
171
|
+
const name = dep.name;
|
172
|
+
const runtime = keyToRuntime(runtimeKey);
|
173
|
+
const parentModule = moduleGraph.getParentModule(dep);
|
174
|
+
const exportsInfo = moduleGraph.getExportsInfo(parentModule);
|
175
|
+
|
176
|
+
if (
|
177
|
+
name
|
178
|
+
? exportsInfo.getUsed(name, runtime) === UsageState.Unused
|
179
|
+
: exportsInfo.isUsed(runtime) === false
|
180
|
+
) {
|
181
|
+
const mode = new ExportMode("unused");
|
182
|
+
|
183
|
+
mode.name = name || "*";
|
184
|
+
|
185
|
+
return mode;
|
186
|
+
}
|
187
|
+
|
188
|
+
const importedExportsType = importedModule.getExportsType(
|
189
|
+
moduleGraph,
|
190
|
+
parentModule.buildMeta.strictHarmonyModule
|
191
|
+
);
|
192
|
+
|
193
|
+
const ids = dep.getIds(moduleGraph);
|
194
|
+
|
195
|
+
// Special handling for reexporting the default export
|
196
|
+
// from non-namespace modules
|
197
|
+
if (name && ids.length > 0 && ids[0] === "default") {
|
198
|
+
switch (importedExportsType) {
|
199
|
+
case "dynamic": {
|
200
|
+
const mode = new ExportMode("reexport-dynamic-default");
|
201
|
+
|
202
|
+
mode.name = name;
|
203
|
+
|
204
|
+
return mode;
|
205
|
+
}
|
206
|
+
case "default-only":
|
207
|
+
case "default-with-named": {
|
208
|
+
const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
|
209
|
+
const mode = new ExportMode("reexport-named-default");
|
210
|
+
|
211
|
+
mode.name = name;
|
212
|
+
mode.partialNamespaceExportInfo = exportInfo;
|
213
|
+
|
214
|
+
return mode;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
// reexporting with a fixed name
|
220
|
+
if (name) {
|
221
|
+
let mode;
|
222
|
+
const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
|
223
|
+
|
224
|
+
if (ids.length > 0) {
|
225
|
+
// export { name as name }
|
226
|
+
switch (importedExportsType) {
|
227
|
+
case "default-only":
|
228
|
+
mode = new ExportMode("reexport-undefined");
|
229
|
+
mode.name = name;
|
230
|
+
break;
|
231
|
+
default:
|
232
|
+
mode = new ExportMode("normal-reexport");
|
233
|
+
mode.items = [
|
234
|
+
new NormalReexportItem(name, ids, exportInfo, false, false)
|
235
|
+
];
|
236
|
+
break;
|
237
|
+
}
|
238
|
+
} else {
|
239
|
+
// export * as name
|
240
|
+
switch (importedExportsType) {
|
241
|
+
case "default-only":
|
242
|
+
mode = new ExportMode("reexport-fake-namespace-object");
|
243
|
+
mode.name = name;
|
244
|
+
mode.partialNamespaceExportInfo = exportInfo;
|
245
|
+
mode.fakeType = 0;
|
246
|
+
break;
|
247
|
+
case "default-with-named":
|
248
|
+
mode = new ExportMode("reexport-fake-namespace-object");
|
249
|
+
mode.name = name;
|
250
|
+
mode.partialNamespaceExportInfo = exportInfo;
|
251
|
+
mode.fakeType = 2;
|
252
|
+
break;
|
253
|
+
case "dynamic":
|
254
|
+
default:
|
255
|
+
mode = new ExportMode("reexport-namespace-object");
|
256
|
+
mode.name = name;
|
257
|
+
mode.partialNamespaceExportInfo = exportInfo;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
return mode;
|
262
|
+
}
|
263
|
+
|
264
|
+
// Star reexporting
|
265
|
+
|
266
|
+
const { ignoredExports, exports, checked, hidden } = dep.getStarReexports(
|
267
|
+
moduleGraph,
|
268
|
+
runtime,
|
269
|
+
exportsInfo,
|
270
|
+
importedModule
|
271
|
+
);
|
272
|
+
if (!exports) {
|
273
|
+
// We have too few info about the modules
|
274
|
+
// Delegate the logic to the runtime code
|
275
|
+
|
276
|
+
const mode = new ExportMode("dynamic-reexport");
|
277
|
+
mode.ignored = ignoredExports;
|
278
|
+
mode.hidden = hidden;
|
279
|
+
|
280
|
+
return mode;
|
281
|
+
}
|
282
|
+
|
283
|
+
if (exports.size === 0) {
|
284
|
+
const mode = new ExportMode("empty-star");
|
285
|
+
mode.hidden = hidden;
|
286
|
+
|
287
|
+
return mode;
|
288
|
+
}
|
289
|
+
|
290
|
+
const mode = new ExportMode("normal-reexport");
|
291
|
+
|
292
|
+
mode.items = Array.from(
|
293
|
+
exports,
|
294
|
+
exportName =>
|
295
|
+
new NormalReexportItem(
|
296
|
+
exportName,
|
297
|
+
[exportName],
|
298
|
+
exportsInfo.getReadOnlyExportInfo(exportName),
|
299
|
+
checked.has(exportName),
|
300
|
+
false
|
301
|
+
)
|
302
|
+
);
|
303
|
+
if (hidden !== undefined) {
|
304
|
+
for (const exportName of hidden) {
|
305
|
+
mode.items.push(
|
306
|
+
new NormalReexportItem(
|
307
|
+
exportName,
|
308
|
+
[exportName],
|
309
|
+
exportsInfo.getReadOnlyExportInfo(exportName),
|
310
|
+
false,
|
311
|
+
true
|
312
|
+
)
|
313
|
+
);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
return mode;
|
318
|
+
};
|
319
|
+
|
152
320
|
class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
153
321
|
/**
|
154
322
|
* @param {string} request the request string
|
@@ -180,7 +348,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
180
348
|
this.otherStarExports = otherStarExports;
|
181
349
|
this.strictExportPresence = strictExportPresence;
|
182
350
|
this.allStarExports = allStarExports;
|
183
|
-
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
355
|
+
*/
|
356
|
+
couldAffectReferencingModule() {
|
357
|
+
return Dependency.TRANSITIVE;
|
184
358
|
}
|
185
359
|
|
186
360
|
// TODO webpack 6 remove
|
@@ -225,169 +399,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
225
399
|
* @returns {ExportMode} the export mode
|
226
400
|
*/
|
227
401
|
getMode(moduleGraph, runtime) {
|
228
|
-
return moduleGraph.
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
* @param {ModuleGraph} moduleGraph the module graph
|
233
|
-
* @param {RuntimeSpec} runtime the runtime
|
234
|
-
* @returns {ExportMode} the export mode
|
235
|
-
*/
|
236
|
-
_getMode(moduleGraph, runtime) {
|
237
|
-
const name = this.name;
|
238
|
-
const ids = this.getIds(moduleGraph);
|
239
|
-
const parentModule = moduleGraph.getParentModule(this);
|
240
|
-
const importedModule = moduleGraph.getModule(this);
|
241
|
-
const exportsInfo = moduleGraph.getExportsInfo(parentModule);
|
242
|
-
|
243
|
-
if (!importedModule) {
|
244
|
-
const mode = new ExportMode("missing");
|
245
|
-
|
246
|
-
mode.userRequest = this.userRequest;
|
247
|
-
|
248
|
-
return mode;
|
249
|
-
}
|
250
|
-
|
251
|
-
if (
|
252
|
-
name
|
253
|
-
? exportsInfo.getUsed(name, runtime) === UsageState.Unused
|
254
|
-
: exportsInfo.isUsed(runtime) === false
|
255
|
-
) {
|
256
|
-
const mode = new ExportMode("unused");
|
257
|
-
|
258
|
-
mode.name = name || "*";
|
259
|
-
|
260
|
-
return mode;
|
261
|
-
}
|
262
|
-
|
263
|
-
const importedExportsType = importedModule.getExportsType(
|
264
|
-
moduleGraph,
|
265
|
-
parentModule.buildMeta.strictHarmonyModule
|
266
|
-
);
|
267
|
-
|
268
|
-
// Special handling for reexporting the default export
|
269
|
-
// from non-namespace modules
|
270
|
-
if (name && ids.length > 0 && ids[0] === "default") {
|
271
|
-
switch (importedExportsType) {
|
272
|
-
case "dynamic": {
|
273
|
-
const mode = new ExportMode("reexport-dynamic-default");
|
274
|
-
|
275
|
-
mode.name = name;
|
276
|
-
|
277
|
-
return mode;
|
278
|
-
}
|
279
|
-
case "default-only":
|
280
|
-
case "default-with-named": {
|
281
|
-
const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
|
282
|
-
const mode = new ExportMode("reexport-named-default");
|
283
|
-
|
284
|
-
mode.name = name;
|
285
|
-
mode.partialNamespaceExportInfo = exportInfo;
|
286
|
-
|
287
|
-
return mode;
|
288
|
-
}
|
289
|
-
}
|
290
|
-
}
|
291
|
-
|
292
|
-
// reexporting with a fixed name
|
293
|
-
if (name) {
|
294
|
-
let mode;
|
295
|
-
const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
|
296
|
-
|
297
|
-
if (ids.length > 0) {
|
298
|
-
// export { name as name }
|
299
|
-
switch (importedExportsType) {
|
300
|
-
case "default-only":
|
301
|
-
mode = new ExportMode("reexport-undefined");
|
302
|
-
mode.name = name;
|
303
|
-
break;
|
304
|
-
default:
|
305
|
-
mode = new ExportMode("normal-reexport");
|
306
|
-
mode.items = [
|
307
|
-
new NormalReexportItem(name, ids, exportInfo, false, false)
|
308
|
-
];
|
309
|
-
break;
|
310
|
-
}
|
311
|
-
} else {
|
312
|
-
// export * as name
|
313
|
-
switch (importedExportsType) {
|
314
|
-
case "default-only":
|
315
|
-
mode = new ExportMode("reexport-fake-namespace-object");
|
316
|
-
mode.name = name;
|
317
|
-
mode.partialNamespaceExportInfo = exportInfo;
|
318
|
-
mode.fakeType = 0;
|
319
|
-
break;
|
320
|
-
case "default-with-named":
|
321
|
-
mode = new ExportMode("reexport-fake-namespace-object");
|
322
|
-
mode.name = name;
|
323
|
-
mode.partialNamespaceExportInfo = exportInfo;
|
324
|
-
mode.fakeType = 2;
|
325
|
-
break;
|
326
|
-
case "dynamic":
|
327
|
-
default:
|
328
|
-
mode = new ExportMode("reexport-namespace-object");
|
329
|
-
mode.name = name;
|
330
|
-
mode.partialNamespaceExportInfo = exportInfo;
|
331
|
-
}
|
332
|
-
}
|
333
|
-
|
334
|
-
return mode;
|
335
|
-
}
|
336
|
-
|
337
|
-
// Star reexporting
|
338
|
-
|
339
|
-
const { ignoredExports, exports, checked, hidden } = this.getStarReexports(
|
340
|
-
moduleGraph,
|
341
|
-
runtime,
|
342
|
-
exportsInfo,
|
343
|
-
importedModule
|
344
|
-
);
|
345
|
-
if (!exports) {
|
346
|
-
// We have too few info about the modules
|
347
|
-
// Delegate the logic to the runtime code
|
348
|
-
|
349
|
-
const mode = new ExportMode("dynamic-reexport");
|
350
|
-
mode.ignored = ignoredExports;
|
351
|
-
mode.hidden = hidden;
|
352
|
-
|
353
|
-
return mode;
|
354
|
-
}
|
355
|
-
|
356
|
-
if (exports.size === 0) {
|
357
|
-
const mode = new ExportMode("empty-star");
|
358
|
-
mode.hidden = hidden;
|
359
|
-
|
360
|
-
return mode;
|
361
|
-
}
|
362
|
-
|
363
|
-
const mode = new ExportMode("normal-reexport");
|
364
|
-
|
365
|
-
mode.items = Array.from(
|
366
|
-
exports,
|
367
|
-
exportName =>
|
368
|
-
new NormalReexportItem(
|
369
|
-
exportName,
|
370
|
-
[exportName],
|
371
|
-
exportsInfo.getReadOnlyExportInfo(exportName),
|
372
|
-
checked.has(exportName),
|
373
|
-
false
|
374
|
-
)
|
402
|
+
return moduleGraph.dependencyCacheProvide(
|
403
|
+
this,
|
404
|
+
getRuntimeKey(runtime),
|
405
|
+
getMode
|
375
406
|
);
|
376
|
-
if (hidden !== undefined) {
|
377
|
-
for (const exportName of hidden) {
|
378
|
-
mode.items.push(
|
379
|
-
new NormalReexportItem(
|
380
|
-
exportName,
|
381
|
-
[exportName],
|
382
|
-
exportsInfo.getReadOnlyExportInfo(exportName),
|
383
|
-
false,
|
384
|
-
true
|
385
|
-
)
|
386
|
-
);
|
387
|
-
}
|
388
|
-
}
|
389
|
-
|
390
|
-
return mode;
|
391
407
|
}
|
392
408
|
|
393
409
|
/**
|
@@ -282,7 +282,10 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
|
282
282
|
}
|
283
283
|
|
284
284
|
const importStatement = dep.getImportStatement(false, templateContext);
|
285
|
-
if (
|
285
|
+
if (
|
286
|
+
referencedModule &&
|
287
|
+
templateContext.moduleGraph.isAsync(referencedModule)
|
288
|
+
) {
|
286
289
|
templateContext.initFragments.push(
|
287
290
|
new ConditionalInitFragment(
|
288
291
|
importStatement[0],
|
@@ -47,6 +47,7 @@ class JsonExportsDependency extends NullDependency {
|
|
47
47
|
constructor(exports) {
|
48
48
|
super();
|
49
49
|
this.exports = exports;
|
50
|
+
this._hashUpdate = undefined;
|
50
51
|
}
|
51
52
|
|
52
53
|
get type() {
|
@@ -72,7 +73,12 @@ class JsonExportsDependency extends NullDependency {
|
|
72
73
|
* @returns {void}
|
73
74
|
*/
|
74
75
|
updateHash(hash, context) {
|
75
|
-
|
76
|
+
if (this._hashUpdate === undefined) {
|
77
|
+
this._hashUpdate = this.exports
|
78
|
+
? JSON.stringify(this.exports)
|
79
|
+
: "undefined";
|
80
|
+
}
|
81
|
+
hash.update(this._hashUpdate);
|
76
82
|
}
|
77
83
|
|
78
84
|
serialize(context) {
|
@@ -30,6 +30,7 @@ class ModuleDecoratorDependency extends NullDependency {
|
|
30
30
|
super();
|
31
31
|
this.decorator = decorator;
|
32
32
|
this.allowExportsAccess = allowExportsAccess;
|
33
|
+
this._hashUpdate = undefined;
|
33
34
|
}
|
34
35
|
|
35
36
|
/**
|
@@ -69,8 +70,10 @@ class ModuleDecoratorDependency extends NullDependency {
|
|
69
70
|
* @returns {void}
|
70
71
|
*/
|
71
72
|
updateHash(hash, context) {
|
72
|
-
|
73
|
-
|
73
|
+
if (this._hashUpdate === undefined) {
|
74
|
+
this._hashUpdate = `${this.decorator}${this.allowExportsAccess}`;
|
75
|
+
}
|
76
|
+
hash.update(this._hashUpdate);
|
74
77
|
}
|
75
78
|
|
76
79
|
serialize(context) {
|
@@ -9,6 +9,7 @@ const Dependency = require("../Dependency");
|
|
9
9
|
const DependencyTemplate = require("../DependencyTemplate");
|
10
10
|
const memoize = require("../util/memoize");
|
11
11
|
|
12
|
+
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
12
13
|
/** @typedef {import("../Module")} Module */
|
13
14
|
|
14
15
|
const getRawModule = memoize(() => require("../RawModule"));
|
@@ -38,6 +39,13 @@ class ModuleDependency extends Dependency {
|
|
38
39
|
return str;
|
39
40
|
}
|
40
41
|
|
42
|
+
/**
|
43
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
44
|
+
*/
|
45
|
+
couldAffectReferencingModule() {
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
|
41
49
|
/**
|
42
50
|
* @param {string} context context directory
|
43
51
|
* @returns {Module} a module
|
@@ -9,16 +9,20 @@ const Dependency = require("../Dependency");
|
|
9
9
|
const DependencyTemplate = require("../DependencyTemplate");
|
10
10
|
|
11
11
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
|
-
/** @typedef {import("../
|
13
|
-
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
12
|
+
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
14
13
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
|
-
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
|
-
/** @typedef {import("../util/Hash")} Hash */
|
17
14
|
|
18
15
|
class NullDependency extends Dependency {
|
19
16
|
get type() {
|
20
17
|
return "null";
|
21
18
|
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
22
|
+
*/
|
23
|
+
couldAffectReferencingModule() {
|
24
|
+
return false;
|
25
|
+
}
|
22
26
|
}
|
23
27
|
|
24
28
|
NullDependency.Template = class NullDependencyTemplate extends (
|
@@ -34,6 +34,7 @@ class ProvidedDependency extends ModuleDependency {
|
|
34
34
|
this.identifier = identifier;
|
35
35
|
this.path = path;
|
36
36
|
this.range = range;
|
37
|
+
this._hashUpdate = undefined;
|
37
38
|
}
|
38
39
|
|
39
40
|
get type() {
|
@@ -51,8 +52,11 @@ class ProvidedDependency extends ModuleDependency {
|
|
51
52
|
* @returns {void}
|
52
53
|
*/
|
53
54
|
updateHash(hash, context) {
|
54
|
-
|
55
|
-
|
55
|
+
if (this._hashUpdate === undefined) {
|
56
|
+
this._hashUpdate =
|
57
|
+
this.identifier + (this.path ? this.path.join(",") : "null");
|
58
|
+
}
|
59
|
+
hash.update(this._hashUpdate);
|
56
60
|
}
|
57
61
|
|
58
62
|
serialize(context) {
|
@@ -28,6 +28,7 @@ class PureExpressionDependency extends NullDependency {
|
|
28
28
|
this.range = range;
|
29
29
|
/** @type {Set<string> | false} */
|
30
30
|
this.usedByExports = false;
|
31
|
+
this._hashUpdate = undefined;
|
31
32
|
}
|
32
33
|
|
33
34
|
/**
|
@@ -37,7 +38,10 @@ class PureExpressionDependency extends NullDependency {
|
|
37
38
|
* @returns {void}
|
38
39
|
*/
|
39
40
|
updateHash(hash, context) {
|
40
|
-
|
41
|
+
if (this._hashUpdate === undefined) {
|
42
|
+
this._hashUpdate = this.range + "";
|
43
|
+
}
|
44
|
+
hash.update(this._hashUpdate);
|
41
45
|
}
|
42
46
|
|
43
47
|
/**
|
@@ -23,6 +23,7 @@ class RuntimeRequirementsDependency extends NullDependency {
|
|
23
23
|
constructor(runtimeRequirements) {
|
24
24
|
super();
|
25
25
|
this.runtimeRequirements = new Set(runtimeRequirements);
|
26
|
+
this._hashUpdate = undefined;
|
26
27
|
}
|
27
28
|
|
28
29
|
/**
|
@@ -32,7 +33,10 @@ class RuntimeRequirementsDependency extends NullDependency {
|
|
32
33
|
* @returns {void}
|
33
34
|
*/
|
34
35
|
updateHash(hash, context) {
|
35
|
-
|
36
|
+
if (this._hashUpdate === undefined) {
|
37
|
+
this._hashUpdate = Array.from(this.runtimeRequirements).join() + "";
|
38
|
+
}
|
39
|
+
hash.update(this._hashUpdate);
|
36
40
|
}
|
37
41
|
|
38
42
|
serialize(context) {
|
@@ -5,10 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const Dependency = require("../Dependency");
|
8
9
|
const makeSerializable = require("../util/makeSerializable");
|
9
10
|
const ModuleDependency = require("./ModuleDependency");
|
10
11
|
|
11
12
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
13
|
+
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
12
14
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
13
15
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
14
16
|
|
@@ -23,6 +25,13 @@ class WebAssemblyExportImportedDependency extends ModuleDependency {
|
|
23
25
|
this.valueType = valueType;
|
24
26
|
}
|
25
27
|
|
28
|
+
/**
|
29
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
30
|
+
*/
|
31
|
+
couldAffectReferencingModule() {
|
32
|
+
return Dependency.TRANSITIVE;
|
33
|
+
}
|
34
|
+
|
26
35
|
/**
|
27
36
|
* Returns list of exports referenced by this dependency
|
28
37
|
* @param {ModuleGraph} moduleGraph module graph
|
package/lib/ids/IdHelpers.js
CHANGED
@@ -13,14 +13,16 @@ const numberHash = require("../util/numberHash");
|
|
13
13
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
14
|
/** @typedef {import("../Compilation")} Compilation */
|
15
15
|
/** @typedef {import("../Module")} Module */
|
16
|
+
/** @typedef {typeof import("../util/Hash")} Hash */
|
16
17
|
|
17
18
|
/**
|
18
19
|
* @param {string} str string to hash
|
19
20
|
* @param {number} len max length of the hash
|
21
|
+
* @param {string | Hash} hashFunction hash function to use
|
20
22
|
* @returns {string} hash
|
21
23
|
*/
|
22
|
-
const getHash = (str, len) => {
|
23
|
-
const hash = createHash(
|
24
|
+
const getHash = (str, len, hashFunction) => {
|
25
|
+
const hash = createHash(hashFunction);
|
24
26
|
hash.update(str);
|
25
27
|
const digest = /** @type {string} */ (hash.digest("hex"));
|
26
28
|
return digest.substr(0, len);
|
@@ -61,12 +63,15 @@ exports.requestToId = requestToId;
|
|
61
63
|
/**
|
62
64
|
* @param {string} string the string
|
63
65
|
* @param {string} delimiter separator for string and hash
|
66
|
+
* @param {string | Hash} hashFunction hash function to use
|
64
67
|
* @returns {string} string with limited max length to 100 chars
|
65
68
|
*/
|
66
|
-
const shortenLongString = (string, delimiter) => {
|
69
|
+
const shortenLongString = (string, delimiter, hashFunction) => {
|
67
70
|
if (string.length < 100) return string;
|
68
71
|
return (
|
69
|
-
string.slice(0, 100 - 6 - delimiter.length) +
|
72
|
+
string.slice(0, 100 - 6 - delimiter.length) +
|
73
|
+
delimiter +
|
74
|
+
getHash(string, 6, hashFunction)
|
70
75
|
);
|
71
76
|
};
|
72
77
|
|
@@ -92,6 +97,7 @@ exports.getShortModuleName = getShortModuleName;
|
|
92
97
|
* @param {string} shortName the short name
|
93
98
|
* @param {Module} module the module
|
94
99
|
* @param {string} context context directory
|
100
|
+
* @param {string | Hash} hashFunction hash function to use
|
95
101
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
96
102
|
* @returns {string} long module name
|
97
103
|
*/
|
@@ -99,10 +105,11 @@ const getLongModuleName = (
|
|
99
105
|
shortName,
|
100
106
|
module,
|
101
107
|
context,
|
108
|
+
hashFunction,
|
102
109
|
associatedObjectForCache
|
103
110
|
) => {
|
104
111
|
const fullName = getFullModuleName(module, context, associatedObjectForCache);
|
105
|
-
return `${shortName}?${getHash(fullName, 4)}`;
|
112
|
+
return `${shortName}?${getHash(fullName, 4, hashFunction)}`;
|
106
113
|
};
|
107
114
|
exports.getLongModuleName = getLongModuleName;
|
108
115
|
|
@@ -126,6 +133,7 @@ exports.getFullModuleName = getFullModuleName;
|
|
126
133
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
127
134
|
* @param {string} context context directory
|
128
135
|
* @param {string} delimiter delimiter for names
|
136
|
+
* @param {string | Hash} hashFunction hash function to use
|
129
137
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
130
138
|
* @returns {string} short chunk name
|
131
139
|
*/
|
@@ -134,6 +142,7 @@ const getShortChunkName = (
|
|
134
142
|
chunkGraph,
|
135
143
|
context,
|
136
144
|
delimiter,
|
145
|
+
hashFunction,
|
137
146
|
associatedObjectForCache
|
138
147
|
) => {
|
139
148
|
const modules = chunkGraph.getChunkRootModules(chunk);
|
@@ -145,7 +154,7 @@ const getShortChunkName = (
|
|
145
154
|
.concat(shortModuleNames)
|
146
155
|
.filter(Boolean)
|
147
156
|
.join(delimiter);
|
148
|
-
return shortenLongString(chunkName, delimiter);
|
157
|
+
return shortenLongString(chunkName, delimiter, hashFunction);
|
149
158
|
};
|
150
159
|
exports.getShortChunkName = getShortChunkName;
|
151
160
|
|
@@ -154,6 +163,7 @@ exports.getShortChunkName = getShortChunkName;
|
|
154
163
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
155
164
|
* @param {string} context context directory
|
156
165
|
* @param {string} delimiter delimiter for names
|
166
|
+
* @param {string | Hash} hashFunction hash function to use
|
157
167
|
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
|
158
168
|
* @returns {string} short chunk name
|
159
169
|
*/
|
@@ -162,6 +172,7 @@ const getLongChunkName = (
|
|
162
172
|
chunkGraph,
|
163
173
|
context,
|
164
174
|
delimiter,
|
175
|
+
hashFunction,
|
165
176
|
associatedObjectForCache
|
166
177
|
) => {
|
167
178
|
const modules = chunkGraph.getChunkRootModules(chunk);
|
@@ -169,14 +180,16 @@ const getLongChunkName = (
|
|
169
180
|
requestToId(getShortModuleName(m, context, associatedObjectForCache))
|
170
181
|
);
|
171
182
|
const longModuleNames = modules.map(m =>
|
172
|
-
requestToId(
|
183
|
+
requestToId(
|
184
|
+
getLongModuleName("", m, context, hashFunction, associatedObjectForCache)
|
185
|
+
)
|
173
186
|
);
|
174
187
|
chunk.idNameHints.sort();
|
175
188
|
const chunkName = Array.from(chunk.idNameHints)
|
176
189
|
.concat(shortModuleNames, longModuleNames)
|
177
190
|
.filter(Boolean)
|
178
191
|
.join(delimiter);
|
179
|
-
return shortenLongString(chunkName, delimiter);
|
192
|
+
return shortenLongString(chunkName, delimiter, hashFunction);
|
180
193
|
};
|
181
194
|
exports.getLongChunkName = getLongChunkName;
|
182
195
|
|