webpack 5.88.0 → 5.88.2
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/BannerPlugin.js +2 -1
- package/lib/Compiler.js +6 -6
- package/lib/ConstPlugin.js +16 -3
- package/lib/DependencyTemplates.js +1 -1
- package/lib/ExportsInfo.js +5 -1
- package/lib/FileSystemInfo.js +52 -24
- package/lib/Generator.js +7 -0
- package/lib/Watching.js +62 -25
- package/lib/buildChunkGraph.js +37 -21
- package/lib/cache/PackFileCacheStrategy.js +19 -9
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -0
- package/lib/javascript/JavascriptModulesPlugin.js +24 -5
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +13 -1
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +20 -2
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/runtime.js +70 -20
- package/lib/util/semver.js +1 -0
- package/package.json +1 -1
- package/schemas/WebpackOptions.json +1 -1
- package/types.d.ts +36 -31
package/lib/BannerPlugin.js
CHANGED
@@ -11,6 +11,7 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
|
11
11
|
const Template = require("./Template");
|
12
12
|
const createSchemaValidation = require("./util/create-schema-validation");
|
13
13
|
|
14
|
+
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerFunction} BannerFunction */
|
14
15
|
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
|
15
16
|
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
|
16
17
|
/** @typedef {import("./Compiler")} Compiler */
|
@@ -60,7 +61,7 @@ class BannerPlugin {
|
|
60
61
|
const getBanner = bannerOption;
|
61
62
|
this.banner = this.options.raw
|
62
63
|
? getBanner
|
63
|
-
: data => wrapComment(getBanner(data));
|
64
|
+
: /** @type {BannerFunction} */ data => wrapComment(getBanner(data));
|
64
65
|
} else {
|
65
66
|
const banner = this.options.raw
|
66
67
|
? bannerOption
|
package/lib/Compiler.js
CHANGED
@@ -208,7 +208,7 @@ class Compiler {
|
|
208
208
|
this.root = this;
|
209
209
|
/** @type {string} */
|
210
210
|
this.outputPath = "";
|
211
|
-
/** @type {Watching} */
|
211
|
+
/** @type {Watching | undefined} */
|
212
212
|
this.watching = undefined;
|
213
213
|
|
214
214
|
/** @type {OutputFileSystem} */
|
@@ -230,15 +230,15 @@ class Compiler {
|
|
230
230
|
/** @type {Set<string | RegExp>} */
|
231
231
|
this.immutablePaths = new Set();
|
232
232
|
|
233
|
-
/** @type {ReadonlySet<string>} */
|
233
|
+
/** @type {ReadonlySet<string> | undefined} */
|
234
234
|
this.modifiedFiles = undefined;
|
235
|
-
/** @type {ReadonlySet<string>} */
|
235
|
+
/** @type {ReadonlySet<string> | undefined} */
|
236
236
|
this.removedFiles = undefined;
|
237
|
-
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
237
|
+
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
|
238
238
|
this.fileTimestamps = undefined;
|
239
|
-
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
239
|
+
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
|
240
240
|
this.contextTimestamps = undefined;
|
241
|
-
/** @type {number} */
|
241
|
+
/** @type {number | undefined} */
|
242
242
|
this.fsStartTime = undefined;
|
243
243
|
|
244
244
|
/** @type {ResolverFactory} */
|
package/lib/ConstPlugin.js
CHANGED
@@ -15,7 +15,10 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|
15
15
|
const { evaluateToString } = require("./javascript/JavascriptParserHelpers");
|
16
16
|
const { parseResource } = require("./util/identifier");
|
17
17
|
|
18
|
+
/** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
|
18
19
|
/** @typedef {import("estree").Expression} Expression */
|
20
|
+
/** @typedef {import("estree").Identifier} Identifier */
|
21
|
+
/** @typedef {import("estree").Pattern} Pattern */
|
19
22
|
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
20
23
|
/** @typedef {import("estree").Statement} Statement */
|
21
24
|
/** @typedef {import("estree").Super} Super */
|
@@ -24,10 +27,14 @@ const { parseResource } = require("./util/identifier");
|
|
24
27
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
25
28
|
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
26
29
|
|
30
|
+
/**
|
31
|
+
* @param {Set<string>} declarations set of declarations
|
32
|
+
* @param {Identifier | Pattern} pattern pattern to collect declarations from
|
33
|
+
*/
|
27
34
|
const collectDeclaration = (declarations, pattern) => {
|
28
35
|
const stack = [pattern];
|
29
36
|
while (stack.length > 0) {
|
30
|
-
const node = stack.pop();
|
37
|
+
const node = /** @type {Pattern} */ (stack.pop());
|
31
38
|
switch (node.type) {
|
32
39
|
case "Identifier":
|
33
40
|
declarations.add(node.name);
|
@@ -44,7 +51,7 @@ const collectDeclaration = (declarations, pattern) => {
|
|
44
51
|
break;
|
45
52
|
case "ObjectPattern":
|
46
53
|
for (const property of node.properties) {
|
47
|
-
stack.push(property.value);
|
54
|
+
stack.push(/** @type {AssignmentProperty} */ (property).value);
|
48
55
|
}
|
49
56
|
break;
|
50
57
|
case "RestElement":
|
@@ -54,8 +61,14 @@ const collectDeclaration = (declarations, pattern) => {
|
|
54
61
|
}
|
55
62
|
};
|
56
63
|
|
64
|
+
/**
|
65
|
+
* @param {Statement} branch branch to get hoisted declarations from
|
66
|
+
* @param {boolean} includeFunctionDeclarations whether to include function declarations
|
67
|
+
* @returns {Array<string>} hoisted declarations
|
68
|
+
*/
|
57
69
|
const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
58
70
|
const declarations = new Set();
|
71
|
+
/** @type {Array<TODO | null | undefined>} */
|
59
72
|
const stack = [branch];
|
60
73
|
while (stack.length > 0) {
|
61
74
|
const node = stack.pop();
|
@@ -103,7 +116,7 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
|
103
116
|
break;
|
104
117
|
case "FunctionDeclaration":
|
105
118
|
if (includeFunctionDeclarations) {
|
106
|
-
collectDeclaration(declarations, node.id);
|
119
|
+
collectDeclaration(declarations, /** @type {Identifier} */ (node.id));
|
107
120
|
}
|
108
121
|
break;
|
109
122
|
case "VariableDeclaration":
|
@@ -27,7 +27,7 @@ class DependencyTemplates {
|
|
27
27
|
|
28
28
|
/**
|
29
29
|
* @param {DependencyConstructor} dependency Constructor of Dependency
|
30
|
-
* @returns {DependencyTemplate} template for this dependency
|
30
|
+
* @returns {DependencyTemplate | undefined} template for this dependency
|
31
31
|
*/
|
32
32
|
get(dependency) {
|
33
33
|
return this._map.get(dependency);
|
package/lib/ExportsInfo.js
CHANGED
@@ -1364,7 +1364,11 @@ class ExportInfo {
|
|
1364
1364
|
if (t === null) return undefined;
|
1365
1365
|
if (t.module !== target.module) return undefined;
|
1366
1366
|
if (!t.export !== !target.export) return undefined;
|
1367
|
-
if (
|
1367
|
+
if (
|
1368
|
+
target.export &&
|
1369
|
+
!equals(/** @type {ArrayLike<string>} */ (t.export), target.export)
|
1370
|
+
)
|
1371
|
+
return undefined;
|
1368
1372
|
result = values.next();
|
1369
1373
|
}
|
1370
1374
|
return target;
|
package/lib/FileSystemInfo.js
CHANGED
@@ -99,8 +99,8 @@ const INVALID = Symbol("invalid");
|
|
99
99
|
* @typedef {Object} SnapshotOptimizationEntry
|
100
100
|
* @property {Snapshot} snapshot
|
101
101
|
* @property {number} shared
|
102
|
-
* @property {Set<string>} snapshotContent
|
103
|
-
* @property {Set<SnapshotOptimizationEntry>} children
|
102
|
+
* @property {Set<string> | undefined} snapshotContent
|
103
|
+
* @property {Set<SnapshotOptimizationEntry> | undefined} children
|
104
104
|
*/
|
105
105
|
|
106
106
|
/**
|
@@ -115,6 +115,12 @@ const INVALID = Symbol("invalid");
|
|
115
115
|
* @property {Set<string>} resolveDependencies.missing list of missing entries
|
116
116
|
*/
|
117
117
|
|
118
|
+
/**
|
119
|
+
* @typedef {Object} SnapshotOptions
|
120
|
+
* @property {boolean=} hash should use hash to snapshot
|
121
|
+
* @property {boolean=} timestamp should use timestamp to snapshot
|
122
|
+
*/
|
123
|
+
|
118
124
|
const DONE_ITERATOR_RESULT = new Set().keys().next();
|
119
125
|
|
120
126
|
// cspell:word tshs
|
@@ -137,7 +143,7 @@ class SnapshotIterable {
|
|
137
143
|
let state = 0;
|
138
144
|
/** @type {IterableIterator<string>} */
|
139
145
|
let it;
|
140
|
-
/** @type {(Snapshot) => (Map<string, any> | Set<string>)[]} */
|
146
|
+
/** @type {(snapshot: Snapshot) => (Map<string, any> | Set<string>)[]} */
|
141
147
|
let getMaps;
|
142
148
|
/** @type {(Map<string, any> | Set<string>)[]} */
|
143
149
|
let maps;
|
@@ -552,7 +558,7 @@ class SnapshotOptimization {
|
|
552
558
|
}
|
553
559
|
};
|
554
560
|
|
555
|
-
/** @type {SnapshotOptimizationEntry} */
|
561
|
+
/** @type {SnapshotOptimizationEntry | undefined} */
|
556
562
|
let newOptimizationEntry = undefined;
|
557
563
|
|
558
564
|
const capturedFilesSize = capturedFiles.size;
|
@@ -757,10 +763,9 @@ const mergeMaps = (a, b) => {
|
|
757
763
|
|
758
764
|
/**
|
759
765
|
* @template T
|
760
|
-
* @
|
761
|
-
* @param {Set<T
|
762
|
-
* @
|
763
|
-
* @returns {Set<T, K>} joined map
|
766
|
+
* @param {Set<T>} a source map
|
767
|
+
* @param {Set<T>} b joining map
|
768
|
+
* @returns {Set<T>} joined map
|
764
769
|
*/
|
765
770
|
const mergeSets = (a, b) => {
|
766
771
|
if (!b || b.size === 0) return a;
|
@@ -858,8 +863,8 @@ const getManagedItem = (managedPath, path) => {
|
|
858
863
|
|
859
864
|
/**
|
860
865
|
* @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
|
861
|
-
* @param {T} entry entry
|
862
|
-
* @returns {T["resolved"] | undefined} the resolved entry
|
866
|
+
* @param {T | null} entry entry
|
867
|
+
* @returns {T["resolved"] | null | undefined} the resolved entry
|
863
868
|
*/
|
864
869
|
const getResolvedTimestamp = entry => {
|
865
870
|
if (entry === null) return null;
|
@@ -868,8 +873,8 @@ const getResolvedTimestamp = entry => {
|
|
868
873
|
};
|
869
874
|
|
870
875
|
/**
|
871
|
-
* @param {ContextHash} entry entry
|
872
|
-
* @returns {string | undefined} the resolved entry
|
876
|
+
* @param {ContextHash | null} entry entry
|
877
|
+
* @returns {string | null | undefined} the resolved entry
|
873
878
|
*/
|
874
879
|
const getResolvedHash = entry => {
|
875
880
|
if (entry === null) return null;
|
@@ -877,6 +882,11 @@ const getResolvedHash = entry => {
|
|
877
882
|
return entry.symlinks === undefined ? entry.hash : undefined;
|
878
883
|
};
|
879
884
|
|
885
|
+
/**
|
886
|
+
* @template T
|
887
|
+
* @param {Set<T>} source source
|
888
|
+
* @param {Set<T>} target target
|
889
|
+
*/
|
880
890
|
const addAll = (source, target) => {
|
881
891
|
for (const key of source) target.add(key);
|
882
892
|
};
|
@@ -1145,6 +1155,11 @@ class FileSystemInfo {
|
|
1145
1155
|
);
|
1146
1156
|
}
|
1147
1157
|
|
1158
|
+
/**
|
1159
|
+
* @param {string} path path
|
1160
|
+
* @param {string} reason reason
|
1161
|
+
* @param {any[]} args arguments
|
1162
|
+
*/
|
1148
1163
|
_log(path, reason, ...args) {
|
1149
1164
|
const key = path + reason;
|
1150
1165
|
if (this._loggedPaths.has(key)) return;
|
@@ -1258,7 +1273,7 @@ class FileSystemInfo {
|
|
1258
1273
|
|
1259
1274
|
/**
|
1260
1275
|
* @param {string} path file path
|
1261
|
-
* @param {function((WebpackError | null)=, string=): void} callback callback function
|
1276
|
+
* @param {function((WebpackError | null)=, (string | null)=): void} callback callback function
|
1262
1277
|
* @returns {void}
|
1263
1278
|
*/
|
1264
1279
|
getFileHash(path, callback) {
|
@@ -1289,7 +1304,7 @@ class FileSystemInfo {
|
|
1289
1304
|
|
1290
1305
|
/**
|
1291
1306
|
* @param {string} path context path
|
1292
|
-
* @param {function((WebpackError | null)=, ContextHash=): void} callback callback function
|
1307
|
+
* @param {function((WebpackError | null)=, (ContextHash | null)=): void} callback callback function
|
1293
1308
|
* @returns {void}
|
1294
1309
|
*/
|
1295
1310
|
_getUnresolvedContextHash(path, callback) {
|
@@ -1320,7 +1335,7 @@ class FileSystemInfo {
|
|
1320
1335
|
|
1321
1336
|
/**
|
1322
1337
|
* @param {string} path context path
|
1323
|
-
* @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function
|
1338
|
+
* @param {function((WebpackError | null)=, (ContextTimestampAndHash | null)=): void} callback callback function
|
1324
1339
|
* @returns {void}
|
1325
1340
|
*/
|
1326
1341
|
_getUnresolvedContextTsh(path, callback) {
|
@@ -1383,7 +1398,7 @@ class FileSystemInfo {
|
|
1383
1398
|
const resolveDirectories = new Set();
|
1384
1399
|
/** @type {Set<string>} */
|
1385
1400
|
const resolveMissing = new Set();
|
1386
|
-
/** @type {Map<string, string | false>} */
|
1401
|
+
/** @type {Map<string, string | false | undefined>} */
|
1387
1402
|
const resolveResults = new Map();
|
1388
1403
|
const invalidResolveResults = new Set();
|
1389
1404
|
const resolverContext = {
|
@@ -1391,6 +1406,10 @@ class FileSystemInfo {
|
|
1391
1406
|
contextDependencies: resolveDirectories,
|
1392
1407
|
missingDependencies: resolveMissing
|
1393
1408
|
};
|
1409
|
+
/**
|
1410
|
+
* @param {string} expected expected result
|
1411
|
+
* @returns {string} expected result
|
1412
|
+
*/
|
1394
1413
|
const expectedToString = expected => {
|
1395
1414
|
return expected ? ` (expected ${expected})` : "";
|
1396
1415
|
};
|
@@ -1610,7 +1629,7 @@ class FileSystemInfo {
|
|
1610
1629
|
break;
|
1611
1630
|
}
|
1612
1631
|
// Check commonjs cache for the module
|
1613
|
-
/** @type {NodeModule} */
|
1632
|
+
/** @type {NodeModule | undefined} */
|
1614
1633
|
const module = require.cache[path];
|
1615
1634
|
if (module && Array.isArray(module.children)) {
|
1616
1635
|
children: for (const child of module.children) {
|
@@ -1910,13 +1929,11 @@ class FileSystemInfo {
|
|
1910
1929
|
|
1911
1930
|
/**
|
1912
1931
|
*
|
1913
|
-
* @param {number} startTime when processing the files has started
|
1932
|
+
* @param {number | null | undefined} startTime when processing the files has started
|
1914
1933
|
* @param {Iterable<string>} files all files
|
1915
1934
|
* @param {Iterable<string>} directories all directories
|
1916
1935
|
* @param {Iterable<string>} missing all missing files or directories
|
1917
|
-
* @param {
|
1918
|
-
* @param {boolean=} options.hash should use hash to snapshot
|
1919
|
-
* @param {boolean=} options.timestamp should use timestamp to snapshot
|
1936
|
+
* @param {SnapshotOptions | null | undefined} options options object (for future extensions)
|
1920
1937
|
* @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function
|
1921
1938
|
* @returns {void}
|
1922
1939
|
*/
|
@@ -2053,6 +2070,9 @@ class FileSystemInfo {
|
|
2053
2070
|
}
|
2054
2071
|
return capturedItems;
|
2055
2072
|
};
|
2073
|
+
/**
|
2074
|
+
* @param {Set<string>} capturedFiles captured files
|
2075
|
+
*/
|
2056
2076
|
const processCapturedFiles = capturedFiles => {
|
2057
2077
|
switch (mode) {
|
2058
2078
|
case 3:
|
@@ -2639,6 +2659,10 @@ class FileSystemInfo {
|
|
2639
2659
|
}
|
2640
2660
|
}
|
2641
2661
|
}
|
2662
|
+
/**
|
2663
|
+
* @param {string} path file path
|
2664
|
+
* @param {string} hash hash
|
2665
|
+
*/
|
2642
2666
|
const processFileHashSnapshot = (path, hash) => {
|
2643
2667
|
const cache = this._fileHashes.get(path);
|
2644
2668
|
if (cache !== undefined) {
|
@@ -2921,7 +2945,7 @@ class FileSystemInfo {
|
|
2921
2945
|
|
2922
2946
|
const hash = createHash(this._hashFunction);
|
2923
2947
|
|
2924
|
-
hash.update(content);
|
2948
|
+
hash.update(/** @type {string | Buffer} */ (content));
|
2925
2949
|
|
2926
2950
|
const digest = /** @type {string} */ (hash.digest("hex"));
|
2927
2951
|
|
@@ -2985,7 +3009,7 @@ class FileSystemInfo {
|
|
2985
3009
|
* @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file
|
2986
3010
|
* @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory
|
2987
3011
|
* @param {function(string[], ItemType[]): T} options.reduce called from all context items
|
2988
|
-
* @param {function((Error | null)=, (T)=): void} callback callback
|
3012
|
+
* @param {function((Error | null)=, (T | null)=): void} callback callback
|
2989
3013
|
*/
|
2990
3014
|
_readContext(
|
2991
3015
|
{
|
@@ -3172,6 +3196,7 @@ class FileSystemInfo {
|
|
3172
3196
|
* @returns {void}
|
3173
3197
|
*/
|
3174
3198
|
_resolveContextTimestamp(entry, callback) {
|
3199
|
+
/** @type {string[]} */
|
3175
3200
|
const hashes = [];
|
3176
3201
|
let safeTime = 0;
|
3177
3202
|
processAsyncTree(
|
@@ -3280,6 +3305,7 @@ class FileSystemInfo {
|
|
3280
3305
|
* @returns {void}
|
3281
3306
|
*/
|
3282
3307
|
_resolveContextHash(entry, callback) {
|
3308
|
+
/** @type {string[]} */
|
3283
3309
|
const hashes = [];
|
3284
3310
|
processAsyncTree(
|
3285
3311
|
entry.symlinks,
|
@@ -3436,7 +3462,9 @@ class FileSystemInfo {
|
|
3436
3462
|
* @returns {void}
|
3437
3463
|
*/
|
3438
3464
|
_resolveContextTsh(entry, callback) {
|
3465
|
+
/** @type {string[]} */
|
3439
3466
|
const hashes = [];
|
3467
|
+
/** @type {string[]} */
|
3440
3468
|
const tsHashes = [];
|
3441
3469
|
let safeTime = 0;
|
3442
3470
|
processAsyncTree(
|
@@ -3554,7 +3582,7 @@ class FileSystemInfo {
|
|
3554
3582
|
}
|
3555
3583
|
let data;
|
3556
3584
|
try {
|
3557
|
-
data = JSON.parse(content.toString("utf-8"));
|
3585
|
+
data = JSON.parse(/** @type {Buffer} */ (content).toString("utf-8"));
|
3558
3586
|
} catch (e) {
|
3559
3587
|
return callback(e);
|
3560
3588
|
}
|
package/lib/Generator.js
CHANGED
@@ -45,6 +45,10 @@
|
|
45
45
|
*
|
46
46
|
*/
|
47
47
|
class Generator {
|
48
|
+
/**
|
49
|
+
* @param {Record<string, Generator>} map map of types
|
50
|
+
* @returns {ByTypeGenerator} generator by type
|
51
|
+
*/
|
48
52
|
static byType(map) {
|
49
53
|
return new ByTypeGenerator(map);
|
50
54
|
}
|
@@ -106,6 +110,9 @@ class Generator {
|
|
106
110
|
}
|
107
111
|
|
108
112
|
class ByTypeGenerator extends Generator {
|
113
|
+
/**
|
114
|
+
* @param {Record<string, Generator>} map map of types
|
115
|
+
*/
|
109
116
|
constructor(map) {
|
110
117
|
super();
|
111
118
|
this.map = map;
|
package/lib/Watching.js
CHANGED
@@ -11,6 +11,8 @@ const Stats = require("./Stats");
|
|
11
11
|
/** @typedef {import("./Compilation")} Compilation */
|
12
12
|
/** @typedef {import("./Compiler")} Compiler */
|
13
13
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
14
|
+
/** @typedef {import("./WebpackError")} WebpackError */
|
15
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
14
16
|
|
15
17
|
/**
|
16
18
|
* @template T
|
@@ -58,9 +60,9 @@ class Watching {
|
|
58
60
|
this._needRecords = true;
|
59
61
|
this.watcher = undefined;
|
60
62
|
this.pausedWatcher = undefined;
|
61
|
-
/** @type {Set<string>} */
|
63
|
+
/** @type {Set<string> | undefined} */
|
62
64
|
this._collectedChangedFiles = undefined;
|
63
|
-
/** @type {Set<string>} */
|
65
|
+
/** @type {Set<string> | undefined} */
|
64
66
|
this._collectedRemovedFiles = undefined;
|
65
67
|
this._done = this._done.bind(this);
|
66
68
|
process.nextTick(() => {
|
@@ -69,8 +71,8 @@ class Watching {
|
|
69
71
|
}
|
70
72
|
|
71
73
|
/**
|
72
|
-
* @param {ReadonlySet<string
|
73
|
-
* @param {ReadonlySet<string
|
74
|
+
* @param {ReadonlySet<string>=} changedFiles changed files
|
75
|
+
* @param {ReadonlySet<string>=} removedFiles removed files
|
74
76
|
*/
|
75
77
|
_mergeWithCollected(changedFiles, removedFiles) {
|
76
78
|
if (!changedFiles) return;
|
@@ -80,11 +82,13 @@ class Watching {
|
|
80
82
|
} else {
|
81
83
|
for (const file of changedFiles) {
|
82
84
|
this._collectedChangedFiles.add(file);
|
83
|
-
|
85
|
+
/** @type {Set<string>} */
|
86
|
+
(this._collectedRemovedFiles).delete(file);
|
84
87
|
}
|
85
|
-
for (const file of removedFiles) {
|
88
|
+
for (const file of /** @type {ReadonlySet<string>} */ (removedFiles)) {
|
86
89
|
this._collectedChangedFiles.delete(file);
|
87
|
-
|
90
|
+
/** @type {Set<string>} */
|
91
|
+
(this._collectedRemovedFiles).add(file);
|
88
92
|
}
|
89
93
|
}
|
90
94
|
}
|
@@ -228,7 +232,7 @@ class Watching {
|
|
228
232
|
}
|
229
233
|
|
230
234
|
/**
|
231
|
-
* @param {Error=} err an optional error
|
235
|
+
* @param {(Error | null)=} err an optional error
|
232
236
|
* @param {Compilation=} compilation the compilation
|
233
237
|
* @returns {void}
|
234
238
|
*/
|
@@ -237,13 +241,18 @@ class Watching {
|
|
237
241
|
|
238
242
|
const logger = compilation && compilation.getLogger("webpack.Watching");
|
239
243
|
|
244
|
+
/** @type {Stats | null} */
|
240
245
|
let stats = null;
|
241
246
|
|
247
|
+
/**
|
248
|
+
* @param {Error} err error
|
249
|
+
* @param {Callback<void>[]=} cbs callbacks
|
250
|
+
*/
|
242
251
|
const handleError = (err, cbs) => {
|
243
252
|
this.compiler.hooks.failed.call(err);
|
244
253
|
this.compiler.cache.beginIdle();
|
245
254
|
this.compiler.idle = true;
|
246
|
-
this.handler(err, stats);
|
255
|
+
this.handler(err, /** @type {Stats} */ (stats));
|
247
256
|
if (!cbs) {
|
248
257
|
cbs = this.callbacks;
|
249
258
|
this.callbacks = [];
|
@@ -258,11 +267,13 @@ class Watching {
|
|
258
267
|
!(this._isBlocked() && (this.blocked = true))
|
259
268
|
) {
|
260
269
|
if (compilation) {
|
261
|
-
|
270
|
+
/** @type {Logger} */
|
271
|
+
(logger).time("storeBuildDependencies");
|
262
272
|
this.compiler.cache.storeBuildDependencies(
|
263
273
|
compilation.buildDependencies,
|
264
274
|
err => {
|
265
|
-
|
275
|
+
/** @type {Logger} */
|
276
|
+
(logger).timeEnd("storeBuildDependencies");
|
266
277
|
if (err) return handleError(err);
|
267
278
|
this._go();
|
268
279
|
}
|
@@ -283,32 +294,42 @@ class Watching {
|
|
283
294
|
|
284
295
|
const cbs = this.callbacks;
|
285
296
|
this.callbacks = [];
|
286
|
-
|
287
|
-
|
288
|
-
|
297
|
+
/** @type {Logger} */
|
298
|
+
(logger).time("done hook");
|
299
|
+
this.compiler.hooks.done.callAsync(/** @type {Stats} */ (stats), err => {
|
300
|
+
/** @type {Logger} */
|
301
|
+
(logger).timeEnd("done hook");
|
289
302
|
if (err) return handleError(err, cbs);
|
290
|
-
this.handler(null, stats);
|
291
|
-
|
303
|
+
this.handler(null, /** @type {Stats} */ (stats));
|
304
|
+
/** @type {Logger} */
|
305
|
+
(logger).time("storeBuildDependencies");
|
292
306
|
this.compiler.cache.storeBuildDependencies(
|
293
|
-
|
307
|
+
/** @type {Compilation} */
|
308
|
+
(compilation).buildDependencies,
|
294
309
|
err => {
|
295
|
-
|
310
|
+
/** @type {Logger} */
|
311
|
+
(logger).timeEnd("storeBuildDependencies");
|
296
312
|
if (err) return handleError(err, cbs);
|
297
|
-
|
313
|
+
/** @type {Logger} */
|
314
|
+
(logger).time("beginIdle");
|
298
315
|
this.compiler.cache.beginIdle();
|
299
316
|
this.compiler.idle = true;
|
300
|
-
|
317
|
+
/** @type {Logger} */
|
318
|
+
(logger).timeEnd("beginIdle");
|
301
319
|
process.nextTick(() => {
|
302
320
|
if (!this.closed) {
|
303
321
|
this.watch(
|
304
|
-
|
305
|
-
compilation.
|
306
|
-
|
322
|
+
/** @type {Compilation} */
|
323
|
+
(compilation).fileDependencies,
|
324
|
+
/** @type {Compilation} */
|
325
|
+
(compilation).contextDependencies,
|
326
|
+
/** @type {Compilation} */
|
327
|
+
(compilation).missingDependencies
|
307
328
|
);
|
308
329
|
}
|
309
330
|
});
|
310
331
|
for (const cb of cbs) cb(null);
|
311
|
-
this.compiler.hooks.afterDone.call(stats);
|
332
|
+
this.compiler.hooks.afterDone.call(/** @type {Stats} */ (stats));
|
312
333
|
}
|
313
334
|
);
|
314
335
|
});
|
@@ -377,6 +398,13 @@ class Watching {
|
|
377
398
|
this._invalidate();
|
378
399
|
}
|
379
400
|
|
401
|
+
/**
|
402
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files
|
403
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories
|
404
|
+
* @param {ReadonlySet<string>=} changedFiles changed files
|
405
|
+
* @param {ReadonlySet<string>=} removedFiles removed files
|
406
|
+
* @returns {void}
|
407
|
+
*/
|
380
408
|
_invalidate(
|
381
409
|
fileTimeInfoEntries,
|
382
410
|
contextTimeInfoEntries,
|
@@ -423,6 +451,10 @@ class Watching {
|
|
423
451
|
}
|
424
452
|
return;
|
425
453
|
}
|
454
|
+
/**
|
455
|
+
* @param {(WebpackError | null)=} err error if any
|
456
|
+
* @param {Compilation=} compilation compilation if any
|
457
|
+
*/
|
426
458
|
const finalCallback = (err, compilation) => {
|
427
459
|
this.running = false;
|
428
460
|
this.compiler.running = false;
|
@@ -433,9 +465,14 @@ class Watching {
|
|
433
465
|
this.compiler.fileTimestamps = undefined;
|
434
466
|
this.compiler.contextTimestamps = undefined;
|
435
467
|
this.compiler.fsStartTime = undefined;
|
468
|
+
/**
|
469
|
+
* @param {(WebpackError | null)=} err error if any
|
470
|
+
*/
|
436
471
|
const shutdown = err => {
|
437
472
|
this.compiler.hooks.watchClose.call();
|
438
|
-
const closeCallbacks =
|
473
|
+
const closeCallbacks =
|
474
|
+
/** @type {Callback<void>[]} */
|
475
|
+
(this._closeCallbacks);
|
439
476
|
this._closeCallbacks = undefined;
|
440
477
|
for (const cb of closeCallbacks) cb(err);
|
441
478
|
};
|