webpack 5.99.7 → 5.99.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/lib/CacheFacade.js +2 -1
- package/lib/ChunkGraph.js +0 -1
- package/lib/ChunkGroup.js +13 -6
- package/lib/Compilation.js +22 -33
- package/lib/ConstPlugin.js +61 -43
- package/lib/ContextModule.js +1 -1
- package/lib/ContextModuleFactory.js +1 -2
- package/lib/ContextReplacementPlugin.js +2 -1
- package/lib/CssModule.js +0 -1
- package/lib/DefinePlugin.js +2 -2
- package/lib/DelegatedModule.js +18 -8
- package/lib/DelegatedModuleFactoryPlugin.js +9 -7
- package/lib/Dependency.js +10 -11
- package/lib/EvalSourceMapDevToolPlugin.js +1 -1
- package/lib/ExportsInfo.js +35 -16
- package/lib/ExternalModule.js +6 -5
- package/lib/FileSystemInfo.js +2 -4
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/NormalModule.js +38 -19
- package/lib/NormalModuleFactory.js +23 -18
- package/lib/RuntimePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +2 -3
- package/lib/WebpackOptionsApply.js +1 -4
- package/lib/asset/AssetGenerator.js +13 -12
- package/lib/asset/AssetSourceGenerator.js +7 -5
- package/lib/config/defaults.js +10 -6
- package/lib/config/normalization.js +5 -5
- package/lib/css/CssModulesPlugin.js +2 -2
- package/lib/debug/ProfilingPlugin.js +18 -21
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +1 -1
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
- package/lib/dependencies/URLDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -3
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
- package/lib/index.js +11 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -2
- package/lib/javascript/JavascriptParser.js +19 -5
- package/lib/json/JsonModulesPlugin.js +4 -4
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +4 -1
- package/lib/node/nodeConsole.js +3 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +3 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RuntimeChunkPlugin.js +5 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +12 -7
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/rules/BasicEffectRulePlugin.js +1 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +4 -6
- package/lib/schemes/DataUriPlugin.js +3 -1
- package/lib/schemes/HttpUriPlugin.js +154 -149
- package/lib/sharing/ProvideSharedPlugin.js +3 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +13 -13
- package/lib/util/createHash.js +3 -3
- package/package.json +45 -40
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +243 -24
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +468 -156
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.json +0 -16
package/lib/ExportsInfo.js
CHANGED
@@ -34,9 +34,18 @@ const RETURNS_TRUE = () => true;
|
|
34
34
|
|
35
35
|
const CIRCULAR = Symbol("circular target");
|
36
36
|
|
37
|
+
/**
|
38
|
+
* @typedef {object} RestoreProvidedDataExports
|
39
|
+
* @property {ExportInfoName} name
|
40
|
+
* @property {ExportInfo["provided"]} provided
|
41
|
+
* @property {ExportInfo["canMangleProvide"]} canMangleProvide
|
42
|
+
* @property {ExportInfo["terminalBinding"]} terminalBinding
|
43
|
+
* @property {RestoreProvidedData | undefined} exportsInfo
|
44
|
+
*/
|
45
|
+
|
37
46
|
class RestoreProvidedData {
|
38
47
|
/**
|
39
|
-
* @param {
|
48
|
+
* @param {RestoreProvidedDataExports[]} exports exports
|
40
49
|
* @param {ExportInfo["provided"]} otherProvided other provided
|
41
50
|
* @param {ExportInfo["canMangleProvide"]} otherCanMangleProvide other can mangle provide
|
42
51
|
* @param {ExportInfo["terminalBinding"]} otherTerminalBinding other terminal binding
|
@@ -78,7 +87,7 @@ makeSerializable(
|
|
78
87
|
"RestoreProvidedData"
|
79
88
|
);
|
80
89
|
|
81
|
-
/** @typedef {Map<
|
90
|
+
/** @typedef {Map<ExportInfoName, ExportInfo>} Exports */
|
82
91
|
/** @typedef {string | string[] | false} UsedName */
|
83
92
|
|
84
93
|
class ExportsInfo {
|
@@ -131,6 +140,7 @@ class ExportsInfo {
|
|
131
140
|
this._sortExports();
|
132
141
|
}
|
133
142
|
if (this._redirectTo !== undefined) {
|
143
|
+
/** @type {Exports} */
|
134
144
|
const map = new Map(
|
135
145
|
Array.from(this._redirectTo.orderedExports, item => [item.name, item])
|
136
146
|
);
|
@@ -160,6 +170,7 @@ class ExportsInfo {
|
|
160
170
|
*/
|
161
171
|
_sortExportsMap(exports) {
|
162
172
|
if (exports.size > 1) {
|
173
|
+
/** @type {string[]} */
|
163
174
|
const namesInOrder = [];
|
164
175
|
for (const entry of exports.values()) {
|
165
176
|
namesInOrder.push(entry.name);
|
@@ -229,7 +240,7 @@ class ExportsInfo {
|
|
229
240
|
}
|
230
241
|
|
231
242
|
/**
|
232
|
-
* @param {
|
243
|
+
* @param {ExportInfoName} name export name
|
233
244
|
* @returns {ExportInfo} export info for this name
|
234
245
|
*/
|
235
246
|
getOwnExportInfo(name) {
|
@@ -242,7 +253,7 @@ class ExportsInfo {
|
|
242
253
|
}
|
243
254
|
|
244
255
|
/**
|
245
|
-
* @param {
|
256
|
+
* @param {ExportInfoName} name export name
|
246
257
|
* @returns {ExportInfo} export info for this name
|
247
258
|
*/
|
248
259
|
getExportInfo(name) {
|
@@ -257,7 +268,7 @@ class ExportsInfo {
|
|
257
268
|
}
|
258
269
|
|
259
270
|
/**
|
260
|
-
* @param {
|
271
|
+
* @param {ExportInfoName} name export name
|
261
272
|
* @returns {ExportInfo} export info for this name
|
262
273
|
*/
|
263
274
|
getReadOnlyExportInfo(name) {
|
@@ -269,7 +280,7 @@ class ExportsInfo {
|
|
269
280
|
}
|
270
281
|
|
271
282
|
/**
|
272
|
-
* @param {
|
283
|
+
* @param {ExportInfoName[]} name export name
|
273
284
|
* @returns {ExportInfo | undefined} export info for this name
|
274
285
|
*/
|
275
286
|
getReadOnlyExportInfoRecursive(name) {
|
@@ -280,7 +291,7 @@ class ExportsInfo {
|
|
280
291
|
}
|
281
292
|
|
282
293
|
/**
|
283
|
-
* @param {
|
294
|
+
* @param {ExportInfoName[]=} name the export name
|
284
295
|
* @returns {ExportsInfo | undefined} the nested exports info
|
285
296
|
*/
|
286
297
|
getNestedExportsInfo(name) {
|
@@ -327,7 +338,8 @@ class ExportsInfo {
|
|
327
338
|
if (targetKey) {
|
328
339
|
exportInfo.setTarget(
|
329
340
|
targetKey,
|
330
|
-
/** @type {ModuleGraphConnection} */
|
341
|
+
/** @type {ModuleGraphConnection} */
|
342
|
+
(targetModule),
|
331
343
|
[exportInfo.name],
|
332
344
|
-1
|
333
345
|
);
|
@@ -552,6 +564,7 @@ class ExportsInfo {
|
|
552
564
|
return true;
|
553
565
|
}
|
554
566
|
}
|
567
|
+
/** @type {string[]} */
|
555
568
|
const array = [];
|
556
569
|
if (!this._exportsAreOrdered) this._sortExports();
|
557
570
|
for (const exportInfo of this._exports.values()) {
|
@@ -604,7 +617,7 @@ class ExportsInfo {
|
|
604
617
|
}
|
605
618
|
|
606
619
|
/**
|
607
|
-
* @param {
|
620
|
+
* @param {ExportInfoName | ExportInfoName[]} name the name of the export
|
608
621
|
* @returns {boolean | undefined | null} if the export is provided
|
609
622
|
*/
|
610
623
|
isExportProvided(name) {
|
@@ -665,7 +678,7 @@ class ExportsInfo {
|
|
665
678
|
}
|
666
679
|
|
667
680
|
/**
|
668
|
-
* @param {
|
681
|
+
* @param {ExportInfoName | ExportInfoName[]} name export name
|
669
682
|
* @param {RuntimeSpec} runtime check usage for this runtime only
|
670
683
|
* @returns {UsageStateType} usage status
|
671
684
|
*/
|
@@ -683,7 +696,7 @@ class ExportsInfo {
|
|
683
696
|
}
|
684
697
|
|
685
698
|
/**
|
686
|
-
* @param {
|
699
|
+
* @param {ExportInfoName | ExportInfoName[]} name the export name
|
687
700
|
* @param {RuntimeSpec} runtime check usage for this runtime only
|
688
701
|
* @returns {UsedName} the used name
|
689
702
|
*/
|
@@ -698,7 +711,7 @@ class ExportsInfo {
|
|
698
711
|
const x = info.getUsedName(name[0], runtime);
|
699
712
|
if (x === false) return false;
|
700
713
|
const arr =
|
701
|
-
/** @type {
|
714
|
+
/** @type {ExportInfoName[]} */
|
702
715
|
(x === name[0] && name.length === 1 ? name : [x]);
|
703
716
|
if (name.length === 1) {
|
704
717
|
return arr;
|
@@ -755,6 +768,7 @@ class ExportsInfo {
|
|
755
768
|
const otherProvided = this._otherExportsInfo.provided;
|
756
769
|
const otherCanMangleProvide = this._otherExportsInfo.canMangleProvide;
|
757
770
|
const otherTerminalBinding = this._otherExportsInfo.terminalBinding;
|
771
|
+
/** @type {RestoreProvidedDataExports[]} */
|
758
772
|
const exports = [];
|
759
773
|
for (const exportInfo of this.orderedExports) {
|
760
774
|
if (
|
@@ -827,19 +841,24 @@ class ExportsInfo {
|
|
827
841
|
/** @typedef {(module: Module) => boolean} ValidTargetModuleFilter */
|
828
842
|
|
829
843
|
/** @typedef {{ connection: ModuleGraphConnection, export: string[], priority: number }} TargetItem */
|
844
|
+
|
830
845
|
/** @typedef {Map<Dependency | undefined, TargetItem>} Target */
|
831
846
|
|
847
|
+
/** @typedef {string} ExportInfoName */
|
848
|
+
/** @typedef {string | null} ExportInfoUsedName */
|
849
|
+
/** @typedef {boolean | null} ExportInfoProvided */
|
850
|
+
|
832
851
|
class ExportInfo {
|
833
852
|
/**
|
834
|
-
* @param {
|
853
|
+
* @param {ExportInfoName} name the original name of the export
|
835
854
|
* @param {ExportInfo=} initFrom init values from this ExportInfo
|
836
855
|
*/
|
837
856
|
constructor(name, initFrom) {
|
838
|
-
/** @type {
|
857
|
+
/** @type {ExportInfoName} */
|
839
858
|
this.name = name;
|
840
859
|
/**
|
841
860
|
* @private
|
842
|
-
* @type {
|
861
|
+
* @type {ExportInfoUsedName}
|
843
862
|
*/
|
844
863
|
this._usedName = initFrom ? initFrom._usedName : null;
|
845
864
|
/**
|
@@ -867,7 +886,7 @@ class ExportInfo {
|
|
867
886
|
* false: it is not provided
|
868
887
|
* null: only the runtime knows if it is provided
|
869
888
|
* undefined: it was not determined if it is provided
|
870
|
-
* @type {
|
889
|
+
* @type {ExportInfoProvided | undefined}
|
871
890
|
*/
|
872
891
|
this.provided = initFrom ? initFrom.provided : undefined;
|
873
892
|
/**
|
package/lib/ExternalModule.js
CHANGED
@@ -28,6 +28,7 @@ const propertyAccess = require("./util/propertyAccess");
|
|
28
28
|
const { register } = require("./util/serialization");
|
29
29
|
|
30
30
|
/** @typedef {import("webpack-sources").Source} Source */
|
31
|
+
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
31
32
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
32
33
|
/** @typedef {import("./Chunk")} Chunk */
|
33
34
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
@@ -58,7 +59,6 @@ const { register } = require("./util/serialization");
|
|
58
59
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
59
60
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
60
61
|
/** @typedef {import("./util/Hash")} Hash */
|
61
|
-
/** @typedef {typeof import("./util/Hash")} HashConstructor */
|
62
62
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
63
63
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
64
64
|
|
@@ -215,9 +215,10 @@ const getSourceForImportExternal = (
|
|
215
215
|
};
|
216
216
|
|
217
217
|
/**
|
218
|
-
* @
|
219
|
-
* @param {
|
220
|
-
* @
|
218
|
+
* @template {{ [key: string]: string }} T
|
219
|
+
* @param {keyof T} key key
|
220
|
+
* @param {T[keyof T]} value value
|
221
|
+
* @returns {undefined | T[keyof T]} replaced value
|
221
222
|
*/
|
222
223
|
const importAssertionReplacer = (key, value) => {
|
223
224
|
if (key === "_isLegacyAssert") {
|
@@ -235,7 +236,7 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
235
236
|
* @param {string} request import source
|
236
237
|
* @param {string=} ident recomputed ident
|
237
238
|
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
238
|
-
* @param {
|
239
|
+
* @param {HashFunction=} hashFunction the hash function to use
|
239
240
|
*/
|
240
241
|
constructor(
|
241
242
|
request,
|
package/lib/FileSystemInfo.js
CHANGED
@@ -24,7 +24,7 @@ const processAsyncTree = require("./util/processAsyncTree");
|
|
24
24
|
/** @typedef {import("./logging/Logger").Logger} Logger */
|
25
25
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
26
26
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
27
|
-
/** @typedef {
|
27
|
+
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
28
28
|
/** @typedef {import("./util/fs").IStats} IStats */
|
29
29
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
30
30
|
/** @typedef {import("./util/fs").PathLike} PathLike */
|
@@ -708,7 +708,6 @@ class SnapshotOptimization {
|
|
708
708
|
};
|
709
709
|
}
|
710
710
|
this._map.set(path, newOptimizationEntry);
|
711
|
-
continue;
|
712
711
|
} else {
|
713
712
|
optimizationEntries.add(optimizationEntry);
|
714
713
|
}
|
@@ -742,7 +741,6 @@ class SnapshotOptimization {
|
|
742
741
|
continue optimizationEntriesLabel;
|
743
742
|
}
|
744
743
|
nonSharedFiles.add(path);
|
745
|
-
continue;
|
746
744
|
}
|
747
745
|
}
|
748
746
|
if (nonSharedFiles.size === 0) {
|
@@ -1058,7 +1056,7 @@ class FileSystemInfo {
|
|
1058
1056
|
* @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
|
1059
1057
|
* @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
|
1060
1058
|
* @param {Logger=} options.logger logger used to log invalid snapshots
|
1061
|
-
* @param {
|
1059
|
+
* @param {HashFunction=} options.hashFunction the hash function to use
|
1062
1060
|
*/
|
1063
1061
|
constructor(
|
1064
1062
|
fs,
|
package/lib/LibManifestPlugin.js
CHANGED
@@ -19,8 +19,8 @@ const { dirname, mkdirp } = require("./util/fs");
|
|
19
19
|
/**
|
20
20
|
* @typedef {object} ManifestModuleData
|
21
21
|
* @property {string | number} id
|
22
|
-
* @property {BuildMeta} buildMeta
|
23
|
-
* @property {boolean | string[]
|
22
|
+
* @property {BuildMeta=} buildMeta
|
23
|
+
* @property {boolean | string[]=} exports
|
24
24
|
*/
|
25
25
|
|
26
26
|
/**
|
@@ -10,10 +10,11 @@ const { DEFAULTS } = require("./config/defaults");
|
|
10
10
|
const createHash = require("./util/createHash");
|
11
11
|
const memoize = require("./util/memoize");
|
12
12
|
|
13
|
+
/** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */
|
14
|
+
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
13
15
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
14
16
|
/** @typedef {import("./Module")} Module */
|
15
17
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
16
|
-
/** @typedef {typeof import("./util/Hash")} Hash */
|
17
18
|
|
18
19
|
/** @typedef {string | RegExp | (string | RegExp)[]} Matcher */
|
19
20
|
/** @typedef {{ test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
|
@@ -76,7 +77,7 @@ const getBefore = (strFn, token) => () => {
|
|
76
77
|
/**
|
77
78
|
* Returns a function that returns a hash of the string
|
78
79
|
* @param {ReturnStringCallback} strFn the function to get the string
|
79
|
-
* @param {
|
80
|
+
* @param {HashFunction=} hashFunction the hash function to use
|
80
81
|
* @returns {ReturnStringCallback} a function that returns the hash of the string
|
81
82
|
*/
|
82
83
|
const getHash =
|
@@ -117,10 +118,13 @@ const lazyObject = obj => {
|
|
117
118
|
|
118
119
|
const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
119
120
|
|
121
|
+
/** @typedef {((context: TODO) => string)} ModuleFilenameTemplateFunction */
|
122
|
+
/** @typedef {string | ModuleFilenameTemplateFunction} ModuleFilenameTemplate */
|
123
|
+
|
120
124
|
/**
|
121
125
|
* @param {Module | string} module the module
|
122
|
-
* @param {{ namespace?: string, moduleFilenameTemplate?:
|
123
|
-
* @param {{ requestShortener: RequestShortener, chunkGraph: ChunkGraph, hashFunction?:
|
126
|
+
* @param {{ namespace?: string, moduleFilenameTemplate?: ModuleFilenameTemplate }} options options
|
127
|
+
* @param {{ requestShortener: RequestShortener, chunkGraph: ChunkGraph, hashFunction?: HashFunction }} contextInfo context info
|
124
128
|
* @returns {string} the filename
|
125
129
|
*/
|
126
130
|
ModuleFilenameHelpers.createFilename = (
|
package/lib/NormalModule.js
CHANGED
@@ -57,6 +57,7 @@ const memoize = require("./util/memoize");
|
|
57
57
|
/** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
|
58
58
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
59
59
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
60
|
+
/** @typedef {import("../declarations/WebpackOptions").NoParse} NoParse */
|
60
61
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
61
62
|
/** @typedef {import("./Compiler")} Compiler */
|
62
63
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
@@ -80,11 +81,13 @@ const memoize = require("./util/memoize");
|
|
80
81
|
/** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes} JavaScriptModuleTypes */
|
81
82
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
82
83
|
/** @typedef {import("./NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
|
84
|
+
/** @typedef {import("./NormalModuleFactory").ResourceSchemeData} ResourceSchemeData */
|
83
85
|
/** @typedef {import("./Parser")} Parser */
|
84
86
|
/** @typedef {import("./Parser").PreparsedAst} PreparsedAst */
|
85
87
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
86
88
|
/** @typedef {import("./ResolverFactory").ResolveContext} ResolveContext */
|
87
89
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
90
|
+
/** @typedef {import("./ResolverFactory").ResolveRequest} ResolveRequest */
|
88
91
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
89
92
|
/** @typedef {import("./logging/Logger").Logger} WebpackLogger */
|
90
93
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
@@ -92,7 +95,7 @@ const memoize = require("./util/memoize");
|
|
92
95
|
/** @typedef {import("./util/Hash")} Hash */
|
93
96
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
94
97
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
95
|
-
/** @typedef {import("
|
98
|
+
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
96
99
|
/** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
97
100
|
/**
|
98
101
|
* @template T
|
@@ -249,7 +252,7 @@ makeSerializable(
|
|
249
252
|
* @property {string} rawRequest request without resolving
|
250
253
|
* @property {LoaderItem[]} loaders list of loaders
|
251
254
|
* @property {string} resource path + query of the real resource
|
252
|
-
* @property {
|
255
|
+
* @property {(ResourceSchemeData & Partial<ResolveRequest>)=} resourceResolveData resource resolve data
|
253
256
|
* @property {string} context context directory for resolving
|
254
257
|
* @property {string=} matchResource path + query of the matched resource (virtual)
|
255
258
|
* @property {Parser} parser the parser used
|
@@ -586,12 +589,14 @@ class NormalModule extends Module {
|
|
586
589
|
* @param {Compilation} compilation the compilation
|
587
590
|
* @param {InputFileSystem} fs file system from reading
|
588
591
|
* @param {NormalModuleCompilationHooks} hooks the hooks
|
589
|
-
* @returns {import("../declarations/LoaderContext").
|
592
|
+
* @returns {import("../declarations/LoaderContext").LoaderContext<T>} loader context
|
590
593
|
*/
|
591
594
|
_createLoaderContext(resolver, options, compilation, fs, hooks) {
|
592
595
|
const { requestShortener } = compilation.runtimeTemplate;
|
593
596
|
const getCurrentLoaderName = () => {
|
594
|
-
const currentLoader = this.getCurrentLoader(
|
597
|
+
const currentLoader = this.getCurrentLoader(
|
598
|
+
/** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext)
|
599
|
+
);
|
595
600
|
if (!currentLoader) return "(not in loader scope)";
|
596
601
|
return requestShortener.shorten(currentLoader.loader);
|
597
602
|
};
|
@@ -600,13 +605,22 @@ class NormalModule extends Module {
|
|
600
605
|
*/
|
601
606
|
const getResolveContext = () => ({
|
602
607
|
fileDependencies: {
|
603
|
-
add: d =>
|
608
|
+
add: d =>
|
609
|
+
/** @type {LoaderContext<EXPECTED_ANY>} */ (
|
610
|
+
loaderContext
|
611
|
+
).addDependency(d)
|
604
612
|
},
|
605
613
|
contextDependencies: {
|
606
|
-
add: d =>
|
614
|
+
add: d =>
|
615
|
+
/** @type {LoaderContext<EXPECTED_ANY>} */ (
|
616
|
+
loaderContext
|
617
|
+
).addContextDependency(d)
|
607
618
|
},
|
608
619
|
missingDependencies: {
|
609
|
-
add: d =>
|
620
|
+
add: d =>
|
621
|
+
/** @type {LoaderContext<EXPECTED_ANY>} */ (
|
622
|
+
loaderContext
|
623
|
+
).addMissingDependency(d)
|
610
624
|
}
|
611
625
|
});
|
612
626
|
const getAbsolutify = memoize(() =>
|
@@ -649,13 +663,13 @@ class NormalModule extends Module {
|
|
649
663
|
? getContextifyInContext()(request)
|
650
664
|
: getContextify()(context, request),
|
651
665
|
/**
|
652
|
-
* @param {
|
666
|
+
* @param {HashFunction=} type type
|
653
667
|
* @returns {Hash} hash
|
654
668
|
*/
|
655
669
|
createHash: type =>
|
656
670
|
createHash(
|
657
671
|
type ||
|
658
|
-
/** @type {
|
672
|
+
/** @type {HashFunction} */
|
659
673
|
(compilation.outputOptions.hashFunction)
|
660
674
|
)
|
661
675
|
};
|
@@ -667,7 +681,9 @@ class NormalModule extends Module {
|
|
667
681
|
* @returns {T} options
|
668
682
|
*/
|
669
683
|
getOptions: schema => {
|
670
|
-
const loader = this.getCurrentLoader(
|
684
|
+
const loader = this.getCurrentLoader(
|
685
|
+
/** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext)
|
686
|
+
);
|
671
687
|
|
672
688
|
let { options } = /** @type {LoaderItem} */ (loader);
|
673
689
|
|
@@ -727,7 +743,9 @@ class NormalModule extends Module {
|
|
727
743
|
);
|
728
744
|
},
|
729
745
|
getLogger: name => {
|
730
|
-
const currentLoader = this.getCurrentLoader(
|
746
|
+
const currentLoader = this.getCurrentLoader(
|
747
|
+
/** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext)
|
748
|
+
);
|
731
749
|
return compilation.getLogger(() =>
|
732
750
|
[currentLoader && currentLoader.loader, name, this.identifier()]
|
733
751
|
.filter(Boolean)
|
@@ -803,7 +821,7 @@ class NormalModule extends Module {
|
|
803
821
|
webpack: true,
|
804
822
|
sourceMap: Boolean(this.useSourceMap),
|
805
823
|
mode: options.mode || "production",
|
806
|
-
hashFunction: /** @type {
|
824
|
+
hashFunction: /** @type {string} */ (options.output.hashFunction),
|
807
825
|
hashDigest: /** @type {string} */ (options.output.hashDigest),
|
808
826
|
hashDigestLength: /** @type {number} */ (options.output.hashDigestLength),
|
809
827
|
hashSalt: /** @type {string} */ (options.output.hashSalt),
|
@@ -815,18 +833,19 @@ class NormalModule extends Module {
|
|
815
833
|
|
816
834
|
Object.assign(loaderContext, options.loader);
|
817
835
|
|
836
|
+
// After `hooks.loader.call` is called, the loaderContext is typed as LoaderContext<EXPECTED_ANY>
|
818
837
|
hooks.loader.call(
|
819
838
|
/** @type {LoaderContext<EXPECTED_ANY>} */
|
820
839
|
(loaderContext),
|
821
840
|
this
|
822
841
|
);
|
823
842
|
|
824
|
-
return loaderContext;
|
843
|
+
return /** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext);
|
825
844
|
}
|
826
845
|
|
827
846
|
// TODO remove `loaderContext` in webpack@6
|
828
847
|
/**
|
829
|
-
* @param {
|
848
|
+
* @param {LoaderContext<EXPECTED_ANY>} loaderContext loader context
|
830
849
|
* @param {number} index index
|
831
850
|
* @returns {LoaderItem | null} loader
|
832
851
|
*/
|
@@ -997,7 +1016,7 @@ class NormalModule extends Module {
|
|
997
1016
|
loaders: this.loaders,
|
998
1017
|
context: loaderContext,
|
999
1018
|
/**
|
1000
|
-
* @param {LoaderContext<
|
1019
|
+
* @param {LoaderContext<EXPECTED_ANY>} loaderContext the loader context
|
1001
1020
|
* @param {string} resourcePath the resource Path
|
1002
1021
|
* @param {(err: Error | null, result?: string | Buffer) => void} callback callback
|
1003
1022
|
*/
|
@@ -1079,7 +1098,7 @@ class NormalModule extends Module {
|
|
1079
1098
|
}
|
1080
1099
|
|
1081
1100
|
/**
|
1082
|
-
* @param {
|
1101
|
+
* @param {Exclude<NoParse, EXPECTED_ANY[]>} rule rule
|
1083
1102
|
* @param {string} content content
|
1084
1103
|
* @returns {boolean} result
|
1085
1104
|
*/
|
@@ -1097,7 +1116,7 @@ class NormalModule extends Module {
|
|
1097
1116
|
}
|
1098
1117
|
|
1099
1118
|
/**
|
1100
|
-
* @param {
|
1119
|
+
* @param {undefined | NoParse} noParseRule no parse rule
|
1101
1120
|
* @param {string} request request
|
1102
1121
|
* @returns {boolean} check if module should not be parsed, returns "true" if the module should !not! be parsed, returns "false" if the module !must! be parsed
|
1103
1122
|
*/
|
@@ -1132,7 +1151,7 @@ class NormalModule extends Module {
|
|
1132
1151
|
*/
|
1133
1152
|
_initBuildHash(compilation) {
|
1134
1153
|
const hash = createHash(
|
1135
|
-
/** @type {
|
1154
|
+
/** @type {HashFunction} */
|
1136
1155
|
(compilation.outputOptions.hashFunction)
|
1137
1156
|
);
|
1138
1157
|
if (this._source) {
|
@@ -1661,7 +1680,7 @@ class NormalModule extends Module {
|
|
1661
1680
|
|
1662
1681
|
/**
|
1663
1682
|
* @param {ObjectDeserializerContext} context context
|
1664
|
-
* @returns {
|
1683
|
+
* @returns {NormalModule} module
|
1665
1684
|
*/
|
1666
1685
|
static deserialize(context) {
|
1667
1686
|
const obj = new NormalModule({
|
@@ -85,7 +85,15 @@ const {
|
|
85
85
|
* @property {string=} context
|
86
86
|
*/
|
87
87
|
|
88
|
-
/**
|
88
|
+
/**
|
89
|
+
* @typedef {object} ResourceSchemeData
|
90
|
+
* @property {string=} mimetype mime type of the resource
|
91
|
+
* @property {string=} parameters additional parameters for the resource
|
92
|
+
* @property {"base64" | false=} encoding encoding of the resource
|
93
|
+
* @property {string=} encodedContent encoded content of the resource
|
94
|
+
*/
|
95
|
+
|
96
|
+
/** @typedef {ResourceData & { data: ResourceSchemeData & Partial<ResolveRequest> }} ResourceDataWithData */
|
89
97
|
|
90
98
|
/**
|
91
99
|
* @typedef {object} ParsedLoaderRequest
|
@@ -321,6 +329,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
321
329
|
/** @type {Set<Module>} */
|
322
330
|
this._restoredUnsafeCacheEntries = new Set();
|
323
331
|
|
332
|
+
/** @type {(resource: string) => import("./util/identifier").ParsedResource} */
|
324
333
|
const cacheParseResource = parseResource.bindCache(
|
325
334
|
associatedObjectForCache
|
326
335
|
);
|
@@ -447,21 +456,22 @@ class NormalModuleFactory extends ModuleFactory {
|
|
447
456
|
const matchResourceMatch = MATCH_RESOURCE_REGEX.exec(request);
|
448
457
|
if (matchResourceMatch) {
|
449
458
|
let matchResource = matchResourceMatch[1];
|
459
|
+
// Check if matchResource starts with ./ or ../
|
450
460
|
if (matchResource.charCodeAt(0) === 46) {
|
451
|
-
// 46
|
461
|
+
// 46 is "."
|
452
462
|
const secondChar = matchResource.charCodeAt(1);
|
453
463
|
if (
|
454
|
-
secondChar === 47 ||
|
455
|
-
(secondChar === 46 && matchResource.charCodeAt(2) === 47)
|
464
|
+
secondChar === 47 || // 47 is "/"
|
465
|
+
(secondChar === 46 && matchResource.charCodeAt(2) === 47) // "../"
|
456
466
|
) {
|
457
|
-
//
|
467
|
+
// Resolve relative path against context
|
458
468
|
matchResource = join(this.fs, context, matchResource);
|
459
469
|
}
|
460
470
|
}
|
461
471
|
|
462
472
|
matchResourceData = {
|
463
|
-
|
464
|
-
|
473
|
+
...cacheParseResource(matchResource),
|
474
|
+
resource: matchResource
|
465
475
|
};
|
466
476
|
requestWithoutMatchResource = request.slice(
|
467
477
|
matchResourceMatch[0].length
|
@@ -546,11 +556,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
546
556
|
|
547
557
|
if (!resourceData) {
|
548
558
|
// ignored
|
549
|
-
return callback(
|
550
|
-
null,
|
551
|
-
/** @type {TODO} */
|
552
|
-
(dependencies[0].createIgnoredModule(context))
|
553
|
-
);
|
559
|
+
return callback(null, dependencies[0].createIgnoredModule(context));
|
554
560
|
}
|
555
561
|
|
556
562
|
const userRequest =
|
@@ -759,9 +765,9 @@ class NormalModuleFactory extends ModuleFactory {
|
|
759
765
|
const defaultResolve = context => {
|
760
766
|
if (/^($|\?)/.test(unresolvedResource)) {
|
761
767
|
resourceData = {
|
768
|
+
...cacheParseResource(unresolvedResource),
|
762
769
|
resource: unresolvedResource,
|
763
|
-
data: {}
|
764
|
-
.../** @type {TODO} */ (cacheParseResource(unresolvedResource))
|
770
|
+
data: {}
|
765
771
|
};
|
766
772
|
continueCallback();
|
767
773
|
}
|
@@ -791,12 +797,11 @@ class NormalModuleFactory extends ModuleFactory {
|
|
791
797
|
/** @type {string} */
|
792
798
|
(_resolvedResource);
|
793
799
|
resourceData = {
|
800
|
+
...cacheParseResource(resolvedResource),
|
794
801
|
resource: resolvedResource,
|
795
802
|
data:
|
796
803
|
/** @type {ResolveRequest} */
|
797
|
-
(resolvedResourceResolveData)
|
798
|
-
.../** @type {TODO} */
|
799
|
-
(cacheParseResource(resolvedResource))
|
804
|
+
(resolvedResourceResolveData)
|
800
805
|
};
|
801
806
|
}
|
802
807
|
continueCallback();
|
@@ -1228,7 +1233,7 @@ If changing the source code is not an option there is also a resolve options cal
|
|
1228
1233
|
}
|
1229
1234
|
);
|
1230
1235
|
},
|
1231
|
-
/** @type {Callback<
|
1236
|
+
/** @type {Callback<(LoaderItem | undefined)[]>} */ (callback)
|
1232
1237
|
);
|
1233
1238
|
}
|
1234
1239
|
|
package/lib/RuntimePlugin.js
CHANGED
@@ -19,6 +19,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
19
19
|
|
20
20
|
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
21
21
|
/** @typedef {import("webpack-sources").Source} Source */
|
22
|
+
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
22
23
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
23
24
|
/** @typedef {import("./Cache").Etag} Etag */
|
24
25
|
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
@@ -29,8 +30,6 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
29
30
|
/** @typedef {import("./Module")} Module */
|
30
31
|
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
31
32
|
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
32
|
-
/** @typedef {import("./util/Hash")} Hash */
|
33
|
-
/** @typedef {import("./util/createHash").Algorithm} Algorithm */
|
34
33
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
35
34
|
|
36
35
|
const validate = createSchemaValidation(
|
@@ -489,7 +488,7 @@ class SourceMapDevToolPlugin {
|
|
489
488
|
(
|
490
489
|
usesContentHash &&
|
491
490
|
createHash(
|
492
|
-
/** @type {
|
491
|
+
/** @type {HashFunction} */
|
493
492
|
(compilation.outputOptions.hashFunction)
|
494
493
|
)
|
495
494
|
.update(sourceMapString)
|
@@ -504,10 +504,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
504
504
|
}
|
505
505
|
if (options.optimization.runtimeChunk) {
|
506
506
|
const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
|
507
|
-
new RuntimeChunkPlugin(
|
508
|
-
/** @type {{ name?: (entrypoint: { name: string }) => string }} */
|
509
|
-
(options.optimization.runtimeChunk)
|
510
|
-
).apply(compiler);
|
507
|
+
new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
|
511
508
|
}
|
512
509
|
if (!options.optimization.emitOnErrors) {
|
513
510
|
const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
|