webpack 5.85.1 → 5.86.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/APIPlugin.js +150 -99
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGroup.js +10 -6
- package/lib/Compiler.js +1 -2
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/DllModule.js +6 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +15 -8
- package/lib/Module.js +7 -1
- package/lib/ProgressPlugin.js +71 -15
- package/lib/WebpackOptionsApply.js +3 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +13 -6
- package/lib/css/CssModulesPlugin.js +37 -12
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +1 -0
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +4 -4
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +3 -0
- package/lib/serialization/types.js +1 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/types.d.ts +43 -34
@@ -36,6 +36,12 @@ const validate = createSchemaValidation(
|
|
36
36
|
* @property {number} bSize
|
37
37
|
*/
|
38
38
|
|
39
|
+
/**
|
40
|
+
* @template K, V
|
41
|
+
* @param {Map<K, Set<V>>} map map
|
42
|
+
* @param {K} key key
|
43
|
+
* @param {V} value value
|
44
|
+
*/
|
39
45
|
const addToSetMap = (map, key, value) => {
|
40
46
|
const set = map.get(key);
|
41
47
|
if (set === undefined) {
|
@@ -68,7 +74,9 @@ class LimitChunkCountPlugin {
|
|
68
74
|
},
|
69
75
|
chunks => {
|
70
76
|
const chunkGraph = compilation.chunkGraph;
|
71
|
-
const maxChunks =
|
77
|
+
const maxChunks =
|
78
|
+
/** @type {LimitChunkCountPluginOptions} */
|
79
|
+
(options).maxChunks;
|
72
80
|
if (!maxChunks) return;
|
73
81
|
if (maxChunks < 1) return;
|
74
82
|
if (compilation.chunks.size <= maxChunks) return;
|
@@ -88,9 +96,17 @@ class LimitChunkCountPlugin {
|
|
88
96
|
c => c.sizeDiff,
|
89
97
|
(a, b) => b - a,
|
90
98
|
// Layer 2: ordered by smallest combined size
|
99
|
+
/**
|
100
|
+
* @param {ChunkCombination} c combination
|
101
|
+
* @returns {number} integrated size
|
102
|
+
*/
|
91
103
|
c => c.integratedSize,
|
92
104
|
(a, b) => a - b,
|
93
105
|
// Layer 3: ordered by position difference in orderedChunk (-> to be deterministic)
|
106
|
+
/**
|
107
|
+
* @param {ChunkCombination} c combination
|
108
|
+
* @returns {number} position difference
|
109
|
+
*/
|
94
110
|
c => c.bIdx - c.aIdx,
|
95
111
|
(a, b) => a - b,
|
96
112
|
// Layer 4: ordered by position in orderedChunk (-> to be deterministic)
|
@@ -193,14 +209,18 @@ class LimitChunkCountPlugin {
|
|
193
209
|
// Update all affected combinations
|
194
210
|
// delete all combination with the removed chunk
|
195
211
|
// we will use combinations with the kept chunk instead
|
196
|
-
for (const combination of
|
212
|
+
for (const combination of /** @type {Set<ChunkCombination>} */ (
|
213
|
+
combinationsByChunk.get(a)
|
214
|
+
)) {
|
197
215
|
if (combination.deleted) continue;
|
198
216
|
combination.deleted = true;
|
199
217
|
combinations.delete(combination);
|
200
218
|
}
|
201
219
|
|
202
220
|
// Update combinations with the kept chunk with new sizes
|
203
|
-
for (const combination of
|
221
|
+
for (const combination of /** @type {Set<ChunkCombination>} */ (
|
222
|
+
combinationsByChunk.get(b)
|
223
|
+
)) {
|
204
224
|
if (combination.deleted) continue;
|
205
225
|
if (combination.a === b) {
|
206
226
|
if (!chunkGraph.canChunksBeIntegrated(a, combination.b)) {
|
@@ -243,7 +263,12 @@ class LimitChunkCountPlugin {
|
|
243
263
|
finishUpdate();
|
244
264
|
}
|
245
265
|
}
|
246
|
-
combinationsByChunk.set(
|
266
|
+
combinationsByChunk.set(
|
267
|
+
a,
|
268
|
+
/** @type {Set<ChunkCombination>} */ (
|
269
|
+
combinationsByChunk.get(b)
|
270
|
+
)
|
271
|
+
);
|
247
272
|
combinationsByChunk.delete(b);
|
248
273
|
}
|
249
274
|
}
|
@@ -39,7 +39,7 @@ 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
|
+
* @param {boolean | undefined} isNamespace is namespace object
|
43
43
|
* @returns {void}
|
44
44
|
*/
|
45
45
|
const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
@@ -9,6 +9,11 @@ const SizeFormatHelpers = require("../SizeFormatHelpers");
|
|
9
9
|
const WebpackError = require("../WebpackError");
|
10
10
|
|
11
11
|
class MinMaxSizeWarning extends WebpackError {
|
12
|
+
/**
|
13
|
+
* @param {string[] | undefined} keys keys
|
14
|
+
* @param {number} minSize minimum size
|
15
|
+
* @param {number} maxSize maximum size
|
16
|
+
*/
|
12
17
|
constructor(keys, minSize, maxSize) {
|
13
18
|
let keysMessage = "Fallback cache group";
|
14
19
|
if (keys) {
|
@@ -40,6 +40,10 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|
40
40
|
* @property {number} added
|
41
41
|
*/
|
42
42
|
|
43
|
+
/**
|
44
|
+
* @param {string} msg message
|
45
|
+
* @returns {string} formatted message
|
46
|
+
*/
|
43
47
|
const formatBailoutReason = msg => {
|
44
48
|
return "ModuleConcatenation bailout: " + msg;
|
45
49
|
};
|
@@ -64,8 +68,13 @@ class ModuleConcatenationPlugin {
|
|
64
68
|
);
|
65
69
|
}
|
66
70
|
const moduleGraph = compilation.moduleGraph;
|
71
|
+
/** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */
|
67
72
|
const bailoutReasonMap = new Map();
|
68
73
|
|
74
|
+
/**
|
75
|
+
* @param {Module} module the module
|
76
|
+
* @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
|
77
|
+
*/
|
69
78
|
const setBailoutReason = (module, reason) => {
|
70
79
|
setInnerBailoutReason(module, reason);
|
71
80
|
moduleGraph
|
@@ -77,16 +86,30 @@ class ModuleConcatenationPlugin {
|
|
77
86
|
);
|
78
87
|
};
|
79
88
|
|
89
|
+
/**
|
90
|
+
* @param {Module} module the module
|
91
|
+
* @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
|
92
|
+
*/
|
80
93
|
const setInnerBailoutReason = (module, reason) => {
|
81
94
|
bailoutReasonMap.set(module, reason);
|
82
95
|
};
|
83
96
|
|
97
|
+
/**
|
98
|
+
* @param {Module} module the module
|
99
|
+
* @param {RequestShortener} requestShortener the request shortener
|
100
|
+
* @returns {string | ((requestShortener: RequestShortener) => string) | undefined} the reason
|
101
|
+
*/
|
84
102
|
const getInnerBailoutReason = (module, requestShortener) => {
|
85
103
|
const reason = bailoutReasonMap.get(module);
|
86
104
|
if (typeof reason === "function") return reason(requestShortener);
|
87
105
|
return reason;
|
88
106
|
};
|
89
107
|
|
108
|
+
/**
|
109
|
+
* @param {Module} module the module
|
110
|
+
* @param {Module | function(RequestShortener): string} problem the problem
|
111
|
+
* @returns {(requestShortener: RequestShortener) => string} the reason
|
112
|
+
*/
|
90
113
|
const formatBailoutWarning = (module, problem) => requestShortener => {
|
91
114
|
if (typeof problem === "function") {
|
92
115
|
return formatBailoutReason(
|
@@ -460,7 +483,7 @@ class ModuleConcatenationPlugin {
|
|
460
483
|
c.module === rootModule ? c.originModule : c.module;
|
461
484
|
const innerConnection =
|
462
485
|
c.dependency instanceof HarmonyImportDependency &&
|
463
|
-
modules.has(otherModule);
|
486
|
+
modules.has(/** @type {Module} */ (otherModule));
|
464
487
|
return !innerConnection;
|
465
488
|
});
|
466
489
|
// add concatenated module to the compilation
|
@@ -533,7 +556,7 @@ class ModuleConcatenationPlugin {
|
|
533
556
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
534
557
|
* @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
|
535
558
|
* @param {Statistics} statistics gathering metrics
|
536
|
-
* @returns {Module | function(RequestShortener): string} the problematic module
|
559
|
+
* @returns {null | Module | function(RequestShortener): string} the problematic module
|
537
560
|
*/
|
538
561
|
_tryToAdd(
|
539
562
|
compilation,
|
@@ -572,6 +595,10 @@ class ModuleConcatenationPlugin {
|
|
572
595
|
chunkGraph.getModuleChunksIterable(config.rootModule)
|
573
596
|
).filter(chunk => !chunkGraph.isModuleInChunk(module, chunk));
|
574
597
|
if (missingChunks.length > 0) {
|
598
|
+
/**
|
599
|
+
* @param {RequestShortener} requestShortener request shortener
|
600
|
+
* @returns {string} problem description
|
601
|
+
*/
|
575
602
|
const problem = requestShortener => {
|
576
603
|
const missingChunksList = Array.from(
|
577
604
|
new Set(missingChunks.map(chunk => chunk.name || "unnamed chunk(s)"))
|
@@ -609,6 +636,10 @@ class ModuleConcatenationPlugin {
|
|
609
636
|
return connection.isActive(runtime);
|
610
637
|
});
|
611
638
|
if (activeNonModulesConnections.length > 0) {
|
639
|
+
/**
|
640
|
+
* @param {RequestShortener} requestShortener request shortener
|
641
|
+
* @returns {string} problem description
|
642
|
+
*/
|
612
643
|
const problem = requestShortener => {
|
613
644
|
const importingExplanations = new Set(
|
614
645
|
activeNonModulesConnections.map(c => c.explanation).filter(Boolean)
|
@@ -666,6 +697,10 @@ class ModuleConcatenationPlugin {
|
|
666
697
|
return false;
|
667
698
|
});
|
668
699
|
if (otherChunkModules.length > 0) {
|
700
|
+
/**
|
701
|
+
* @param {RequestShortener} requestShortener request shortener
|
702
|
+
* @returns {string} problem description
|
703
|
+
*/
|
669
704
|
const problem = requestShortener => {
|
670
705
|
const names = otherChunkModules
|
671
706
|
.map(m => m.readableIdentifier(requestShortener))
|
@@ -693,6 +728,10 @@ class ModuleConcatenationPlugin {
|
|
693
728
|
nonHarmonyConnections.set(originModule, connections);
|
694
729
|
}
|
695
730
|
if (nonHarmonyConnections.size > 0) {
|
731
|
+
/**
|
732
|
+
* @param {RequestShortener} requestShortener request shortener
|
733
|
+
* @returns {string} problem description
|
734
|
+
*/
|
696
735
|
const problem = requestShortener => {
|
697
736
|
const names = Array.from(nonHarmonyConnections)
|
698
737
|
.map(([originModule, connections]) => {
|
@@ -753,6 +792,10 @@ class ModuleConcatenationPlugin {
|
|
753
792
|
}
|
754
793
|
}
|
755
794
|
if (otherRuntimeConnections.length > 0) {
|
795
|
+
/**
|
796
|
+
* @param {RequestShortener} requestShortener request shortener
|
797
|
+
* @returns {string} problem description
|
798
|
+
*/
|
756
799
|
const problem = requestShortener => {
|
757
800
|
return `Module ${module.readableIdentifier(
|
758
801
|
requestShortener
|
@@ -831,10 +874,17 @@ class ConcatConfiguration {
|
|
831
874
|
this.warnings = new Map();
|
832
875
|
}
|
833
876
|
|
877
|
+
/**
|
878
|
+
* @param {Module} module the module
|
879
|
+
*/
|
834
880
|
add(module) {
|
835
881
|
this.modules.add(module);
|
836
882
|
}
|
837
883
|
|
884
|
+
/**
|
885
|
+
* @param {Module} module the module
|
886
|
+
* @returns {boolean} true, when the module is in the module set
|
887
|
+
*/
|
838
888
|
has(module) {
|
839
889
|
return this.modules.has(module);
|
840
890
|
}
|
@@ -843,10 +893,17 @@ class ConcatConfiguration {
|
|
843
893
|
return this.modules.size === 1;
|
844
894
|
}
|
845
895
|
|
896
|
+
/**
|
897
|
+
* @param {Module} module the module
|
898
|
+
* @param {Module | function(RequestShortener): string} problem the problem
|
899
|
+
*/
|
846
900
|
addWarning(module, problem) {
|
847
901
|
this.warnings.set(module, problem);
|
848
902
|
}
|
849
903
|
|
904
|
+
/**
|
905
|
+
* @returns {Map<Module, Module | function(RequestShortener): string>} warnings
|
906
|
+
*/
|
850
907
|
getWarningsSorted() {
|
851
908
|
return new Map(
|
852
909
|
Array.from(this.warnings).sort((a, b) => {
|
@@ -13,12 +13,18 @@ const { compareSelect, compareStrings } = require("../util/comparators");
|
|
13
13
|
const createHash = require("../util/createHash");
|
14
14
|
|
15
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
16
|
+
/** @typedef {import("../Cache").Etag} Etag */
|
16
17
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
17
18
|
/** @typedef {import("../Compiler")} Compiler */
|
18
19
|
/** @typedef {typeof import("../util/Hash")} Hash */
|
19
20
|
|
20
21
|
const EMPTY_SET = new Set();
|
21
22
|
|
23
|
+
/**
|
24
|
+
* @template T
|
25
|
+
* @param {T | T[]} itemOrItems item or items
|
26
|
+
* @param {Set<T>} list list
|
27
|
+
*/
|
22
28
|
const addToList = (itemOrItems, list) => {
|
23
29
|
if (Array.isArray(itemOrItems)) {
|
24
30
|
for (const item of itemOrItems) {
|
@@ -61,6 +67,10 @@ const quoteMeta = str => {
|
|
61
67
|
|
62
68
|
const cachedSourceMap = new WeakMap();
|
63
69
|
|
70
|
+
/**
|
71
|
+
* @param {Source} source source
|
72
|
+
* @returns {CachedSource} cached source
|
73
|
+
*/
|
64
74
|
const toCachedSource = source => {
|
65
75
|
if (source instanceof CachedSource) {
|
66
76
|
return source;
|
@@ -72,6 +82,10 @@ const toCachedSource = source => {
|
|
72
82
|
return newSource;
|
73
83
|
};
|
74
84
|
|
85
|
+
/** @typedef {Set<string>} OwnHashes */
|
86
|
+
/** @typedef {Set<string>} ReferencedHashes */
|
87
|
+
/** @typedef {Set<string>} Hashes */
|
88
|
+
|
75
89
|
/**
|
76
90
|
* @typedef {Object} AssetInfoForRealContentHash
|
77
91
|
* @property {string} name
|
@@ -80,11 +94,11 @@ const toCachedSource = source => {
|
|
80
94
|
* @property {RawSource | undefined} newSource
|
81
95
|
* @property {RawSource | undefined} newSourceWithoutOwn
|
82
96
|
* @property {string} content
|
83
|
-
* @property {
|
84
|
-
* @property {Promise} contentComputePromise
|
85
|
-
* @property {Promise} contentComputeWithoutOwnPromise
|
86
|
-
* @property {
|
87
|
-
* @property {
|
97
|
+
* @property {OwnHashes | undefined} ownHashes
|
98
|
+
* @property {Promise<void> | undefined} contentComputePromise
|
99
|
+
* @property {Promise<void> | undefined} contentComputeWithoutOwnPromise
|
100
|
+
* @property {ReferencedHashes | undefined} referencedHashes
|
101
|
+
* @property {Hashes} hashes
|
88
102
|
*/
|
89
103
|
|
90
104
|
/**
|
@@ -149,27 +163,25 @@ class RealContentHashPlugin {
|
|
149
163
|
const assets = compilation.getAssets();
|
150
164
|
/** @type {AssetInfoForRealContentHash[]} */
|
151
165
|
const assetsWithInfo = [];
|
166
|
+
/** @type {Map<string, [AssetInfoForRealContentHash]>} */
|
152
167
|
const hashToAssets = new Map();
|
153
168
|
for (const { source, info, name } of assets) {
|
154
169
|
const cachedSource = toCachedSource(source);
|
155
|
-
const content = cachedSource.source();
|
156
|
-
/** @type {
|
170
|
+
const content = /** @type {string} */ (cachedSource.source());
|
171
|
+
/** @type {Hashes} */
|
157
172
|
const hashes = new Set();
|
158
173
|
addToList(info.contenthash, hashes);
|
174
|
+
/** @type {AssetInfoForRealContentHash} */
|
159
175
|
const data = {
|
160
176
|
name,
|
161
177
|
info,
|
162
178
|
source: cachedSource,
|
163
|
-
/** @type {RawSource | undefined} */
|
164
179
|
newSource: undefined,
|
165
|
-
/** @type {RawSource | undefined} */
|
166
180
|
newSourceWithoutOwn: undefined,
|
167
181
|
content,
|
168
|
-
/** @type {Set<string>} */
|
169
182
|
ownHashes: undefined,
|
170
183
|
contentComputePromise: undefined,
|
171
184
|
contentComputeWithoutOwnPromise: undefined,
|
172
|
-
/** @type {Set<string>} */
|
173
185
|
referencedHashes: undefined,
|
174
186
|
hashes
|
175
187
|
};
|
@@ -218,11 +230,17 @@ class RealContentHashPlugin {
|
|
218
230
|
});
|
219
231
|
})
|
220
232
|
);
|
233
|
+
/**
|
234
|
+
* @param {string} hash the hash
|
235
|
+
* @returns {undefined | ReferencedHashes} the referenced hashes
|
236
|
+
*/
|
221
237
|
const getDependencies = hash => {
|
222
238
|
const assets = hashToAssets.get(hash);
|
223
239
|
if (!assets) {
|
224
240
|
const referencingAssets = assetsWithInfo.filter(asset =>
|
225
|
-
asset.referencedHashes.has(
|
241
|
+
/** @type {ReferencedHashes} */ (asset.referencedHashes).has(
|
242
|
+
hash
|
243
|
+
)
|
226
244
|
);
|
227
245
|
const err = new WebpackError(`RealContentHashPlugin
|
228
246
|
Some kind of unexpected caching problem occurred.
|
@@ -242,23 +260,36 @@ ${referencingAssets
|
|
242
260
|
}
|
243
261
|
const hashes = new Set();
|
244
262
|
for (const { referencedHashes, ownHashes } of assets) {
|
245
|
-
if (!ownHashes.has(hash)) {
|
246
|
-
for (const hash of ownHashes) {
|
263
|
+
if (!(/** @type {OwnHashes} */ (ownHashes).has(hash))) {
|
264
|
+
for (const hash of /** @type {OwnHashes} */ (ownHashes)) {
|
247
265
|
hashes.add(hash);
|
248
266
|
}
|
249
267
|
}
|
250
|
-
for (const hash of
|
268
|
+
for (const hash of /** @type {ReferencedHashes} */ (
|
269
|
+
referencedHashes
|
270
|
+
)) {
|
251
271
|
hashes.add(hash);
|
252
272
|
}
|
253
273
|
}
|
254
274
|
return hashes;
|
255
275
|
};
|
276
|
+
/**
|
277
|
+
* @param {string} hash the hash
|
278
|
+
* @returns {string} the hash info
|
279
|
+
*/
|
256
280
|
const hashInfo = hash => {
|
257
281
|
const assets = hashToAssets.get(hash);
|
258
|
-
return `${hash} (${Array.from(
|
282
|
+
return `${hash} (${Array.from(
|
283
|
+
/** @type {AssetInfoForRealContentHash[]} */ (assets),
|
284
|
+
a => a.name
|
285
|
+
)})`;
|
259
286
|
};
|
260
287
|
const hashesInOrder = new Set();
|
261
288
|
for (const hash of hashToAssets.keys()) {
|
289
|
+
/**
|
290
|
+
* @param {string} hash the hash
|
291
|
+
* @param {Set<string>} stack stack of hashes
|
292
|
+
*/
|
262
293
|
const add = (hash, stack) => {
|
263
294
|
const deps = getDependencies(hash);
|
264
295
|
if (!deps) return;
|
@@ -282,21 +313,31 @@ ${referencingAssets
|
|
282
313
|
add(hash, new Set());
|
283
314
|
}
|
284
315
|
const hashToNewHash = new Map();
|
316
|
+
/**
|
317
|
+
* @param {AssetInfoForRealContentHash} asset asset info
|
318
|
+
* @returns {Etag} etag
|
319
|
+
*/
|
285
320
|
const getEtag = asset =>
|
286
321
|
cacheGenerate.mergeEtags(
|
287
322
|
cacheGenerate.getLazyHashedEtag(asset.source),
|
288
|
-
Array.from(
|
289
|
-
|
323
|
+
Array.from(
|
324
|
+
/** @type {ReferencedHashes} */ (asset.referencedHashes),
|
325
|
+
hash => hashToNewHash.get(hash)
|
290
326
|
).join("|")
|
291
327
|
);
|
328
|
+
/**
|
329
|
+
* @param {AssetInfoForRealContentHash} asset asset info
|
330
|
+
* @returns {Promise<void>}
|
331
|
+
*/
|
292
332
|
const computeNewContent = asset => {
|
293
333
|
if (asset.contentComputePromise) return asset.contentComputePromise;
|
294
334
|
return (asset.contentComputePromise = (async () => {
|
295
335
|
if (
|
296
|
-
asset.ownHashes.size > 0 ||
|
297
|
-
Array.from(
|
298
|
-
|
299
|
-
|
336
|
+
/** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
|
337
|
+
Array.from(
|
338
|
+
/** @type {ReferencedHashes} */
|
339
|
+
(asset.referencedHashes)
|
340
|
+
).some(hash => hashToNewHash.get(hash) !== hash)
|
300
341
|
) {
|
301
342
|
const identifier = asset.name;
|
302
343
|
const etag = getEtag(asset);
|
@@ -313,15 +354,20 @@ ${referencingAssets
|
|
313
354
|
}
|
314
355
|
})());
|
315
356
|
};
|
357
|
+
/**
|
358
|
+
* @param {AssetInfoForRealContentHash} asset asset info
|
359
|
+
* @returns {Promise<void>}
|
360
|
+
*/
|
316
361
|
const computeNewContentWithoutOwn = asset => {
|
317
362
|
if (asset.contentComputeWithoutOwnPromise)
|
318
363
|
return asset.contentComputeWithoutOwnPromise;
|
319
364
|
return (asset.contentComputeWithoutOwnPromise = (async () => {
|
320
365
|
if (
|
321
|
-
asset.ownHashes.size > 0 ||
|
322
|
-
Array.from(
|
323
|
-
|
324
|
-
|
366
|
+
/** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
|
367
|
+
Array.from(
|
368
|
+
/** @type {ReferencedHashes} */
|
369
|
+
(asset.referencedHashes)
|
370
|
+
).some(hash => hashToNewHash.get(hash) !== hash)
|
325
371
|
) {
|
326
372
|
const identifier = asset.name + "|without-own";
|
327
373
|
const etag = getEtag(asset);
|
@@ -332,7 +378,9 @@ ${referencingAssets
|
|
332
378
|
const newContent = asset.content.replace(
|
333
379
|
hashRegExp,
|
334
380
|
hash => {
|
335
|
-
if (
|
381
|
+
if (
|
382
|
+
/** @type {OwnHashes} */ (asset.ownHashes).has(hash)
|
383
|
+
) {
|
336
384
|
return "";
|
337
385
|
}
|
338
386
|
return hashToNewHash.get(hash);
|
@@ -346,17 +394,19 @@ ${referencingAssets
|
|
346
394
|
};
|
347
395
|
const comparator = compareSelect(a => a.name, compareStrings);
|
348
396
|
for (const oldHash of hashesInOrder) {
|
349
|
-
const assets =
|
397
|
+
const assets =
|
398
|
+
/** @type {AssetInfoForRealContentHash[]} */
|
399
|
+
(hashToAssets.get(oldHash));
|
350
400
|
assets.sort(comparator);
|
351
401
|
await Promise.all(
|
352
402
|
assets.map(asset =>
|
353
|
-
asset.ownHashes.has(oldHash)
|
403
|
+
/** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)
|
354
404
|
? computeNewContentWithoutOwn(asset)
|
355
405
|
: computeNewContent(asset)
|
356
406
|
)
|
357
407
|
);
|
358
408
|
const assetsContent = mapAndDeduplicateBuffers(assets, asset => {
|
359
|
-
if (asset.ownHashes.has(oldHash)) {
|
409
|
+
if (/** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)) {
|
360
410
|
return asset.newSourceWithoutOwn
|
361
411
|
? asset.newSourceWithoutOwn.buffer()
|
362
412
|
: asset.source.buffer();
|
@@ -9,6 +9,8 @@ const { STAGE_BASIC } = require("../OptimizationStages");
|
|
9
9
|
const Queue = require("../util/Queue");
|
10
10
|
const { intersect } = require("../util/SetHelpers");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
12
14
|
/** @typedef {import("../Compiler")} Compiler */
|
13
15
|
|
14
16
|
class RemoveParentModulesPlugin {
|
@@ -18,6 +20,10 @@ class RemoveParentModulesPlugin {
|
|
18
20
|
*/
|
19
21
|
apply(compiler) {
|
20
22
|
compiler.hooks.compilation.tap("RemoveParentModulesPlugin", compilation => {
|
23
|
+
/**
|
24
|
+
* @param {Iterable<Chunk>} chunks the chunks
|
25
|
+
* @param {ChunkGroup[]} chunkGroups the chunk groups
|
26
|
+
*/
|
21
27
|
const handler = (chunks, chunkGroups) => {
|
22
28
|
const chunkGraph = compilation.chunkGraph;
|
23
29
|
const queue = new Queue();
|
@@ -5,11 +5,17 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
/** @typedef {import("../Compilation").EntryData} EntryData */
|
8
9
|
/** @typedef {import("../Compiler")} Compiler */
|
10
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
9
11
|
|
10
12
|
class RuntimeChunkPlugin {
|
11
13
|
constructor(options) {
|
12
14
|
this.options = {
|
15
|
+
/**
|
16
|
+
* @param {Entrypoint} entrypoint entrypoint name
|
17
|
+
* @returns {string} runtime chunk name
|
18
|
+
*/
|
13
19
|
name: entrypoint => `runtime~${entrypoint.name}`,
|
14
20
|
...options
|
15
21
|
};
|
@@ -26,7 +32,9 @@ class RuntimeChunkPlugin {
|
|
26
32
|
"RuntimeChunkPlugin",
|
27
33
|
(_, { name: entryName }) => {
|
28
34
|
if (entryName === undefined) return;
|
29
|
-
const data =
|
35
|
+
const data =
|
36
|
+
/** @type {EntryData} */
|
37
|
+
(compilation.entries.get(entryName));
|
30
38
|
if (data.options.runtime === undefined && !data.options.dependOn) {
|
31
39
|
// Determine runtime chunk name
|
32
40
|
let name = this.options.name;
|
@@ -16,6 +16,8 @@ const HarmonyExportImportedSpecifierDependency = require("../dependencies/Harmon
|
|
16
16
|
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
17
17
|
const formatLocation = require("../formatLocation");
|
18
18
|
|
19
|
+
/** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */
|
20
|
+
/** @typedef {import("estree").Statement} Statement */
|
19
21
|
/** @typedef {import("../Compiler")} Compiler */
|
20
22
|
/** @typedef {import("../Dependency")} Dependency */
|
21
23
|
/** @typedef {import("../Module")} Module */
|
@@ -117,6 +119,7 @@ class SideEffectsFlagPlugin {
|
|
117
119
|
* @returns {void}
|
118
120
|
*/
|
119
121
|
const parserHandler = parser => {
|
122
|
+
/** @type {undefined | Statement | ModuleDeclaration} */
|
120
123
|
let sideEffectsStatement;
|
121
124
|
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
122
125
|
sideEffectsStatement = undefined;
|
@@ -258,7 +261,7 @@ class SideEffectsFlagPlugin {
|
|
258
261
|
// TODO improve for export *
|
259
262
|
if (isReexport && dep.name) {
|
260
263
|
const exportInfo = moduleGraph.getExportInfo(
|
261
|
-
connection.originModule,
|
264
|
+
/** @type {Module} */ (connection.originModule),
|
262
265
|
dep.name
|
263
266
|
);
|
264
267
|
exportInfo.moveTarget(
|
@@ -319,6 +322,12 @@ class SideEffectsFlagPlugin {
|
|
319
322
|
);
|
320
323
|
}
|
321
324
|
|
325
|
+
/**
|
326
|
+
* @param {string} moduleName the module name
|
327
|
+
* @param {undefined | boolean | string | string[]} flagValue the flag value
|
328
|
+
* @param {Map<string, RegExp>} cache cache for glob to regexp
|
329
|
+
* @returns {boolean | undefined} true, when the module has side effects, undefined or false when not
|
330
|
+
*/
|
322
331
|
static moduleHasSideEffects(moduleName, flagValue, cache) {
|
323
332
|
switch (typeof flagValue) {
|
324
333
|
case "undefined":
|