webpack 5.84.1 → 5.85.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (121) hide show
  1. package/lib/AsyncDependenciesBlock.js +2 -2
  2. package/lib/AutomaticPrefetchPlugin.js +1 -0
  3. package/lib/BannerPlugin.js +4 -0
  4. package/lib/CacheFacade.js +4 -0
  5. package/lib/ChunkGroup.js +5 -1
  6. package/lib/CleanPlugin.js +30 -7
  7. package/lib/CompatibilityPlugin.js +1 -1
  8. package/lib/Compilation.js +1 -1
  9. package/lib/Compiler.js +1 -1
  10. package/lib/ContextModuleFactory.js +1 -1
  11. package/lib/DllModuleFactory.js +1 -1
  12. package/lib/HookWebpackError.js +1 -1
  13. package/lib/IgnoreErrorModuleFactory.js +1 -1
  14. package/lib/Module.js +21 -9
  15. package/lib/ModuleFactory.js +1 -1
  16. package/lib/ModuleTypeConstants.js +2 -1
  17. package/lib/NormalModuleFactory.js +1 -1
  18. package/lib/NormalModuleReplacementPlugin.js +4 -2
  19. package/lib/NullFactory.js +1 -1
  20. package/lib/RecordIdsPlugin.js +4 -4
  21. package/lib/RuntimeModule.js +5 -5
  22. package/lib/RuntimePlugin.js +4 -0
  23. package/lib/RuntimeTemplate.js +2 -2
  24. package/lib/SelfModuleFactory.js +1 -1
  25. package/lib/Template.js +1 -1
  26. package/lib/UseStrictPlugin.js +4 -0
  27. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  28. package/lib/WatchIgnorePlugin.js +4 -0
  29. package/lib/WebpackOptionsApply.js +2 -1
  30. package/lib/asset/AssetGenerator.js +7 -2
  31. package/lib/asset/AssetModulesPlugin.js +7 -1
  32. package/lib/asset/AssetParser.js +4 -1
  33. package/lib/asset/RawDataUrlModule.js +5 -3
  34. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  35. package/lib/cache/PackFileCacheStrategy.js +7 -1
  36. package/lib/config/defaults.js +38 -10
  37. package/lib/config/normalization.js +2 -1
  38. package/lib/container/ContainerEntryModule.js +4 -0
  39. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  40. package/lib/container/FallbackDependency.js +7 -0
  41. package/lib/container/FallbackItemDependency.js +3 -0
  42. package/lib/container/FallbackModule.js +4 -0
  43. package/lib/container/FallbackModuleFactory.js +1 -1
  44. package/lib/container/RemoteModule.js +4 -0
  45. package/lib/container/RemoteRuntimeModule.js +1 -0
  46. package/lib/container/RemoteToExternalDependency.js +3 -0
  47. package/lib/dependencies/CommonJsPlugin.js +14 -12
  48. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -1
  49. package/lib/dependencies/HarmonyExports.js +3 -1
  50. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +16 -5
  51. package/lib/dependencies/HarmonyImportSpecifierDependency.js +75 -6
  52. package/lib/dependencies/WorkerPlugin.js +25 -1
  53. package/lib/esm/ModuleChunkFormatPlugin.js +13 -5
  54. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  55. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -8
  56. package/lib/hmr/LazyCompilationPlugin.js +1 -1
  57. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  58. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  59. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  60. package/lib/ids/HashedModuleIdsPlugin.js +8 -1
  61. package/lib/ids/IdHelpers.js +6 -0
  62. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  63. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  64. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  65. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  66. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
  67. package/lib/javascript/BasicEvaluatedExpression.js +12 -1
  68. package/lib/javascript/ChunkHelpers.js +2 -2
  69. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  70. package/lib/javascript/JavascriptModulesPlugin.js +24 -19
  71. package/lib/javascript/JavascriptParser.js +42 -18
  72. package/lib/javascript/StartupHelpers.js +1 -1
  73. package/lib/json/JsonGenerator.js +7 -5
  74. package/lib/json/JsonParser.js +1 -1
  75. package/lib/library/AbstractLibraryPlugin.js +4 -0
  76. package/lib/library/AssignLibraryPlugin.js +6 -4
  77. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  78. package/lib/library/ModuleLibraryPlugin.js +6 -3
  79. package/lib/library/SystemLibraryPlugin.js +1 -0
  80. package/lib/library/UmdLibraryPlugin.js +4 -0
  81. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  82. package/lib/node/NodeTemplatePlugin.js +10 -2
  83. package/lib/node/NodeWatchFileSystem.js +1 -1
  84. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -1
  85. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
  86. package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
  87. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -1
  88. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  89. package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
  90. package/lib/runtime/BaseUriRuntimeModule.js +5 -1
  91. package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
  92. package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
  93. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  94. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  95. package/lib/runtime/PublicPathRuntimeModule.js +5 -0
  96. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  97. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -0
  98. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -0
  99. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  100. package/lib/util/createHash.js +1 -1
  101. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  102. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  103. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
  104. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
  105. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
  106. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
  107. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
  108. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
  109. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  110. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
  111. package/lib/wasm-sync/WebAssemblyParser.js +9 -2
  112. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  113. package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
  114. package/lib/web/FetchCompileWasmPlugin.js +19 -2
  115. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  116. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  117. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  118. package/package.json +1 -1
  119. package/schemas/WebpackOptions.check.js +1 -1
  120. package/schemas/WebpackOptions.json +12 -0
  121. package/types.d.ts +189 -141
@@ -39,14 +39,14 @@ class AsyncDependenciesBlock extends DependenciesBlock {
39
39
  }
40
40
 
41
41
  /**
42
- * @returns {string} The name of the chunk
42
+ * @returns {string | undefined} The name of the chunk
43
43
  */
44
44
  get chunkName() {
45
45
  return this.groupOptions.name;
46
46
  }
47
47
 
48
48
  /**
49
- * @param {string} value The new chunk name
49
+ * @param {string | undefined} value The new chunk name
50
50
  * @returns {void}
51
51
  */
52
52
  set chunkName(value) {
@@ -27,6 +27,7 @@ class AutomaticPrefetchPlugin {
27
27
  );
28
28
  }
29
29
  );
30
+ /** @type {{context: string, request: string}[] | null} */
30
31
  let lastModules = null;
31
32
  compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
32
33
  lastModules = [];
@@ -24,6 +24,10 @@ const validate = createSchemaValidation(
24
24
  }
25
25
  );
26
26
 
27
+ /**
28
+ * @param {string} str string to wrap
29
+ * @returns {string} wrapped string
30
+ */
27
31
  const wrapComment = str => {
28
32
  if (!str.includes("\n")) {
29
33
  return Template.toComment(str);
@@ -55,6 +55,10 @@ class MultiItemCache {
55
55
  * @returns {Promise<T>} promise with the data
56
56
  */
57
57
  getPromise() {
58
+ /**
59
+ * @param {number} i index
60
+ * @returns {Promise<T>} promise with the data
61
+ */
58
62
  const next = i => {
59
63
  return this._items[i].getPromise().then(result => {
60
64
  if (result !== undefined) return result;
package/lib/ChunkGroup.js CHANGED
@@ -353,7 +353,7 @@ class ChunkGroup {
353
353
  }
354
354
 
355
355
  /**
356
- * @returns {Array} an array containing the blocks
356
+ * @returns {Array<AsyncDependenciesBlock>} an array containing the blocks
357
357
  */
358
358
  getBlocks() {
359
359
  return this._blocks.getFromCache(getArray);
@@ -363,6 +363,10 @@ class ChunkGroup {
363
363
  return this._blocks.size;
364
364
  }
365
365
 
366
+ /**
367
+ * @param {AsyncDependenciesBlock} block block
368
+ * @returns {boolean} true, if block exists
369
+ */
366
370
  hasBlock(block) {
367
371
  return this._blocks.has(block);
368
372
  }
@@ -78,7 +78,8 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
78
78
  directories,
79
79
  10,
80
80
  (directory, callback) => {
81
- fs.readdir(join(fs, outputPath, directory), (err, entries) => {
81
+ /** @type {NonNullable<OutputFileSystem["readdir"]>} */
82
+ (fs.readdir)(join(fs, outputPath, directory), (err, entries) => {
82
83
  if (err) {
83
84
  if (err.code === "ENOENT") return callback();
84
85
  if (err.code === "ENOTDIR") {
@@ -128,7 +129,8 @@ const getDiffToOldAssets = (currentAssets, oldAssets) => {
128
129
  */
129
130
  const doStat = (fs, filename, callback) => {
130
131
  if ("lstat" in fs) {
131
- fs.lstat(filename, callback);
132
+ /** @type {NonNullable<OutputFileSystem["lstat"]>} */
133
+ (fs.lstat)(filename, callback);
132
134
  } else {
133
135
  fs.stat(filename, callback);
134
136
  }
@@ -145,6 +147,9 @@ const doStat = (fs, filename, callback) => {
145
147
  * @returns {void}
146
148
  */
147
149
  const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
150
+ /**
151
+ * @param {string} msg message
152
+ */
148
153
  const log = msg => {
149
154
  if (dry) {
150
155
  logger.info(msg);
@@ -165,6 +170,10 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
165
170
  jobs,
166
171
  10,
167
172
  ({ type, filename, parent }, push, callback) => {
173
+ /**
174
+ * @param {Error & { code?: string }} err error
175
+ * @returns {void}
176
+ */
168
177
  const handleError = err => {
169
178
  if (err.code === "ENOENT") {
170
179
  log(`${filename} was removed during cleaning by something else`);
@@ -195,7 +204,9 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
195
204
  });
196
205
  return callback();
197
206
  }
198
- fs.readdir(path, (err, entries) => {
207
+
208
+ /** @type {NonNullable<OutputFileSystem["readdir"]>} */
209
+ (fs.readdir)(path, (err, entries) => {
199
210
  if (err) return handleError(err);
200
211
  /** @type {Job} */
201
212
  const deleteJob = {
@@ -317,9 +328,17 @@ class CleanPlugin {
317
328
  typeof keep === "function"
318
329
  ? keep
319
330
  : typeof keep === "string"
320
- ? path => path.startsWith(keep)
331
+ ? /**
332
+ * @param {string} path path
333
+ * @returns {boolean} true, if the path should be kept
334
+ */
335
+ path => path.startsWith(keep)
321
336
  : typeof keep === "object" && keep.test
322
- ? path => keep.test(path)
337
+ ? /**
338
+ * @param {string} path path
339
+ * @returns {boolean} true, if the path should be kept
340
+ */
341
+ path => keep.test(path)
323
342
  : () => false;
324
343
 
325
344
  // We assume that no external modification happens while the compiler is active
@@ -371,6 +390,10 @@ class CleanPlugin {
371
390
 
372
391
  const outputPath = compilation.getPath(compiler.outputPath, {});
373
392
 
393
+ /**
394
+ * @param {string} path path
395
+ * @returns {boolean} true, if needs to be kept
396
+ */
374
397
  const isKept = path => {
375
398
  const result = hooks.keep.call(path);
376
399
  if (result !== undefined) return result;
@@ -378,7 +401,7 @@ class CleanPlugin {
378
401
  };
379
402
 
380
403
  /**
381
- * @param {Error=} err err
404
+ * @param {(Error | null)=} err err
382
405
  * @param {Set<string>=} diff diff
383
406
  */
384
407
  const diffCallback = (err, diff) => {
@@ -392,7 +415,7 @@ class CleanPlugin {
392
415
  outputPath,
393
416
  dry,
394
417
  logger,
395
- diff,
418
+ /** @type {Set<string>} */ (diff),
396
419
  isKept,
397
420
  (err, keptAssets) => {
398
421
  if (err) {
@@ -113,7 +113,7 @@ class CompatibilityPlugin {
113
113
  return true;
114
114
  });
115
115
  parser.hooks.pattern
116
- .for("__webpack_exports__")
116
+ .for(RuntimeGlobals.exports)
117
117
  .tap(PLUGIN_NAME, pattern => {
118
118
  parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
119
119
  name: "__nested_webpack_exports__",
@@ -681,7 +681,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
681
681
  optimizeChunkModules: new AsyncSeriesBailHook(["chunks", "modules"]),
682
682
  /** @type {SyncHook<[Iterable<Chunk>, Iterable<Module>]>} */
683
683
  afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]),
684
- /** @type {SyncBailHook<[], boolean>} */
684
+ /** @type {SyncBailHook<[], boolean | undefined>} */
685
685
  shouldRecord: new SyncBailHook([]),
686
686
 
687
687
  /** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
package/lib/Compiler.js CHANGED
@@ -126,7 +126,7 @@ class Compiler {
126
126
  /** @type {SyncHook<[]>} */
127
127
  initialize: new SyncHook([]),
128
128
 
129
- /** @type {SyncBailHook<[Compilation], boolean>} */
129
+ /** @type {SyncBailHook<[Compilation], boolean | undefined>} */
130
130
  shouldEmit: new SyncBailHook(["compilation"]),
131
131
  /** @type {AsyncSeriesHook<[Stats]>} */
132
132
  done: new AsyncSeriesHook(["stats"]),
@@ -80,7 +80,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
80
80
 
81
81
  /**
82
82
  * @param {ModuleFactoryCreateData} data data object
83
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
83
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
84
84
  * @returns {void}
85
85
  */
86
86
  create(data, callback) {
@@ -19,7 +19,7 @@ class DllModuleFactory extends ModuleFactory {
19
19
  }
20
20
  /**
21
21
  * @param {ModuleFactoryCreateData} data data object
22
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
22
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
23
23
  * @returns {void}
24
24
  */
25
25
  create(data, callback) {
@@ -85,7 +85,7 @@ const tryRunOrWebpackError = (fn, hook) => {
85
85
  if (err instanceof WebpackError) {
86
86
  throw err;
87
87
  }
88
- throw new HookWebpackError(err, hook);
88
+ throw new HookWebpackError(/** @type {Error} */ (err), hook);
89
89
  }
90
90
  return r;
91
91
  };
@@ -26,7 +26,7 @@ class IgnoreErrorModuleFactory extends ModuleFactory {
26
26
 
27
27
  /**
28
28
  * @param {ModuleFactoryCreateData} data data object
29
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
29
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
30
30
  * @returns {void}
31
31
  */
32
32
  create(data, callback) {
package/lib/Module.js CHANGED
@@ -131,13 +131,13 @@ const deprecatedNeedRebuild = util.deprecate(
131
131
  class Module extends DependenciesBlock {
132
132
  /**
133
133
  * @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
134
- * @param {string=} context an optional context
135
- * @param {string=} layer an optional layer in which the module is
134
+ * @param {(string | null)=} context an optional context
135
+ * @param {(string | null)=} layer an optional layer in which the module is
136
136
  */
137
137
  constructor(type, context = null, layer = null) {
138
138
  super();
139
139
 
140
- /** @type {ModuleTypes | ""} */
140
+ /** @type {ModuleTypes} */
141
141
  this.type = type;
142
142
  /** @type {string | null} */
143
143
  this.context = context;
@@ -151,7 +151,7 @@ class Module extends DependenciesBlock {
151
151
  this.debugId = debugId++;
152
152
 
153
153
  // Info from Factory
154
- /** @type {ResolveOptions} */
154
+ /** @type {ResolveOptions | undefined} */
155
155
  this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
156
156
  /** @type {object | undefined} */
157
157
  this.factoryMeta = undefined;
@@ -167,9 +167,9 @@ class Module extends DependenciesBlock {
167
167
  this._warnings = undefined;
168
168
  /** @type {WebpackError[] | undefined} */
169
169
  this._errors = undefined;
170
- /** @type {BuildMeta} */
170
+ /** @type {BuildMeta | undefined} */
171
171
  this.buildMeta = undefined;
172
- /** @type {Record<string, any>} */
172
+ /** @type {Record<string, any> | undefined} */
173
173
  this.buildInfo = undefined;
174
174
  /** @type {Dependency[] | undefined} */
175
175
  this.presentationalDependencies = undefined;
@@ -331,6 +331,10 @@ class Module extends DependenciesBlock {
331
331
  );
332
332
  }
333
333
 
334
+ /**
335
+ * @param {Chunk} chunk the chunk
336
+ * @returns {boolean} true, when the module was added
337
+ */
334
338
  addChunk(chunk) {
335
339
  const chunkGraph = ChunkGraph.getChunkGraphForModule(
336
340
  this,
@@ -342,6 +346,10 @@ class Module extends DependenciesBlock {
342
346
  return true;
343
347
  }
344
348
 
349
+ /**
350
+ * @param {Chunk} chunk the chunk
351
+ * @returns {void}
352
+ */
345
353
  removeChunk(chunk) {
346
354
  return ChunkGraph.getChunkGraphForModule(
347
355
  this,
@@ -350,6 +358,10 @@ class Module extends DependenciesBlock {
350
358
  ).disconnectChunkAndModule(chunk, this);
351
359
  }
352
360
 
361
+ /**
362
+ * @param {Chunk} chunk the chunk
363
+ * @returns {boolean} true, when the module is in the chunk
364
+ */
353
365
  isInChunk(chunk) {
354
366
  return ChunkGraph.getChunkGraphForModule(
355
367
  this,
@@ -435,7 +447,7 @@ class Module extends DependenciesBlock {
435
447
  case "namespace":
436
448
  return "namespace";
437
449
  case "default":
438
- switch (this.buildMeta.defaultObject) {
450
+ switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
439
451
  case "redirect":
440
452
  return "default-with-named";
441
453
  case "redirect-warn":
@@ -447,7 +459,7 @@ class Module extends DependenciesBlock {
447
459
  if (strict) return "default-with-named";
448
460
  // Try to figure out value of __esModule by following reexports
449
461
  const handleDefault = () => {
450
- switch (this.buildMeta.defaultObject) {
462
+ switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
451
463
  case "redirect":
452
464
  case "redirect-warn":
453
465
  return "default-with-named";
@@ -664,7 +676,7 @@ class Module extends DependenciesBlock {
664
676
  ] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
665
677
  if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
666
678
  for (const originChunk of chunkGraph.getModuleChunksIterable(
667
- fromModule
679
+ /** @type {Module} */ (fromModule)
668
680
  )) {
669
681
  // return true if module this is not reachable from originChunk when ignoring chunk
670
682
  if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))
@@ -38,7 +38,7 @@ class ModuleFactory {
38
38
  /**
39
39
  * @abstract
40
40
  * @param {ModuleFactoryCreateData} data data object
41
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
41
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
42
42
  * @returns {void}
43
43
  */
44
44
  create(data, callback) {
@@ -135,7 +135,8 @@ const WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY = "lazy-compilation-proxy";
135
135
  /** @typedef {"css" | "css/global" | "css/module"} CSSModuleTypes */
136
136
  /** @typedef {"asset" | "asset/inline" | "asset/resource" | "asset/source" | "asset/raw-data-url"} AssetModuleTypes */
137
137
  /** @typedef {"runtime" | "fallback-module" | "remote-module" | "provide-module" | "consume-shared-module" | "lazy-compilation-proxy"} WebpackModuleTypes */
138
- /** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CSSModuleTypes | AssetModuleTypes | WebpackModuleTypes} ModuleTypes */
138
+ /** @typedef {string} UnknownModuleTypes */
139
+ /** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CSSModuleTypes | AssetModuleTypes | WebpackModuleTypes | UnknownModuleTypes} ModuleTypes */
139
140
 
140
141
  exports.ASSET_MODULE_TYPE = ASSET_MODULE_TYPE;
141
142
  exports.ASSET_MODULE_TYPE_RAW_DATA_URL = ASSET_MODULE_TYPE_RAW_DATA_URL;
@@ -753,7 +753,7 @@ class NormalModuleFactory extends ModuleFactory {
753
753
 
754
754
  /**
755
755
  * @param {ModuleFactoryCreateData} data data object
756
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
756
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
757
757
  * @returns {void}
758
758
  */
759
759
  create(data, callback) {
@@ -43,7 +43,9 @@ class NormalModuleReplacementPlugin {
43
43
  });
44
44
  nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", result => {
45
45
  const createData = result.createData;
46
- if (resourceRegExp.test(createData.resource)) {
46
+ if (
47
+ resourceRegExp.test(/** @type {string} */ (createData.resource))
48
+ ) {
47
49
  if (typeof newResource === "function") {
48
50
  newResource(result);
49
51
  } else {
@@ -56,7 +58,7 @@ class NormalModuleReplacementPlugin {
56
58
  } else {
57
59
  createData.resource = join(
58
60
  fs,
59
- dirname(fs, createData.resource),
61
+ dirname(fs, /** @type {string} */ (createData.resource)),
60
62
  newResource
61
63
  );
62
64
  }
@@ -13,7 +13,7 @@ const ModuleFactory = require("./ModuleFactory");
13
13
  class NullFactory extends ModuleFactory {
14
14
  /**
15
15
  * @param {ModuleFactoryCreateData} data data object
16
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
16
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
17
17
  * @returns {void}
18
18
  */
19
19
  create(data, callback) {
@@ -69,7 +69,7 @@ class RecordIdsPlugin {
69
69
  compilation.hooks.recordModules.tap(
70
70
  "RecordIdsPlugin",
71
71
  /**
72
- * @param {Module[]} modules the modules array
72
+ * @param {Iterable<Module>} modules the modules array
73
73
  * @param {Records} records the records object
74
74
  * @returns {void}
75
75
  */
@@ -92,7 +92,7 @@ class RecordIdsPlugin {
92
92
  compilation.hooks.reviveModules.tap(
93
93
  "RecordIdsPlugin",
94
94
  /**
95
- * @param {Module[]} modules the modules array
95
+ * @param {Iterable<Module>} modules the modules array
96
96
  * @param {Records} records the records object
97
97
  * @returns {void}
98
98
  */
@@ -166,7 +166,7 @@ class RecordIdsPlugin {
166
166
  compilation.hooks.recordChunks.tap(
167
167
  "RecordIdsPlugin",
168
168
  /**
169
- * @param {Chunk[]} chunks the chunks array
169
+ * @param {Iterable<Chunk>} chunks the chunks array
170
170
  * @param {Records} records the records object
171
171
  * @returns {void}
172
172
  */
@@ -192,7 +192,7 @@ class RecordIdsPlugin {
192
192
  compilation.hooks.reviveChunks.tap(
193
193
  "RecordIdsPlugin",
194
194
  /**
195
- * @param {Chunk[]} chunks the chunks array
195
+ * @param {Iterable<Chunk>} chunks the chunks array
196
196
  * @param {Records} records the records object
197
197
  * @returns {void}
198
198
  */
@@ -38,15 +38,15 @@ class RuntimeModule extends Module {
38
38
  this.stage = stage;
39
39
  this.buildMeta = {};
40
40
  this.buildInfo = {};
41
- /** @type {Compilation} */
41
+ /** @type {Compilation | undefined} */
42
42
  this.compilation = undefined;
43
- /** @type {Chunk} */
43
+ /** @type {Chunk | undefined} */
44
44
  this.chunk = undefined;
45
- /** @type {ChunkGraph} */
45
+ /** @type {ChunkGraph | undefined} */
46
46
  this.chunkGraph = undefined;
47
47
  this.fullHash = false;
48
48
  this.dependentHash = false;
49
- /** @type {string} */
49
+ /** @type {string | undefined} */
50
50
  this._cachedGeneratedCode = undefined;
51
51
  }
52
52
 
@@ -117,7 +117,7 @@ class RuntimeModule extends Module {
117
117
  hash.update(this.getGeneratedCode());
118
118
  }
119
119
  } catch (err) {
120
- hash.update(err.message);
120
+ hash.update(/** @type {Error} */ (err).message);
121
121
  }
122
122
  super.updateHash(hash, context);
123
123
  }
@@ -99,6 +99,10 @@ class RuntimePlugin {
99
99
  apply(compiler) {
100
100
  compiler.hooks.compilation.tap("RuntimePlugin", compilation => {
101
101
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
102
+ /**
103
+ * @param {Chunk} chunk chunk
104
+ * @returns {boolean} true, when chunk loading is disabled for the chunk
105
+ */
102
106
  const isChunkLoadingDisabledForChunk = chunk => {
103
107
  const options = chunk.getEntryOptions();
104
108
  const chunkLoading =
@@ -794,10 +794,10 @@ class RuntimeTemplate {
794
794
  * @param {Module} options.originModule the origin module
795
795
  * @param {boolean|undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
796
796
  * @param {boolean} options.isCall true, if expression will be called
797
- * @param {boolean} options.callContext when false, call context will not be preserved
797
+ * @param {boolean | null} options.callContext when false, call context will not be preserved
798
798
  * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
799
799
  * @param {string} options.importVar the identifier name of the import variable
800
- * @param {InitFragment[]} options.initFragments init fragments will be added here
800
+ * @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
801
801
  * @param {RuntimeSpec} options.runtime runtime for which this code will be generated
802
802
  * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
803
803
  * @returns {string} expression
@@ -19,7 +19,7 @@ class SelfModuleFactory {
19
19
 
20
20
  /**
21
21
  * @param {ModuleFactoryCreateData} data data object
22
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
22
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
23
23
  * @returns {void}
24
24
  */
25
25
  create(data, callback) {
package/lib/Template.js CHANGED
@@ -290,7 +290,7 @@ class Template {
290
290
  * @param {Module[]} modules modules to render (should be ordered by identifier)
291
291
  * @param {function(Module): Source} renderModule function to render a module
292
292
  * @param {string=} prefix applying prefix strings
293
- * @returns {Source} rendered chunk modules in a Source object
293
+ * @returns {Source | null} rendered chunk modules in a Source object or null if no modules
294
294
  */
295
295
  static renderChunkModules(renderContext, modules, renderModule, prefix = "") {
296
296
  const { chunkGraph } = renderContext;
@@ -13,6 +13,7 @@ const {
13
13
  const ConstDependency = require("./dependencies/ConstDependency");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
16
17
 
17
18
  const PLUGIN_NAME = "UseStrictPlugin";
18
19
 
@@ -26,6 +27,9 @@ class UseStrictPlugin {
26
27
  compiler.hooks.compilation.tap(
27
28
  PLUGIN_NAME,
28
29
  (compilation, { normalModuleFactory }) => {
30
+ /**
31
+ * @param {JavascriptParser} parser the parser
32
+ */
29
33
  const handler = parser => {
30
34
  parser.hooks.program.tap(PLUGIN_NAME, ast => {
31
35
  const firstNode = ast.body[0];
@@ -40,6 +40,13 @@ class WarnDeprecatedOptionPlugin {
40
40
  }
41
41
 
42
42
  class DeprecatedOptionWarning extends WebpackError {
43
+ /**
44
+ * Create an instance deprecated option warning
45
+ *
46
+ * @param {string} option the target option
47
+ * @param {string | number} value the deprecated option value
48
+ * @param {string} suggestion the suggestion replacement
49
+ */
43
50
  constructor(option, value, suggestion) {
44
51
  super();
45
52
 
@@ -36,6 +36,10 @@ class IgnoringWatchFileSystem {
36
36
  watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
37
37
  files = Array.from(files);
38
38
  dirs = Array.from(dirs);
39
+ /**
40
+ * @param {string} path path to check
41
+ * @returns {boolean} true, if path is ignored
42
+ */
39
43
  const ignored = path =>
40
44
  this.paths.some(p =>
41
45
  p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0
@@ -657,7 +657,8 @@ class WebpackOptionsApply extends OptionsApply {
657
657
  maxAge: cacheOptions.maxAge,
658
658
  profile: cacheOptions.profile,
659
659
  allowCollectingMemory: cacheOptions.allowCollectingMemory,
660
- compression: cacheOptions.compression
660
+ compression: cacheOptions.compression,
661
+ readonly: cacheOptions.readonly
661
662
  }),
662
663
  cacheOptions.idleTimeout,
663
664
  cacheOptions.idleTimeoutForInitialStore,
@@ -107,6 +107,11 @@ const encodeDataUri = (encoding, source) => {
107
107
  return encodedContent;
108
108
  };
109
109
 
110
+ /**
111
+ * @param {string} encoding encoding
112
+ * @param {string} content content
113
+ * @returns {Buffer} decoded content
114
+ */
110
115
  const decodeDataUriContent = (encoding, content) => {
111
116
  const isBase64 = encoding === "base64";
112
117
 
@@ -230,10 +235,10 @@ class AssetGenerator extends Generator {
230
235
  ) {
231
236
  switch (type) {
232
237
  case ASSET_MODULE_TYPE:
233
- return module.originalSource();
238
+ return /** @type {Source} */ (module.originalSource());
234
239
  default: {
235
240
  let content;
236
- const originalSource = module.originalSource();
241
+ const originalSource = /** @type {Source} */ (module.originalSource());
237
242
  if (module.buildInfo.dataUrl) {
238
243
  let encodedSource;
239
244
  if (typeof this.dataUrlOptions === "function") {
@@ -21,6 +21,10 @@ const memoize = require("../util/memoize");
21
21
  /** @typedef {import("../Compiler")} Compiler */
22
22
  /** @typedef {import("../Module")} Module */
23
23
 
24
+ /**
25
+ * @param {string} name name of definitions
26
+ * @returns {TODO} definition
27
+ */
24
28
  const getSchema = name => {
25
29
  const { definitions } = require("../../schemas/WebpackOptions.json");
26
30
  return {
@@ -204,7 +208,9 @@ class AssetModulesPlugin {
204
208
  codeGenResult.data.get("fullContentHash")
205
209
  });
206
210
  } catch (e) {
207
- e.message += `\nduring rendering of asset ${module.identifier()}`;
211
+ /** @type {Error} */ (
212
+ e
213
+ ).message += `\nduring rendering of asset ${module.identifier()}`;
208
214
  throw e;
209
215
  }
210
216
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  const Parser = require("../Parser");
9
9
 
10
+ /** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
10
11
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
11
12
  /** @typedef {import("../Parser").ParserState} ParserState */
12
13
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
@@ -45,7 +46,9 @@ class AssetParser extends Parser {
45
46
  typeof this.dataUrlCondition === "object"
46
47
  ) {
47
48
  state.module.buildInfo.dataUrl =
48
- Buffer.byteLength(source) <= this.dataUrlCondition.maxSize;
49
+ Buffer.byteLength(source) <=
50
+ /** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
51
+ (this.dataUrlCondition.maxSize);
49
52
  } else {
50
53
  throw new Error("Unexpected dataUrlCondition type");
51
54
  }