webpack 5.66.0 → 5.67.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.

Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/lib/Cache.js +1 -1
  3. package/lib/CacheFacade.js +2 -2
  4. package/lib/CleanPlugin.js +1 -1
  5. package/lib/Compilation.js +12 -9
  6. package/lib/Compiler.js +57 -3
  7. package/lib/ContextModule.js +21 -17
  8. package/lib/DelegatedModule.js +1 -1
  9. package/lib/DependencyTemplates.js +1 -1
  10. package/lib/DllModule.js +1 -1
  11. package/lib/EvalDevToolModulePlugin.js +16 -1
  12. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  13. package/lib/ExternalModule.js +1 -1
  14. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  15. package/lib/FileSystemInfo.js +29 -25
  16. package/lib/HookWebpackError.js +1 -1
  17. package/lib/Module.js +1 -1
  18. package/lib/MultiCompiler.js +1 -1
  19. package/lib/MultiWatching.js +1 -1
  20. package/lib/NormalModule.js +6 -4
  21. package/lib/RawModule.js +1 -1
  22. package/lib/RuntimeGlobals.js +18 -0
  23. package/lib/RuntimeModule.js +1 -1
  24. package/lib/RuntimePlugin.js +28 -3
  25. package/lib/RuntimeTemplate.js +1 -1
  26. package/lib/Watching.js +1 -1
  27. package/lib/WebpackOptionsApply.js +1 -1
  28. package/lib/asset/AssetGenerator.js +62 -24
  29. package/lib/asset/AssetModulesPlugin.js +3 -0
  30. package/lib/asset/RawDataUrlModule.js +8 -5
  31. package/lib/cache/ResolverCachePlugin.js +1 -1
  32. package/lib/cli.js +44 -3
  33. package/lib/config/defaults.js +22 -5
  34. package/lib/config/normalization.js +5 -0
  35. package/lib/container/ContainerEntryModule.js +4 -2
  36. package/lib/container/FallbackModule.js +4 -4
  37. package/lib/container/RemoteModule.js +4 -2
  38. package/lib/css/CssExportsGenerator.js +139 -0
  39. package/lib/css/CssGenerator.js +3 -0
  40. package/lib/css/CssLoadingRuntimeModule.js +139 -85
  41. package/lib/css/CssModulesPlugin.js +20 -3
  42. package/lib/debug/ProfilingPlugin.js +12 -10
  43. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  44. package/lib/dependencies/LoaderPlugin.js +2 -2
  45. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  46. package/lib/hmr/lazyCompilationBackend.js +1 -1
  47. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  48. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  49. package/lib/ids/IdHelpers.js +24 -10
  50. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  51. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  52. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  53. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  54. package/lib/index.js +5 -0
  55. package/lib/optimize/ConcatenatedModule.js +1 -1
  56. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  57. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  58. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  59. package/lib/schemes/HttpUriPlugin.js +8 -8
  60. package/lib/sharing/ConsumeSharedModule.js +4 -2
  61. package/lib/sharing/ProvideSharedModule.js +4 -2
  62. package/lib/sharing/utils.js +1 -1
  63. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
  65. package/lib/util/AsyncQueue.js +1 -1
  66. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  67. package/package.json +3 -10
  68. package/schemas/WebpackOptions.check.js +1 -1
  69. package/schemas/WebpackOptions.json +43 -6
  70. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  71. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  72. package/types.d.ts +163 -42
package/README.md CHANGED
@@ -687,7 +687,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
687
687
 
688
688
  - [@google](https://github.com/google) for [Google Web Toolkit (GWT)](http://www.gwtproject.org/), which aims to compile Java to JavaScript. It features a similar [Code Splitting](http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html) as webpack.
689
689
  - [@medikoo](https://github.com/medikoo) for [modules-webmake](https://github.com/medikoo/modules-webmake), which is a similar project. webpack was born because I wanted Code Splitting for modules-webmake. Interestingly the [Code Splitting issue is still open](https://github.com/medikoo/modules-webmake/issues/7) (thanks also to @Phoscur for the discussion).
690
- - [@substack](https://github.com/substack) for [browserify](http://browserify.org/), which is a similar project and source for many ideas.
690
+ - [@substack](https://github.com/substack) for [browserify](https://browserify.org/), which is a similar project and source for many ideas.
691
691
  - [@jrburke](https://github.com/jrburke) for [require.js](https://requirejs.org/), which is a similar project and source for many ideas.
692
692
  - [@defunctzombie](https://github.com/defunctzombie) for the [browser-field spec](https://github.com/defunctzombie/package-browser-field-spec), which makes modules available for node.js, browserify and webpack.
693
693
  - Every early webpack user, which contributed to webpack by writing issues or PRs. You influenced the direction...
package/lib/Cache.js CHANGED
@@ -21,7 +21,7 @@ const {
21
21
  /**
22
22
  * @template T
23
23
  * @callback CallbackCache
24
- * @param {WebpackError=} err
24
+ * @param {(WebpackError | null)=} err
25
25
  * @param {T=} result
26
26
  * @returns {void}
27
27
  */
@@ -19,7 +19,7 @@ const mergeEtags = require("./cache/mergeEtags");
19
19
  /**
20
20
  * @template T
21
21
  * @callback CallbackCache
22
- * @param {WebpackError=} err
22
+ * @param {(WebpackError | null)=} err
23
23
  * @param {T=} result
24
24
  * @returns {void}
25
25
  */
@@ -27,7 +27,7 @@ const mergeEtags = require("./cache/mergeEtags");
27
27
  /**
28
28
  * @template T
29
29
  * @callback CallbackNormalErrorCache
30
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
31
31
  * @param {T=} result
32
32
  * @returns {void}
33
33
  */
@@ -45,7 +45,7 @@ const validate = createSchemaValidation(
45
45
  * @param {OutputFileSystem} fs filesystem
46
46
  * @param {string} outputPath output path
47
47
  * @param {Set<string>} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
48
- * @param {function(Error=, Set<string>=): void} callback returns the filenames of the assets that shouldn't be there
48
+ * @param {function((Error | null)=, Set<string>=): void} callback returns the filenames of the assets that shouldn't be there
49
49
  * @returns {void}
50
50
  */
51
51
  const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
@@ -116,34 +116,34 @@ const { isSourceEqual } = require("./util/source");
116
116
 
117
117
  /**
118
118
  * @callback Callback
119
- * @param {WebpackError=} err
119
+ * @param {(WebpackError | null)=} err
120
120
  * @returns {void}
121
121
  */
122
122
 
123
123
  /**
124
124
  * @callback ModuleCallback
125
- * @param {WebpackError=} err
125
+ * @param {(WebpackError | null)=} err
126
126
  * @param {Module=} result
127
127
  * @returns {void}
128
128
  */
129
129
 
130
130
  /**
131
131
  * @callback ModuleFactoryResultCallback
132
- * @param {WebpackError=} err
132
+ * @param {(WebpackError | null)=} err
133
133
  * @param {ModuleFactoryResult=} result
134
134
  * @returns {void}
135
135
  */
136
136
 
137
137
  /**
138
138
  * @callback ModuleOrFactoryResultCallback
139
- * @param {WebpackError=} err
139
+ * @param {(WebpackError | null)=} err
140
140
  * @param {Module | ModuleFactoryResult=} result
141
141
  * @returns {void}
142
142
  */
143
143
 
144
144
  /**
145
145
  * @callback ExecuteModuleCallback
146
- * @param {WebpackError=} err
146
+ * @param {(WebpackError | null)=} err
147
147
  * @param {ExecuteModuleResult=} result
148
148
  * @returns {void}
149
149
  */
@@ -1020,7 +1020,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1020
1020
  /** @type {Map<DepConstructor, ModuleFactory>} */
1021
1021
  this.dependencyFactories = new Map();
1022
1022
  /** @type {DependencyTemplates} */
1023
- this.dependencyTemplates = new DependencyTemplates();
1023
+ this.dependencyTemplates = new DependencyTemplates(
1024
+ this.outputOptions.hashFunction
1025
+ );
1024
1026
  this.childrenCounters = {};
1025
1027
  /** @type {Set<number|string>} */
1026
1028
  this.usedChunkIds = null;
@@ -3553,10 +3555,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3553
3555
  }
3554
3556
 
3555
3557
  /**
3558
+ * If `module` is passed, `loc` and `request` must also be passed.
3556
3559
  * @param {string | ChunkGroupOptions} groupOptions options for the chunk group
3557
- * @param {Module} module the module the references the chunk group
3558
- * @param {DependencyLocation} loc the location from with the chunk group is referenced (inside of module)
3559
- * @param {string} request the request from which the the chunk group is referenced
3560
+ * @param {Module=} module the module the references the chunk group
3561
+ * @param {DependencyLocation=} loc the location from with the chunk group is referenced (inside of module)
3562
+ * @param {string=} request the request from which the the chunk group is referenced
3560
3563
  * @returns {ChunkGroup} the new or existing chunk group
3561
3564
  */
3562
3565
  addChunkInGroup(groupOptions, module, loc, request) {
package/lib/Compiler.js CHANGED
@@ -58,13 +58,13 @@ const { isSourceEqual } = require("./util/source");
58
58
  /**
59
59
  * @template T
60
60
  * @callback Callback
61
- * @param {Error=} err
61
+ * @param {(Error | null)=} err
62
62
  * @param {T=} result
63
63
  */
64
64
 
65
65
  /**
66
66
  * @callback RunAsChildCallback
67
- * @param {Error=} err
67
+ * @param {(Error | null)=} err
68
68
  * @param {Chunk[]=} entries
69
69
  * @param {Compilation=} compilation
70
70
  */
@@ -165,6 +165,11 @@ class Compiler {
165
165
  /** @type {AsyncSeriesHook<[Compilation]>} */
166
166
  afterCompile: new AsyncSeriesHook(["compilation"]),
167
167
 
168
+ /** @type {AsyncSeriesHook<[]>} */
169
+ readRecords: new AsyncSeriesHook([]),
170
+ /** @type {AsyncSeriesHook<[]>} */
171
+ emitRecords: new AsyncSeriesHook([]),
172
+
168
173
  /** @type {AsyncSeriesHook<[Compiler]>} */
169
174
  watchRun: new AsyncSeriesHook(["compiler"]),
170
175
  /** @type {SyncHook<[Error]>} */
@@ -882,8 +887,32 @@ ${other}`);
882
887
  * @returns {void}
883
888
  */
884
889
  emitRecords(callback) {
885
- if (!this.recordsOutputPath) return callback();
890
+ if (this.hooks.emitRecords.isUsed()) {
891
+ if (this.recordsOutputPath) {
892
+ asyncLib.parallel(
893
+ [
894
+ cb => this.hooks.emitRecords.callAsync(cb),
895
+ this._emitRecords.bind(this)
896
+ ],
897
+ err => callback(err)
898
+ );
899
+ } else {
900
+ this.hooks.emitRecords.callAsync(callback);
901
+ }
902
+ } else {
903
+ if (this.recordsOutputPath) {
904
+ this._emitRecords(callback);
905
+ } else {
906
+ callback();
907
+ }
908
+ }
909
+ }
886
910
 
911
+ /**
912
+ * @param {Callback<void>} callback signals when the call finishes
913
+ * @returns {void}
914
+ */
915
+ _emitRecords(callback) {
887
916
  const writeFile = () => {
888
917
  this.outputFileSystem.writeFile(
889
918
  this.recordsOutputPath,
@@ -926,6 +955,31 @@ ${other}`);
926
955
  * @returns {void}
927
956
  */
928
957
  readRecords(callback) {
958
+ if (this.hooks.readRecords.isUsed()) {
959
+ if (this.recordsInputPath) {
960
+ asyncLib.parallel([
961
+ cb => this.hooks.readRecords.callAsync(cb),
962
+ this._readRecords.bind(this)
963
+ ]);
964
+ } else {
965
+ this.records = {};
966
+ this.hooks.readRecords.callAsync(callback);
967
+ }
968
+ } else {
969
+ if (this.recordsInputPath) {
970
+ this._readRecords(callback);
971
+ } else {
972
+ this.records = {};
973
+ callback();
974
+ }
975
+ }
976
+ }
977
+
978
+ /**
979
+ * @param {Callback<void>} callback signals when the call finishes
980
+ * @returns {void}
981
+ */
982
+ _readRecords(callback) {
929
983
  if (!this.recordsInputPath) {
930
984
  this.records = {};
931
985
  return callback();
@@ -71,7 +71,7 @@ const makeSerializable = require("./util/makeSerializable");
71
71
 
72
72
  /**
73
73
  * @callback ResolveDependenciesCallback
74
- * @param {Error=} err
74
+ * @param {(Error | null)=} err
75
75
  * @param {ContextElementDependency[]=} dependencies
76
76
  */
77
77
 
@@ -149,12 +149,9 @@ class ContextModule extends Module {
149
149
  this.resolveDependencies = undefined;
150
150
  }
151
151
 
152
- prettyRegExp(regexString) {
153
- // remove the "/" at the front and the beginning
154
- // "/foo/" -> "foo"
155
- return regexString
156
- .substring(1, regexString.length - 1)
157
- .replace(/!/g, "%21");
152
+ _prettyRegExp(regexString, stripSlash = true) {
153
+ const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C");
154
+ return stripSlash ? str.substring(1, str.length - 1) : str;
158
155
  }
159
156
 
160
157
  _createIdentifier() {
@@ -175,13 +172,19 @@ class ContextModule extends Module {
175
172
  identifier += `|${this.options.addon}`;
176
173
  }
177
174
  if (this.options.regExp) {
178
- identifier += `|${this.options.regExp}`;
175
+ identifier += `|${this._prettyRegExp(this.options.regExp, false)}`;
179
176
  }
180
177
  if (this.options.include) {
181
- identifier += `|include: ${this.options.include}`;
178
+ identifier += `|include: ${this._prettyRegExp(
179
+ this.options.include,
180
+ false
181
+ )}`;
182
182
  }
183
183
  if (this.options.exclude) {
184
- identifier += `|exclude: ${this.options.exclude}`;
184
+ identifier += `|exclude: ${this._prettyRegExp(
185
+ this.options.exclude,
186
+ false
187
+ )}`;
185
188
  }
186
189
  if (this.options.referencedExports) {
187
190
  identifier += `|referencedExports: ${JSON.stringify(
@@ -231,13 +234,13 @@ class ContextModule extends Module {
231
234
  identifier += ` ${requestShortener.shorten(this.options.addon)}`;
232
235
  }
233
236
  if (this.options.regExp) {
234
- identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
237
+ identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
235
238
  }
236
239
  if (this.options.include) {
237
- identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
240
+ identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
238
241
  }
239
242
  if (this.options.exclude) {
240
- identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
243
+ identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
241
244
  }
242
245
  if (this.options.referencedExports) {
243
246
  identifier += ` referencedExports: ${this.options.referencedExports
@@ -272,6 +275,7 @@ class ContextModule extends Module {
272
275
  this.context,
273
276
  options.associatedObjectForCache
274
277
  );
278
+ if (this.layer) identifier = `(${this.layer})/${identifier}`;
275
279
  if (this.options.mode) {
276
280
  identifier += ` ${this.options.mode}`;
277
281
  }
@@ -286,13 +290,13 @@ class ContextModule extends Module {
286
290
  )}`;
287
291
  }
288
292
  if (this.options.regExp) {
289
- identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
293
+ identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
290
294
  }
291
295
  if (this.options.include) {
292
- identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
296
+ identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
293
297
  }
294
298
  if (this.options.exclude) {
295
- identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
299
+ identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
296
300
  }
297
301
  if (this.options.referencedExports) {
298
302
  identifier += ` referencedExports: ${this.options.referencedExports
@@ -312,7 +316,7 @@ class ContextModule extends Module {
312
316
 
313
317
  /**
314
318
  * @param {NeedBuildContext} context context info
315
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
319
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
316
320
  * @returns {void}
317
321
  */
318
322
  needBuild({ fileSystemInfo }, callback) {
@@ -91,7 +91,7 @@ class DelegatedModule extends Module {
91
91
 
92
92
  /**
93
93
  * @param {NeedBuildContext} context context info
94
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
94
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
95
95
  * @returns {void}
96
96
  */
97
97
  needBuild(context, callback) {
@@ -57,7 +57,7 @@ class DependencyTemplates {
57
57
  }
58
58
 
59
59
  clone() {
60
- const newInstance = new DependencyTemplates();
60
+ const newInstance = new DependencyTemplates(this._hashFunction);
61
61
  newInstance._map = new Map(this._map);
62
62
  newInstance._hash = this._hash;
63
63
  return newInstance;
package/lib/DllModule.js CHANGED
@@ -96,7 +96,7 @@ class DllModule extends Module {
96
96
 
97
97
  /**
98
98
  * @param {NeedBuildContext} context context info
99
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
99
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
100
100
  * @returns {void}
101
101
  */
102
102
  needBuild(context, callback) {
@@ -8,6 +8,7 @@
8
8
  const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ExternalModule = require("./ExternalModule");
10
10
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
11
+ const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
@@ -77,7 +78,13 @@ class EvalDevToolModulePlugin {
77
78
  .replace(/^\//, "")
78
79
  );
79
80
  const result = new RawSource(
80
- `eval(${JSON.stringify(content + footer)});`
81
+ `eval(${
82
+ compilation.outputOptions.trustedTypes
83
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
84
+ content + footer
85
+ )})`
86
+ : JSON.stringify(content + footer)
87
+ });`
81
88
  );
82
89
  cache.set(source, result);
83
90
  return result;
@@ -95,6 +102,14 @@ class EvalDevToolModulePlugin {
95
102
  hash.update("EvalDevToolModulePlugin");
96
103
  hash.update("2");
97
104
  });
105
+ if (compilation.outputOptions.trustedTypes) {
106
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
107
+ "EvalDevToolModulePlugin",
108
+ (module, set, context) => {
109
+ set.add(RuntimeGlobals.createScript);
110
+ }
111
+ );
112
+ }
98
113
  });
99
114
  }
100
115
  }
@@ -8,6 +8,7 @@
8
8
  const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
10
  const NormalModule = require("./NormalModule");
11
+ const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
12
13
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
13
14
  const ConcatenatedModule = require("./optimize/ConcatenatedModule");
@@ -165,7 +166,15 @@ class EvalSourceMapDevToolPlugin {
165
166
  ) + `\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
166
167
 
167
168
  return result(
168
- new RawSource(`eval(${JSON.stringify(content + footer)});`)
169
+ new RawSource(
170
+ `eval(${
171
+ compilation.outputOptions.trustedTypes
172
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
173
+ content + footer
174
+ )})`
175
+ : JSON.stringify(content + footer)
176
+ });`
177
+ )
169
178
  );
170
179
  }
171
180
  );
@@ -181,6 +190,14 @@ class EvalSourceMapDevToolPlugin {
181
190
  hash.update("EvalSourceMapDevToolPlugin");
182
191
  hash.update("2");
183
192
  });
193
+ if (compilation.outputOptions.trustedTypes) {
194
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
195
+ "EvalSourceMapDevToolPlugin",
196
+ (module, set, context) => {
197
+ set.add(RuntimeGlobals.createScript);
198
+ }
199
+ );
200
+ }
184
201
  }
185
202
  );
186
203
  }
@@ -432,7 +432,7 @@ class ExternalModule extends Module {
432
432
 
433
433
  /**
434
434
  * @param {NeedBuildContext} context context info
435
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
435
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
436
436
  * @returns {void}
437
437
  */
438
438
  needBuild(context, callback) {
@@ -117,7 +117,7 @@ class ExternalModuleFactoryPlugin {
117
117
 
118
118
  /**
119
119
  * @param {Externals} externals externals config
120
- * @param {function(Error=, ExternalModule=): void} callback callback
120
+ * @param {function((Error | null)=, ExternalModule=): void} callback callback
121
121
  * @returns {void}
122
122
  */
123
123
  const handleExternals = (externals, callback) => {
@@ -1185,7 +1185,7 @@ class FileSystemInfo {
1185
1185
 
1186
1186
  /**
1187
1187
  * @param {string} path file path
1188
- * @param {function(WebpackError=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1188
+ * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1189
1189
  * @returns {void}
1190
1190
  */
1191
1191
  getFileTimestamp(path, callback) {
@@ -1196,7 +1196,7 @@ class FileSystemInfo {
1196
1196
 
1197
1197
  /**
1198
1198
  * @param {string} path context path
1199
- * @param {function(WebpackError=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1199
+ * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1200
1200
  * @returns {void}
1201
1201
  */
1202
1202
  getContextTimestamp(path, callback) {
@@ -1217,7 +1217,7 @@ class FileSystemInfo {
1217
1217
 
1218
1218
  /**
1219
1219
  * @param {string} path context path
1220
- * @param {function(WebpackError=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1220
+ * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1221
1221
  * @returns {void}
1222
1222
  */
1223
1223
  _getUnresolvedContextTimestamp(path, callback) {
@@ -1228,7 +1228,7 @@ class FileSystemInfo {
1228
1228
 
1229
1229
  /**
1230
1230
  * @param {string} path file path
1231
- * @param {function(WebpackError=, string=): void} callback callback function
1231
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1232
1232
  * @returns {void}
1233
1233
  */
1234
1234
  getFileHash(path, callback) {
@@ -1239,7 +1239,7 @@ class FileSystemInfo {
1239
1239
 
1240
1240
  /**
1241
1241
  * @param {string} path context path
1242
- * @param {function(WebpackError=, string=): void} callback callback function
1242
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1243
1243
  * @returns {void}
1244
1244
  */
1245
1245
  getContextHash(path, callback) {
@@ -1259,7 +1259,7 @@ class FileSystemInfo {
1259
1259
 
1260
1260
  /**
1261
1261
  * @param {string} path context path
1262
- * @param {function(WebpackError=, ContextHash=): void} callback callback function
1262
+ * @param {function((WebpackError | null)=, ContextHash=): void} callback callback function
1263
1263
  * @returns {void}
1264
1264
  */
1265
1265
  _getUnresolvedContextHash(path, callback) {
@@ -1270,7 +1270,7 @@ class FileSystemInfo {
1270
1270
 
1271
1271
  /**
1272
1272
  * @param {string} path context path
1273
- * @param {function(WebpackError=, ResolvedContextTimestampAndHash=): void} callback callback function
1273
+ * @param {function((WebpackError | null)=, ResolvedContextTimestampAndHash=): void} callback callback function
1274
1274
  * @returns {void}
1275
1275
  */
1276
1276
  getContextTsh(path, callback) {
@@ -1290,7 +1290,7 @@ class FileSystemInfo {
1290
1290
 
1291
1291
  /**
1292
1292
  * @param {string} path context path
1293
- * @param {function(WebpackError=, ContextTimestampAndHash=): void} callback callback function
1293
+ * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function
1294
1294
  * @returns {void}
1295
1295
  */
1296
1296
  _getUnresolvedContextTsh(path, callback) {
@@ -1330,7 +1330,7 @@ class FileSystemInfo {
1330
1330
  /**
1331
1331
  * @param {string} context context directory
1332
1332
  * @param {Iterable<string>} deps dependencies
1333
- * @param {function(Error=, ResolveBuildDependenciesResult=): void} callback callback function
1333
+ * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function
1334
1334
  * @returns {void}
1335
1335
  */
1336
1336
  resolveBuildDependencies(context, deps, callback) {
@@ -1798,7 +1798,7 @@ class FileSystemInfo {
1798
1798
 
1799
1799
  /**
1800
1800
  * @param {Map<string, string | false>} resolveResults results from resolving
1801
- * @param {function(Error=, boolean=): void} callback callback with true when resolveResults resolve the same way
1801
+ * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way
1802
1802
  * @returns {void}
1803
1803
  */
1804
1804
  checkResolveResultsValid(resolveResults, callback) {
@@ -1880,7 +1880,7 @@ class FileSystemInfo {
1880
1880
  * @param {Object} options options object (for future extensions)
1881
1881
  * @param {boolean=} options.hash should use hash to snapshot
1882
1882
  * @param {boolean=} options.timestamp should use timestamp to snapshot
1883
- * @param {function(WebpackError=, Snapshot=): void} callback callback function
1883
+ * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function
1884
1884
  * @returns {void}
1885
1885
  */
1886
1886
  createSnapshot(startTime, files, directories, missing, options, callback) {
@@ -2256,8 +2256,10 @@ class FileSystemInfo {
2256
2256
  for (const path of managedItems) {
2257
2257
  const cache = this._managedItems.get(path);
2258
2258
  if (cache !== undefined) {
2259
- if (cache !== "missing") {
2259
+ if (!cache.startsWith("*")) {
2260
2260
  managedFiles.add(join(this.fs, path, "package.json"));
2261
+ } else if (cache === "*nested") {
2262
+ managedMissing.add(join(this.fs, path, "package.json"));
2261
2263
  }
2262
2264
  managedItemInfo.set(path, cache);
2263
2265
  } else {
@@ -2271,8 +2273,10 @@ class FileSystemInfo {
2271
2273
  }
2272
2274
  jobError();
2273
2275
  } else if (entry) {
2274
- if (entry !== "missing") {
2276
+ if (!entry.startsWith("*")) {
2275
2277
  managedFiles.add(join(this.fs, path, "package.json"));
2278
+ } else if (cache === "*nested") {
2279
+ managedMissing.add(join(this.fs, path, "package.json"));
2276
2280
  }
2277
2281
  managedItemInfo.set(path, entry);
2278
2282
  jobDone();
@@ -2375,7 +2379,7 @@ class FileSystemInfo {
2375
2379
 
2376
2380
  /**
2377
2381
  * @param {Snapshot} snapshot the snapshot made
2378
- * @param {function(WebpackError=, boolean=): void} callback callback function
2382
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2379
2383
  * @returns {void}
2380
2384
  */
2381
2385
  checkSnapshotValid(snapshot, callback) {
@@ -2395,7 +2399,7 @@ class FileSystemInfo {
2395
2399
 
2396
2400
  /**
2397
2401
  * @param {Snapshot} snapshot the snapshot made
2398
- * @param {function(WebpackError=, boolean=): void} callback callback function
2402
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2399
2403
  * @returns {void}
2400
2404
  */
2401
2405
  _checkSnapshotValidNoCache(snapshot, callback) {
@@ -2944,7 +2948,7 @@ class FileSystemInfo {
2944
2948
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file
2945
2949
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory
2946
2950
  * @param {function(string[], ItemType[]): T} options.reduce called from all context items
2947
- * @param {function(Error=, (T)=): void} callback callback
2951
+ * @param {function((Error | null)=, (T)=): void} callback callback
2948
2952
  */
2949
2953
  _readContext(
2950
2954
  {
@@ -3127,7 +3131,7 @@ class FileSystemInfo {
3127
3131
 
3128
3132
  /**
3129
3133
  * @param {ContextFileSystemInfoEntry} entry entry
3130
- * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3134
+ * @param {function((Error | null)=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3131
3135
  * @returns {void}
3132
3136
  */
3133
3137
  _resolveContextTimestamp(entry, callback) {
@@ -3235,7 +3239,7 @@ class FileSystemInfo {
3235
3239
 
3236
3240
  /**
3237
3241
  * @param {ContextHash} entry context hash
3238
- * @param {function(Error=, string=): void} callback callback
3242
+ * @param {function((Error | null)=, string=): void} callback callback
3239
3243
  * @returns {void}
3240
3244
  */
3241
3245
  _resolveContextHash(entry, callback) {
@@ -3391,7 +3395,7 @@ class FileSystemInfo {
3391
3395
 
3392
3396
  /**
3393
3397
  * @param {ContextTimestampAndHash} entry entry
3394
- * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
3398
+ * @param {function((Error | null)=, ResolvedContextTimestampAndHash=): void} callback callback
3395
3399
  * @returns {void}
3396
3400
  */
3397
3401
  _resolveContextTsh(entry, callback) {
@@ -3471,8 +3475,8 @@ class FileSystemInfo {
3471
3475
  }
3472
3476
  if (!elements.has(path)) {
3473
3477
  // file or directory doesn't exist
3474
- this._managedItems.set(path, "missing");
3475
- return callback(null, "missing");
3478
+ this._managedItems.set(path, "*missing");
3479
+ return callback(null, "*missing");
3476
3480
  }
3477
3481
  // something exists
3478
3482
  // it may be a file or directory
@@ -3481,8 +3485,8 @@ class FileSystemInfo {
3481
3485
  (path.endsWith("/node_modules") || path.endsWith("\\node_modules"))
3482
3486
  ) {
3483
3487
  // we are only interested in existence of this special directory
3484
- this._managedItems.set(path, "exists");
3485
- return callback(null, "exists");
3488
+ this._managedItems.set(path, "*node_modules");
3489
+ return callback(null, "*node_modules");
3486
3490
  }
3487
3491
 
3488
3492
  // we assume it's a directory, as files shouldn't occur in managed paths
@@ -3499,8 +3503,8 @@ class FileSystemInfo {
3499
3503
  ) {
3500
3504
  // This is only a grouping folder e. g. used by yarn
3501
3505
  // we are only interested in existence of this special directory
3502
- this._managedItems.set(path, "nested");
3503
- return callback(null, "nested");
3506
+ this._managedItems.set(path, "*nested");
3507
+ return callback(null, "*nested");
3504
3508
  }
3505
3509
  this.logger.warn(
3506
3510
  `Managed item ${path} isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)`
@@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError;
51
51
 
52
52
  /**
53
53
  * @template T
54
- * @param {function(WebpackError=, T=): void} callback webpack error callback
54
+ * @param {function((WebpackError | null)=, T=): void} callback webpack error callback
55
55
  * @param {string} hook name of hook
56
56
  * @returns {Callback<T>} generic callback
57
57
  */
package/lib/Module.js CHANGED
@@ -691,7 +691,7 @@ class Module extends DependenciesBlock {
691
691
 
692
692
  /**
693
693
  * @param {NeedBuildContext} context context info
694
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
694
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
695
695
  * @returns {void}
696
696
  */
697
697
  needBuild(context, callback) {
@@ -27,7 +27,7 @@ const ArrayQueue = require("./util/ArrayQueue");
27
27
  /**
28
28
  * @template T
29
29
  * @callback Callback
30
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
31
31
  * @param {T=} result
32
32
  */
33
33