webpack 5.98.0 → 5.99.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.
Files changed (251) hide show
  1. package/README.md +7 -3
  2. package/lib/AsyncDependenciesBlock.js +3 -1
  3. package/lib/BannerPlugin.js +1 -1
  4. package/lib/Cache.js +9 -7
  5. package/lib/CacheFacade.js +5 -5
  6. package/lib/Chunk.js +2 -2
  7. package/lib/ChunkGraph.js +21 -16
  8. package/lib/ChunkTemplate.js +6 -6
  9. package/lib/CleanPlugin.js +10 -10
  10. package/lib/CodeGenerationResults.js +4 -3
  11. package/lib/CompatibilityPlugin.js +4 -1
  12. package/lib/Compilation.js +326 -152
  13. package/lib/Compiler.js +13 -18
  14. package/lib/ConditionalInitFragment.js +1 -1
  15. package/lib/ConstPlugin.js +5 -3
  16. package/lib/ContextModule.js +4 -2
  17. package/lib/ContextModuleFactory.js +3 -3
  18. package/lib/ContextReplacementPlugin.js +43 -16
  19. package/lib/DefinePlugin.js +25 -24
  20. package/lib/DelegatedModule.js +4 -2
  21. package/lib/DelegatedModuleFactoryPlugin.js +2 -1
  22. package/lib/Dependency.js +19 -13
  23. package/lib/DependencyTemplates.js +4 -3
  24. package/lib/DllModule.js +4 -2
  25. package/lib/DllModuleFactory.js +2 -2
  26. package/lib/DllReferencePlugin.js +2 -1
  27. package/lib/DynamicEntryPlugin.js +1 -1
  28. package/lib/EnvironmentPlugin.js +4 -2
  29. package/lib/ExportsInfo.js +72 -40
  30. package/lib/ExternalModule.js +14 -5
  31. package/lib/ExternalModuleFactoryPlugin.js +24 -12
  32. package/lib/FileSystemInfo.js +129 -94
  33. package/lib/FlagDependencyExportsPlugin.js +6 -4
  34. package/lib/FlagDependencyUsagePlugin.js +1 -1
  35. package/lib/Generator.js +29 -1
  36. package/lib/HookWebpackError.js +2 -2
  37. package/lib/HotModuleReplacementPlugin.js +3 -9
  38. package/lib/IgnoreErrorModuleFactory.js +2 -2
  39. package/lib/IgnorePlugin.js +0 -5
  40. package/lib/InitFragment.js +1 -1
  41. package/lib/LoaderOptionsPlugin.js +8 -5
  42. package/lib/MainTemplate.js +7 -7
  43. package/lib/Module.js +40 -17
  44. package/lib/ModuleBuildError.js +3 -1
  45. package/lib/ModuleDependencyError.js +4 -3
  46. package/lib/ModuleDependencyWarning.js +4 -3
  47. package/lib/ModuleFactory.js +9 -3
  48. package/lib/ModuleFilenameHelpers.js +13 -13
  49. package/lib/ModuleGraph.js +20 -14
  50. package/lib/ModuleGraphConnection.js +7 -13
  51. package/lib/ModuleNotFoundError.js +1 -1
  52. package/lib/ModuleParseError.js +2 -1
  53. package/lib/ModuleSourceTypesConstants.js +11 -0
  54. package/lib/ModuleTemplate.js +5 -5
  55. package/lib/ModuleTypeConstants.js +15 -0
  56. package/lib/MultiCompiler.js +4 -4
  57. package/lib/MultiStats.js +1 -1
  58. package/lib/NormalModule.js +101 -54
  59. package/lib/NormalModuleFactory.js +38 -33
  60. package/lib/NormalModuleReplacementPlugin.js +3 -2
  61. package/lib/NullFactory.js +2 -2
  62. package/lib/Parser.js +4 -3
  63. package/lib/ProgressPlugin.js +1 -2
  64. package/lib/RawModule.js +4 -2
  65. package/lib/RecordIdsPlugin.js +6 -2
  66. package/lib/RequestShortener.js +3 -1
  67. package/lib/ResolverFactory.js +12 -9
  68. package/lib/RuntimeModule.js +4 -2
  69. package/lib/RuntimeTemplate.js +2 -1
  70. package/lib/SelfModuleFactory.js +2 -2
  71. package/lib/SourceMapDevToolPlugin.js +0 -8
  72. package/lib/Template.js +6 -5
  73. package/lib/TemplatedPathPlugin.js +15 -12
  74. package/lib/WebpackOptionsApply.js +1 -1
  75. package/lib/asset/AssetGenerator.js +237 -170
  76. package/lib/asset/AssetModulesPlugin.js +50 -8
  77. package/lib/asset/AssetSourceGenerator.js +18 -0
  78. package/lib/asset/RawDataUrlModule.js +4 -2
  79. package/lib/buildChunkGraph.js +14 -4
  80. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  81. package/lib/cache/PackFileCacheStrategy.js +137 -121
  82. package/lib/cache/ResolverCachePlugin.js +15 -7
  83. package/lib/cache/getLazyHashedEtag.js +4 -3
  84. package/lib/cli.js +23 -15
  85. package/lib/config/defaults.js +93 -26
  86. package/lib/config/normalization.js +14 -13
  87. package/lib/config/target.js +8 -8
  88. package/lib/container/ContainerEntryModule.js +4 -2
  89. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  90. package/lib/container/FallbackModule.js +4 -2
  91. package/lib/container/FallbackModuleFactory.js +2 -2
  92. package/lib/container/RemoteModule.js +4 -2
  93. package/lib/container/options.js +5 -5
  94. package/lib/css/CssGenerator.js +71 -9
  95. package/lib/css/CssModulesPlugin.js +30 -5
  96. package/lib/css/CssParser.js +37 -17
  97. package/lib/css/walkCssTokens.js +17 -17
  98. package/lib/debug/ProfilingPlugin.js +98 -38
  99. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
  100. package/lib/dependencies/AMDPlugin.js +5 -2
  101. package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
  102. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  103. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
  104. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  105. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
  106. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
  107. package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
  108. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  109. package/lib/dependencies/ContextDependencyHelpers.js +13 -6
  110. package/lib/dependencies/CssIcssExportDependency.js +15 -12
  111. package/lib/dependencies/CssIcssImportDependency.js +4 -1
  112. package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
  113. package/lib/dependencies/ExportsInfoDependency.js +6 -1
  114. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
  115. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
  116. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
  117. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  118. package/lib/dependencies/HarmonyImportDependency.js +8 -6
  119. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
  120. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
  121. package/lib/dependencies/ImportContextDependency.js +2 -1
  122. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
  123. package/lib/dependencies/JsonExportsDependency.js +24 -8
  124. package/lib/dependencies/LoaderPlugin.js +4 -14
  125. package/lib/dependencies/RequireContextDependency.js +2 -1
  126. package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
  127. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
  128. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
  129. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  130. package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
  131. package/lib/dependencies/WorkerDependency.js +6 -3
  132. package/lib/dependencies/WorkerPlugin.js +100 -41
  133. package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
  134. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  136. package/lib/hmr/LazyCompilationPlugin.js +32 -24
  137. package/lib/hmr/lazyCompilationBackend.js +1 -1
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  139. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  140. package/lib/ids/IdHelpers.js +15 -14
  141. package/lib/ids/SyncModuleIdsPlugin.js +9 -5
  142. package/lib/index.js +5 -5
  143. package/lib/javascript/BasicEvaluatedExpression.js +6 -6
  144. package/lib/javascript/JavascriptGenerator.js +11 -1
  145. package/lib/javascript/JavascriptModulesPlugin.js +51 -31
  146. package/lib/javascript/JavascriptParser.js +272 -188
  147. package/lib/javascript/JavascriptParserHelpers.js +10 -9
  148. package/lib/javascript/StartupHelpers.js +4 -1
  149. package/lib/json/JsonData.js +4 -4
  150. package/lib/json/JsonGenerator.js +54 -22
  151. package/lib/json/JsonModulesPlugin.js +16 -2
  152. package/lib/json/JsonParser.js +8 -4
  153. package/lib/library/AbstractLibraryPlugin.js +7 -3
  154. package/lib/library/AssignLibraryPlugin.js +29 -1
  155. package/lib/library/EnableLibraryPlugin.js +7 -10
  156. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  157. package/lib/library/ModuleLibraryPlugin.js +121 -15
  158. package/lib/logging/Logger.js +2 -2
  159. package/lib/logging/createConsoleLogger.js +4 -4
  160. package/lib/node/NodeEnvironmentPlugin.js +6 -2
  161. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
  162. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  163. package/lib/node/nodeConsole.js +3 -1
  164. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  165. package/lib/optimize/ConcatenatedModule.js +19 -12
  166. package/lib/optimize/InnerGraph.js +3 -2
  167. package/lib/optimize/InnerGraphPlugin.js +13 -7
  168. package/lib/optimize/LimitChunkCountPlugin.js +20 -0
  169. package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
  170. package/lib/optimize/RealContentHashPlugin.js +8 -4
  171. package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
  172. package/lib/optimize/SplitChunksPlugin.js +87 -65
  173. package/lib/rules/BasicEffectRulePlugin.js +9 -1
  174. package/lib/rules/BasicMatcherRulePlugin.js +15 -4
  175. package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
  176. package/lib/rules/RuleSetCompiler.js +25 -14
  177. package/lib/rules/UseEffectRulePlugin.js +47 -17
  178. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
  179. package/lib/schemes/HttpUriPlugin.js +38 -17
  180. package/lib/serialization/BinaryMiddleware.js +52 -19
  181. package/lib/serialization/FileMiddleware.js +78 -48
  182. package/lib/serialization/ObjectMiddleware.js +78 -29
  183. package/lib/serialization/PlainObjectSerializer.js +1 -1
  184. package/lib/serialization/Serializer.js +15 -10
  185. package/lib/serialization/SerializerMiddleware.js +80 -41
  186. package/lib/serialization/SingleItemMiddleware.js +10 -7
  187. package/lib/serialization/types.js +1 -1
  188. package/lib/sharing/ConsumeSharedModule.js +4 -2
  189. package/lib/sharing/ProvideSharedModule.js +4 -2
  190. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  191. package/lib/sharing/utils.js +2 -2
  192. package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
  193. package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
  194. package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
  195. package/lib/stats/StatsFactory.js +11 -11
  196. package/lib/stats/StatsPrinter.js +7 -7
  197. package/lib/util/ArrayHelpers.js +2 -4
  198. package/lib/util/ArrayQueue.js +1 -1
  199. package/lib/util/AsyncQueue.js +4 -4
  200. package/lib/util/IterableHelpers.js +1 -1
  201. package/lib/util/LazyBucketSortedSet.js +41 -23
  202. package/lib/util/LazySet.js +3 -2
  203. package/lib/util/MapHelpers.js +1 -1
  204. package/lib/util/ParallelismFactorCalculator.js +1 -1
  205. package/lib/util/Semaphore.js +3 -3
  206. package/lib/util/SetHelpers.js +1 -1
  207. package/lib/util/SortableSet.js +9 -7
  208. package/lib/util/TupleQueue.js +9 -8
  209. package/lib/util/TupleSet.js +2 -2
  210. package/lib/util/WeakTupleMap.js +12 -11
  211. package/lib/util/binarySearchBounds.js +2 -1
  212. package/lib/util/cleverMerge.js +84 -54
  213. package/lib/util/comparators.js +22 -21
  214. package/lib/util/compileBooleanMatcher.js +3 -3
  215. package/lib/util/concatenate.js +6 -4
  216. package/lib/util/create-schema-validation.js +4 -4
  217. package/lib/util/createHash.js +2 -2
  218. package/lib/util/deprecation.js +35 -33
  219. package/lib/util/deterministicGrouping.js +6 -6
  220. package/lib/util/findGraphRoots.js +1 -1
  221. package/lib/util/fs.js +39 -39
  222. package/lib/util/hash/wasm-hash.js +2 -2
  223. package/lib/util/identifier.js +15 -18
  224. package/lib/util/makeSerializable.js +1 -1
  225. package/lib/util/memoize.js +4 -1
  226. package/lib/util/objectToMap.js +3 -2
  227. package/lib/util/processAsyncTree.js +2 -2
  228. package/lib/util/propertyName.js +0 -1
  229. package/lib/util/registerExternalSerializer.js +15 -18
  230. package/lib/util/removeBOM.js +25 -0
  231. package/lib/util/runtime.js +34 -27
  232. package/lib/util/serialization.js +5 -16
  233. package/lib/util/smartGrouping.js +3 -3
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  235. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
  236. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
  237. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
  239. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
  240. package/lib/wasm-sync/WebAssemblyParser.js +9 -4
  241. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
  243. package/package.json +19 -17
  244. package/schemas/WebpackOptions.check.js +1 -1
  245. package/schemas/WebpackOptions.json +48 -13
  246. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
  247. package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
  248. package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
  249. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  250. package/types.d.ts +918 -615
  251. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -12,6 +12,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
12
12
 
13
13
  /** @typedef {import("../../declarations/LoaderContext").LoaderPluginLoaderContext} LoaderPluginLoaderContext */
14
14
  /** @typedef {import("../Compilation").DepConstructor} DepConstructor */
15
+ /** @typedef {import("../Compilation").ExecuteModuleExports} ExecuteModuleExports */
15
16
  /** @typedef {import("../Compilation").ExecuteModuleResult} ExecuteModuleResult */
16
17
  /** @typedef {import("../Compiler")} Compiler */
17
18
  /** @typedef {import("../Module")} Module */
@@ -20,7 +21,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
20
21
  /**
21
22
  * @callback ImportModuleCallback
22
23
  * @param {(Error | null)=} err error object
23
- * @param {any=} exports exports of the evaluated module
24
+ * @param {ExecuteModuleExports=} exports exports of the evaluated module
24
25
  */
25
26
 
26
27
  /**
@@ -31,11 +32,6 @@ const LoaderImportDependency = require("./LoaderImportDependency");
31
32
  */
32
33
 
33
34
  class LoaderPlugin {
34
- /**
35
- * @param {object} options options
36
- */
37
- constructor(options = {}) {}
38
-
39
35
  /**
40
36
  * Apply the plugin
41
37
  * @param {Compiler} compiler the compiler instance
@@ -150,12 +146,7 @@ class LoaderPlugin {
150
146
  for (const d of buildDependencies) {
151
147
  loaderContext.addBuildDependency(d);
152
148
  }
153
- return callback(
154
- null,
155
- source,
156
- /** @type {object | null} */ (map),
157
- referencedModule
158
- );
149
+ return callback(null, source, map, referencedModule);
159
150
  }
160
151
  );
161
152
  };
@@ -271,8 +262,7 @@ class LoaderPlugin {
271
262
  );
272
263
  };
273
264
 
274
- // eslint-disable-next-line no-warning-comments
275
- // @ts-ignore Overloading doesn't work
265
+ // @ts-expect-error overloading doesn't work
276
266
  loaderContext.importModule = (request, options, callback) => {
277
267
  if (!callback) {
278
268
  return new Promise((resolve, reject) => {
@@ -10,10 +10,11 @@ const ContextDependency = require("./ContextDependency");
10
10
  const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
11
11
 
12
12
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
13
+ /** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
13
14
 
14
15
  class RequireContextDependency extends ContextDependency {
15
16
  /**
16
- * @param {TODO} options options
17
+ * @param {ContextDependencyOptions} options options
17
18
  * @param {Range} range range
18
19
  */
19
20
  constructor(options, range) {
@@ -7,6 +7,7 @@
7
7
 
8
8
  const RequireContextDependency = require("./RequireContextDependency");
9
9
 
10
+ /** @typedef {import("../ContextModule").ContextMode} ContextMode */
10
11
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
11
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
12
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
@@ -22,12 +23,13 @@ module.exports = class RequireContextDependencyParserPlugin {
22
23
  .tap("RequireContextDependencyParserPlugin", expr => {
23
24
  let regExp = /^\.\/.*$/;
24
25
  let recursive = true;
26
+ /** @type {ContextMode} */
25
27
  let mode = "sync";
26
28
  switch (expr.arguments.length) {
27
29
  case 4: {
28
30
  const modeExpr = parser.evaluateExpression(expr.arguments[3]);
29
31
  if (!modeExpr.isString()) return;
30
- mode = /** @type {string} */ (modeExpr.string);
32
+ mode = /** @type {ContextMode} */ (modeExpr.string);
31
33
  }
32
34
  // falls through
33
35
  case 3: {
@@ -47,13 +49,14 @@ module.exports = class RequireContextDependencyParserPlugin {
47
49
  if (!requestExpr.isString()) return;
48
50
  const dep = new RequireContextDependency(
49
51
  {
50
- request: requestExpr.string,
52
+ request: /** @type {string} */ (requestExpr.string),
51
53
  recursive,
52
54
  regExp,
53
55
  mode,
54
56
  category: "commonjs"
55
57
  },
56
- /** @type {Range} */ (expr.range)
58
+ /** @type {Range} */
59
+ (expr.range)
57
60
  );
58
61
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
59
62
  dep.optional = Boolean(parser.scope.inTry);
@@ -8,13 +8,14 @@
8
8
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
+ /** @typedef {import("../AsyncDependenciesBlock").GroupOptions} GroupOptions */
11
12
  /** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
12
13
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
13
14
 
14
15
  class RequireEnsureDependenciesBlock extends AsyncDependenciesBlock {
15
16
  /**
16
- * @param {ChunkGroupOptions & { entryOptions?: TODO }} chunkName chunk name
17
- * @param {DependencyLocation} loc location info
17
+ * @param {GroupOptions | null} chunkName chunk name
18
+ * @param {(DependencyLocation | null)=} loc location info
18
19
  */
19
20
  constructor(chunkName, loc) {
20
21
  super(chunkName, loc, null);
@@ -10,6 +10,7 @@ const RequireEnsureDependency = require("./RequireEnsureDependency");
10
10
  const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
11
11
  const getFunctionExpression = require("./getFunctionExpression");
12
12
 
13
+ /** @typedef {import("../AsyncDependenciesBlock").GroupOptions} GroupOptions */
13
14
  /** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
14
15
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
15
16
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
@@ -25,6 +26,7 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
25
26
  parser.hooks.call
26
27
  .for("require.ensure")
27
28
  .tap("RequireEnsureDependenciesBlockParserPlugin", expr => {
29
+ /** @type {string | GroupOptions | null} */
28
30
  let chunkName = null;
29
31
  let errorExpressionArg = null;
30
32
  let errorExpression = null;
@@ -32,7 +34,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
32
34
  case 4: {
33
35
  const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
34
36
  if (!chunkNameExpr.isString()) return;
35
- chunkName = chunkNameExpr.string;
37
+ chunkName =
38
+ /** @type {string} */
39
+ (chunkNameExpr.string);
36
40
  }
37
41
  // falls through
38
42
  case 3: {
@@ -44,7 +48,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
44
48
  expr.arguments[2]
45
49
  );
46
50
  if (!chunkNameExpr.isString()) return;
47
- chunkName = chunkNameExpr.string;
51
+ chunkName =
52
+ /** @type {string} */
53
+ (chunkNameExpr.string);
48
54
  }
49
55
  }
50
56
  // falls through
@@ -70,9 +76,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
70
76
  }
71
77
 
72
78
  const depBlock = new RequireEnsureDependenciesBlock(
73
- /** @type {ChunkGroupOptions & { entryOptions?: TODO }} */
74
- (chunkName),
75
- /** @type {DependencyLocation} */ (expr.loc)
79
+ chunkName,
80
+ /** @type {DependencyLocation} */
81
+ (expr.loc)
76
82
  );
77
83
  const errorCallbackExists =
78
84
  expr.arguments.length === 4 ||
@@ -19,7 +19,7 @@ class RequireResolveContextDependency extends ContextDependency {
19
19
  * @param {ContextDependencyOptions} options options
20
20
  * @param {Range} range range
21
21
  * @param {Range} valueRange value range
22
- * @param {TODO} context context
22
+ * @param {string=} context context
23
23
  */
24
24
  constructor(options, range, valueRange, context) {
25
25
  super(options, context);
@@ -21,7 +21,7 @@ class WebAssemblyExportImportedDependency extends ModuleDependency {
21
21
  * @param {string} exportName export name
22
22
  * @param {string} request request
23
23
  * @param {string} name name
24
- * @param {TODO} valueType value type
24
+ * @param {string} valueType value type
25
25
  */
26
26
  constructor(exportName, request, name, valueType) {
27
27
  super(request);
@@ -30,6 +30,7 @@ class WorkerDependency extends ModuleDependency {
30
30
  * @param {Range} range range
31
31
  * @param {object} workerDependencyOptions options
32
32
  * @param {string=} workerDependencyOptions.publicPath public path for the worker
33
+ * @param {boolean=} workerDependencyOptions.needNewUrl need generate `new URL(...)`
33
34
  */
34
35
  constructor(request, range, workerDependencyOptions) {
35
36
  super(request);
@@ -118,12 +119,14 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
118
119
  runtimeRequirements.add(RuntimeGlobals.baseURI);
119
120
  runtimeRequirements.add(RuntimeGlobals.getChunkScriptFilename);
120
121
 
122
+ const workerImportStr = `/* worker import */ ${workerImportBaseUrl} + ${
123
+ RuntimeGlobals.getChunkScriptFilename
124
+ }(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`;
125
+
121
126
  source.replace(
122
127
  dep.range[0],
123
128
  dep.range[1] - 1,
124
- `/* worker import */ ${workerImportBaseUrl} + ${
125
- RuntimeGlobals.getChunkScriptFilename
126
- }(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`
129
+ dep.options.needNewUrl ? `new URL(${workerImportStr})` : workerImportStr
127
130
  );
128
131
  }
129
132
  };
@@ -27,6 +27,8 @@ const WorkerDependency = require("./WorkerDependency");
27
27
 
28
28
  /** @typedef {import("estree").CallExpression} CallExpression */
29
29
  /** @typedef {import("estree").Expression} Expression */
30
+ /** @typedef {import("estree").Identifier} Identifier */
31
+ /** @typedef {import("estree").MemberExpression} MemberExpression */
30
32
  /** @typedef {import("estree").ObjectExpression} ObjectExpression */
31
33
  /** @typedef {import("estree").Pattern} Pattern */
32
34
  /** @typedef {import("estree").Property} Property */
@@ -117,45 +119,81 @@ class WorkerPlugin {
117
119
  /**
118
120
  * @param {JavascriptParser} parser the parser
119
121
  * @param {Expression} expr expression
120
- * @returns {[BasicEvaluatedExpression, [number, number]] | void} parsed
122
+ * @returns {[string, [number, number]] | void} parsed
121
123
  */
122
124
  const parseModuleUrl = (parser, expr) => {
123
- if (
124
- expr.type !== "NewExpression" ||
125
- expr.callee.type === "Super" ||
126
- expr.arguments.length !== 2
127
- )
125
+ if (expr.type !== "NewExpression" || expr.callee.type === "Super")
128
126
  return;
129
- const [arg1, arg2] = expr.arguments;
130
- if (arg1.type === "SpreadElement") return;
131
- if (arg2.type === "SpreadElement") return;
132
- const callee = parser.evaluateExpression(expr.callee);
133
- if (!callee.isIdentifier() || callee.identifier !== "URL") return;
134
- const arg2Value = parser.evaluateExpression(arg2);
135
127
  if (
136
- !arg2Value.isString() ||
137
- !(/** @type {string} */ (arg2Value.string).startsWith("file://")) ||
138
- arg2Value.string !== getUrl(parser.state.module)
128
+ expr.arguments.length === 1 &&
129
+ expr.arguments[0].type === "MemberExpression" &&
130
+ isMetaUrl(parser, expr.arguments[0])
139
131
  ) {
140
- return;
132
+ const arg1 = expr.arguments[0];
133
+ return [
134
+ getUrl(parser.state.module),
135
+ [
136
+ /** @type {Range} */ (arg1.range)[0],
137
+ /** @type {Range} */ (arg1.range)[1]
138
+ ]
139
+ ];
140
+ } else if (expr.arguments.length === 2) {
141
+ const [arg1, arg2] = expr.arguments;
142
+ if (arg1.type === "SpreadElement") return;
143
+ if (arg2.type === "SpreadElement") return;
144
+ const callee = parser.evaluateExpression(expr.callee);
145
+ if (!callee.isIdentifier() || callee.identifier !== "URL") return;
146
+ const arg2Value = parser.evaluateExpression(arg2);
147
+ if (
148
+ !arg2Value.isString() ||
149
+ !(
150
+ /** @type {string} */ (arg2Value.string).startsWith("file://")
151
+ ) ||
152
+ arg2Value.string !== getUrl(parser.state.module)
153
+ ) {
154
+ return;
155
+ }
156
+ const arg1Value = parser.evaluateExpression(arg1);
157
+ if (!arg1Value.isString()) return;
158
+ return [
159
+ /** @type {string} */ (arg1Value.string),
160
+ [
161
+ /** @type {Range} */ (arg1.range)[0],
162
+ /** @type {Range} */ (arg2.range)[1]
163
+ ]
164
+ ];
141
165
  }
142
- const arg1Value = parser.evaluateExpression(arg1);
143
- return [
144
- arg1Value,
145
- [
146
- /** @type {Range} */ (arg1.range)[0],
147
- /** @type {Range} */ (arg2.range)[1]
148
- ]
149
- ];
150
166
  };
151
167
 
168
+ /**
169
+ * @param {JavascriptParser} parser the parser
170
+ * @param {MemberExpression} expr expression
171
+ * @returns {boolean} is `import.meta.url`
172
+ */
173
+ const isMetaUrl = (parser, expr) => {
174
+ const chain = parser.extractMemberExpressionChain(expr);
175
+
176
+ if (
177
+ chain.members.length !== 1 ||
178
+ chain.object.type !== "MetaProperty" ||
179
+ chain.object.meta.name !== "import" ||
180
+ chain.object.property.name !== "meta" ||
181
+ chain.members[0] !== "url"
182
+ )
183
+ return false;
184
+
185
+ return true;
186
+ };
187
+
188
+ /** @typedef {Record<string, EXPECTED_ANY>} Values */
189
+
152
190
  /**
153
191
  * @param {JavascriptParser} parser the parser
154
192
  * @param {ObjectExpression} expr expression
155
- * @returns {{ expressions: Record<string, Expression | Pattern>, otherElements: (Property | SpreadElement)[], values: Record<string, any>, spread: boolean, insertType: "comma" | "single", insertLocation: number }} parsed object
193
+ * @returns {{ expressions: Record<string, Expression | Pattern>, otherElements: (Property | SpreadElement)[], values: Values, spread: boolean, insertType: "comma" | "single", insertLocation: number }} parsed object
156
194
  */
157
195
  const parseObjectExpression = (parser, expr) => {
158
- /** @type {Record<string, any>} */
196
+ /** @type {Values} */
159
197
  const values = {};
160
198
  /** @type {Record<string, Expression | Pattern>} */
161
199
  const expressions = {};
@@ -174,7 +212,8 @@ class WorkerPlugin {
174
212
  expressions[prop.key.name] = prop.value;
175
213
  if (!prop.shorthand && !prop.value.type.endsWith("Pattern")) {
176
214
  const value = parser.evaluateExpression(
177
- /** @type {Expression} */ (prop.value)
215
+ /** @type {Expression} */
216
+ (prop.value)
178
217
  );
179
218
  if (value.isCompileTimeValue())
180
219
  values[prop.key.name] = value.asCompileTimeValue();
@@ -217,10 +256,27 @@ class WorkerPlugin {
217
256
  const [arg1, arg2] = expr.arguments;
218
257
  if (arg1.type === "SpreadElement") return;
219
258
  if (arg2 && arg2.type === "SpreadElement") return;
220
- const parsedUrl = parseModuleUrl(parser, arg1);
221
- if (!parsedUrl) return;
222
- const [url, range] = parsedUrl;
223
- if (!url.isString()) return;
259
+
260
+ /** @type {string} */
261
+ let url;
262
+ /** @type {[number, number]} */
263
+ let range;
264
+ /** @type {boolean} */
265
+ let needNewUrl = false;
266
+
267
+ if (arg1.type === "MemberExpression" && isMetaUrl(parser, arg1)) {
268
+ url = getUrl(parser.state.module);
269
+ range = [
270
+ /** @type {Range} */ (arg1.range)[0],
271
+ /** @type {Range} */ (arg1.range)[1]
272
+ ];
273
+ needNewUrl = true;
274
+ } else {
275
+ const parsedUrl = parseModuleUrl(parser, arg1);
276
+ if (!parsedUrl) return;
277
+ [url, range] = parsedUrl;
278
+ }
279
+
224
280
  const {
225
281
  expressions,
226
282
  otherElements,
@@ -234,7 +290,7 @@ class WorkerPlugin {
234
290
  /** @type {Record<string, Expression | Pattern>} */
235
291
  expressions: {},
236
292
  otherElements: [],
237
- /** @type {Record<string, any>} */
293
+ /** @type {Values} */
238
294
  values: {},
239
295
  spread: false,
240
296
  insertType: arg2 ? "spread" : "argument",
@@ -342,13 +398,10 @@ class WorkerPlugin {
342
398
  }
343
399
  });
344
400
  block.loc = expr.loc;
345
- const dep = new WorkerDependency(
346
- /** @type {string} */ (url.string),
347
- range,
348
- {
349
- publicPath: this._workerPublicPath
350
- }
351
- );
401
+ const dep = new WorkerDependency(url, range, {
402
+ publicPath: this._workerPublicPath,
403
+ needNewUrl
404
+ });
352
405
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
353
406
  block.addDependency(dep);
354
407
  parser.state.module.addBlock(block);
@@ -370,7 +423,7 @@ class WorkerPlugin {
370
423
  );
371
424
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
372
425
  parser.state.module.addPresentationalDependency(dep);
373
- /** @type {TODO} */
426
+ /** @type {EXPECTED_ANY} */
374
427
  (expressions).type = undefined;
375
428
  }
376
429
  } else if (insertType === "comma") {
@@ -406,7 +459,13 @@ class WorkerPlugin {
406
459
 
407
460
  parser.walkExpression(expr.callee);
408
461
  for (const key of Object.keys(expressions)) {
409
- if (expressions[key]) parser.walkExpression(expressions[key]);
462
+ if (expressions[key]) {
463
+ if (expressions[key].type.endsWith("Pattern")) continue;
464
+ parser.walkExpression(
465
+ /** @type {Expression} */
466
+ (expressions[key])
467
+ );
468
+ }
410
469
  }
411
470
  for (const prop of otherElements) {
412
471
  parser.walkProperty(prop);
@@ -151,6 +151,11 @@ class ModuleChunkFormatPlugin {
151
151
  let index = 0;
152
152
  for (let i = 0; i < entries.length; i++) {
153
153
  const [module, entrypoint] = entries[i];
154
+ if (
155
+ !chunkGraph.getModuleSourceTypes(module).has("javascript")
156
+ ) {
157
+ continue;
158
+ }
154
159
  const final = i + 1 === entries.length;
155
160
  const moduleId = chunkGraph.getModuleId(module);
156
161
  const chunks = getAllChunks(
@@ -69,6 +69,7 @@ module.exports = function () {
69
69
  me.children.push(request);
70
70
  }
71
71
  } else {
72
+ // eslint-disable-next-line no-console
72
73
  console.warn(
73
74
  "[HMR] unexpected require(" +
74
75
  request +
@@ -109,6 +109,7 @@ module.exports = function () {
109
109
  var appliedUpdate = {};
110
110
 
111
111
  var warnUnexpectedRequire = function warnUnexpectedRequire(module) {
112
+ // eslint-disable-next-line no-console
112
113
  console.warn(
113
114
  "[HMR] unexpected require(" + module.id + ") to disposed module"
114
115
  );
@@ -23,14 +23,16 @@ const { registerNotSerializable } = require("../util/serialization");
23
23
  /** @typedef {import("../Compilation")} Compilation */
24
24
  /** @typedef {import("../Compiler")} Compiler */
25
25
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
26
+ /** @typedef {import("../Module").BuildCallback} BuildCallback */
26
27
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
27
28
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
28
29
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
29
30
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
31
+ /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
30
32
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
31
33
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
34
+ /** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
32
35
  /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
33
- /** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
34
36
  /** @typedef {import("../RequestShortener")} RequestShortener */
35
37
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
36
38
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -42,8 +44,8 @@ const { registerNotSerializable } = require("../util/serialization");
42
44
 
43
45
  /**
44
46
  * @typedef {object} BackendApi
45
- * @property {function(function((Error | null)=) : void): void} dispose
46
- * @property {function(Module): ModuleResult} module
47
+ * @property {(callback: (err?: (Error | null)) => void) => void} dispose
48
+ * @property {(module: Module) => ModuleResult} module
47
49
  */
48
50
 
49
51
  const HMR_DEPENDENCY_TYPES = new Set([
@@ -54,7 +56,7 @@ const HMR_DEPENDENCY_TYPES = new Set([
54
56
  ]);
55
57
 
56
58
  /**
57
- * @param {undefined|string|RegExp|Function} test test option
59
+ * @param {Options["test"]} test test option
58
60
  * @param {Module} module the module
59
61
  * @returns {boolean | null | string} true, if the module should be selected
60
62
  */
@@ -169,7 +171,7 @@ class LazyCompilationProxyModule extends Module {
169
171
 
170
172
  /**
171
173
  * @param {NeedBuildContext} context context info
172
- * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
174
+ * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
173
175
  * @returns {void}
174
176
  */
175
177
  needBuild(context, callback) {
@@ -181,7 +183,7 @@ class LazyCompilationProxyModule extends Module {
181
183
  * @param {Compilation} compilation the compilation
182
184
  * @param {ResolverWithOptions} resolver the resolver
183
185
  * @param {InputFileSystem} fs the file system
184
- * @param {function(WebpackError=): void} callback callback function
186
+ * @param {BuildCallback} callback callback function
185
187
  * @returns {void}
186
188
  */
187
189
  build(options, compilation, resolver, fs, callback) {
@@ -315,13 +317,13 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
315
317
 
316
318
  /**
317
319
  * @param {ModuleFactoryCreateData} data data object
318
- * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
320
+ * @param {ModuleFactoryCallback} callback callback
319
321
  * @returns {void}
320
322
  */
321
323
  create(data, callback) {
322
- const dependency = /** @type {LazyCompilationDependency} */ (
323
- data.dependencies[0]
324
- );
324
+ const dependency =
325
+ /** @type {LazyCompilationDependency} */
326
+ (data.dependencies[0]);
325
327
  callback(null, {
326
328
  module: dependency.proxyModule.originalModule
327
329
  });
@@ -331,7 +333,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
331
333
  /**
332
334
  * @callback BackendHandler
333
335
  * @param {Compiler} compiler compiler
334
- * @param {function(Error | null, BackendApi=): void} callback callback
336
+ * @param {(err: Error | null, backendApi?: BackendApi) => void} callback callback
335
337
  * @returns {void}
336
338
  */
337
339
 
@@ -341,13 +343,19 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
341
343
  * @returns {Promise<BackendApi>} backend
342
344
  */
343
345
 
346
+ /** @typedef {BackendHandler | PromiseBackendHandler} BackEnd */
347
+
348
+ /**
349
+ * @typedef {object} Options options
350
+ * @property {BackEnd} backend the backend
351
+ * @property {boolean=} entries
352
+ * @property {boolean=} imports
353
+ * @property {(RegExp | string | ((module: Module) => boolean))=} test additional filter for lazy compiled entrypoint modules
354
+ */
355
+
344
356
  class LazyCompilationPlugin {
345
357
  /**
346
- * @param {object} options options
347
- * @param {BackendHandler | PromiseBackendHandler} options.backend the backend
348
- * @param {boolean} options.entries true, when entries are lazy compiled
349
- * @param {boolean} options.imports true, when import() modules are lazy compiled
350
- * @param {RegExp | string | (function(Module): boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules
358
+ * @param {Options} options options
351
359
  */
352
360
  constructor({ backend, entries, imports, test }) {
353
361
  this.backend = backend;
@@ -386,7 +394,7 @@ class LazyCompilationPlugin {
386
394
  (compilation, { normalModuleFactory }) => {
387
395
  normalModuleFactory.hooks.module.tap(
388
396
  "LazyCompilationPlugin",
389
- (originalModule, createData, resolveData) => {
397
+ (module, createData, resolveData) => {
390
398
  if (
391
399
  resolveData.dependencies.every(dep =>
392
400
  HMR_DEPENDENCY_TYPES.has(dep.type)
@@ -407,7 +415,7 @@ class LazyCompilationPlugin {
407
415
  hmrDep.request
408
416
  )
409
417
  );
410
- if (!isReferringToDynamicImport) return;
418
+ if (!isReferringToDynamicImport) return module;
411
419
  } else if (
412
420
  !resolveData.dependencies.every(
413
421
  dep =>
@@ -418,21 +426,21 @@ class LazyCompilationPlugin {
418
426
  (this.entries && dep.type === "entry")
419
427
  )
420
428
  )
421
- return;
429
+ return module;
422
430
  if (
423
431
  /webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client|webpack-hot-middleware[/\\]client/.test(
424
432
  resolveData.request
425
433
  ) ||
426
- !checkTest(this.test, originalModule)
434
+ !checkTest(this.test, module)
427
435
  )
428
- return;
429
- const moduleInfo = backend.module(originalModule);
430
- if (!moduleInfo) return;
436
+ return module;
437
+ const moduleInfo = backend.module(module);
438
+ if (!moduleInfo) return module;
431
439
  const { client, data, active } = moduleInfo;
432
440
 
433
441
  return new LazyCompilationProxyModule(
434
442
  compiler.context,
435
- originalModule,
443
+ module,
436
444
  resolveData.request,
437
445
  client,
438
446
  data,
@@ -43,7 +43,7 @@ module.exports = options => (compiler, callback) => {
43
43
  (options.server)
44
44
  );
45
45
  })();
46
- /** @type {function(Server): void} */
46
+ /** @type {(server: Server) => void} */
47
47
  const listen =
48
48
  typeof options.listen === "function"
49
49
  ? options.listen
@@ -20,7 +20,7 @@ const {
20
20
  /**
21
21
  * @typedef {object} DeterministicModuleIdsPluginOptions
22
22
  * @property {string=} context context relative to which module identifiers are computed
23
- * @property {function(Module): boolean=} test selector function for modules
23
+ * @property {((module: Module) => boolean)=} test selector function for modules
24
24
  * @property {number=} maxLength maximum id length in digits (used as starting point)
25
25
  * @property {number=} salt hash salt for ids
26
26
  * @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { DEFAULTS } = require("../config/defaults");
8
9
  const {
9
10
  compareModulesByPreOrderIndexOrIdentifier
10
11
  } = require("../util/comparators");
@@ -37,7 +38,7 @@ class HashedModuleIdsPlugin {
37
38
  /** @type {HashedModuleIdsPluginOptions} */
38
39
  this.options = {
39
40
  context: undefined,
40
- hashFunction: "md4",
41
+ hashFunction: DEFAULTS.HASH_FUNCTION,
41
42
  hashDigest: "base64",
42
43
  hashDigestLength: 4,
43
44
  ...options