webpack 5.99.6 → 5.99.8

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 (219) hide show
  1. package/lib/AutomaticPrefetchPlugin.js +21 -22
  2. package/lib/BannerPlugin.js +31 -35
  3. package/lib/CleanPlugin.js +5 -3
  4. package/lib/Compilation.js +21 -15
  5. package/lib/Compiler.js +2 -1
  6. package/lib/ContextExclusionPlugin.js +4 -2
  7. package/lib/ContextModule.js +1 -1
  8. package/lib/ContextModuleFactory.js +1 -2
  9. package/lib/ContextReplacementPlugin.js +7 -4
  10. package/lib/DefinePlugin.js +2 -2
  11. package/lib/DelegatedModule.js +18 -8
  12. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +138 -139
  23. package/lib/ExportsInfo.js +35 -16
  24. package/lib/ExternalModule.js +6 -5
  25. package/lib/ExternalsPlugin.js +3 -1
  26. package/lib/FileSystemInfo.js +2 -2
  27. package/lib/FlagDependencyExportsPlugin.js +2 -1
  28. package/lib/IgnorePlugin.js +6 -4
  29. package/lib/IgnoreWarningsPlugin.js +4 -2
  30. package/lib/LibManifestPlugin.js +5 -6
  31. package/lib/LoaderOptionsPlugin.js +4 -2
  32. package/lib/LoaderTargetPlugin.js +4 -2
  33. package/lib/Module.js +19 -12
  34. package/lib/ModuleFilenameHelpers.js +8 -4
  35. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  36. package/lib/MultiCompiler.js +5 -3
  37. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  38. package/lib/NormalModule.js +13 -8
  39. package/lib/NormalModuleReplacementPlugin.js +33 -36
  40. package/lib/PlatformPlugin.js +3 -1
  41. package/lib/PrefetchPlugin.js +4 -2
  42. package/lib/ProgressPlugin.js +23 -26
  43. package/lib/RecordIdsPlugin.js +72 -102
  44. package/lib/RuntimePlugin.js +34 -32
  45. package/lib/SourceMapDevToolPlugin.js +9 -8
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +6 -7
  51. package/lib/asset/AssetGenerator.js +2 -2
  52. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  53. package/lib/cache/IdleFileCachePlugin.js +11 -12
  54. package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
  55. package/lib/cache/ResolverCachePlugin.js +8 -6
  56. package/lib/cli.js +5 -1
  57. package/lib/config/defaults.js +10 -6
  58. package/lib/config/normalization.js +14 -8
  59. package/lib/container/ContainerReferencePlugin.js +24 -26
  60. package/lib/container/ModuleFederationPlugin.js +2 -1
  61. package/lib/css/CssGenerator.js +1 -1
  62. package/lib/css/CssModulesPlugin.js +8 -6
  63. package/lib/debug/ProfilingPlugin.js +18 -21
  64. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  65. package/lib/dependencies/ContextElementDependency.js +1 -1
  66. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  68. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  69. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  70. package/lib/dependencies/LoaderPlugin.js +5 -3
  71. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  72. package/lib/dependencies/RequireContextPlugin.js +2 -1
  73. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  74. package/lib/dependencies/WorkerPlugin.js +2 -2
  75. package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
  76. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  77. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
  78. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  79. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  80. package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
  81. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  82. package/lib/ids/NamedChunkIdsPlugin.js +4 -2
  83. package/lib/ids/NamedModuleIdsPlugin.js +4 -2
  84. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  85. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  86. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  87. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  88. package/lib/index.js +11 -0
  89. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  90. package/lib/javascript/JavascriptParser.js +634 -656
  91. package/lib/json/JsonModulesPlugin.js +4 -4
  92. package/lib/library/AbstractLibraryPlugin.js +1 -1
  93. package/lib/library/ModuleLibraryPlugin.js +60 -42
  94. package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
  95. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  96. package/lib/node/nodeConsole.js +3 -2
  97. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  98. package/lib/optimize/ConcatenatedModule.js +15 -16
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  100. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  101. package/lib/optimize/MangleExportsPlugin.js +15 -16
  102. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  103. package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
  104. package/lib/optimize/RealContentHashPlugin.js +4 -2
  105. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  106. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  107. package/lib/optimize/RuntimeChunkPlugin.js +21 -23
  108. package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
  109. package/lib/optimize/SplitChunksPlugin.js +9 -7
  110. package/lib/performance/SizeLimitsPlugin.js +3 -1
  111. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  112. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  113. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  114. package/lib/rules/RuleSetCompiler.js +19 -5
  115. package/lib/rules/UseEffectRulePlugin.js +4 -6
  116. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  117. package/lib/schemes/DataUriPlugin.js +5 -3
  118. package/lib/schemes/FileUriPlugin.js +5 -3
  119. package/lib/schemes/HttpUriPlugin.js +186 -188
  120. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  121. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  122. package/lib/serialization/ObjectMiddleware.js +13 -0
  123. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  124. package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
  125. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  126. package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
  127. package/lib/util/concatenate.js +4 -2
  128. package/lib/util/createHash.js +3 -3
  129. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  130. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  131. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  132. package/package.json +35 -30
  133. package/schemas/WebpackOptions.check.d.ts +1 -1
  134. package/schemas/WebpackOptions.check.js +2 -2
  135. package/schemas/WebpackOptions.json +267 -26
  136. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  137. package/schemas/plugins/BannerPlugin.check.js +1 -1
  138. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  139. package/schemas/plugins/DllPlugin.check.js +1 -1
  140. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  141. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  142. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  143. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  144. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  145. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  146. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  147. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  148. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  149. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  150. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  151. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  152. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  153. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  154. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  155. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  156. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  157. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  158. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  159. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  160. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  161. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  162. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  163. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  164. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  165. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  166. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  167. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  168. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  169. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  170. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  171. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  172. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  174. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  175. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  176. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  177. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  178. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  180. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  182. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  183. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  186. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  187. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  188. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  189. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  190. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  191. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  192. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  193. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  194. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  195. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  196. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  197. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  198. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  199. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  200. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  201. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  202. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  203. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  204. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  209. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  210. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  211. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  212. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  213. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  214. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  215. package/types.d.ts +587 -207
  216. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  217. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  218. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  219. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -12,27 +12,27 @@ const HarmonyExports = require("./HarmonyExports");
12
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
14
 
15
+ const PLUGIN_NAME = "HarmonyTopLevelThisParserPlugin";
16
+
15
17
  class HarmonyTopLevelThisParserPlugin {
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @returns {void}
19
21
  */
20
22
  apply(parser) {
21
- parser.hooks.expression
22
- .for("this")
23
- .tap("HarmonyTopLevelThisParserPlugin", node => {
24
- if (!parser.scope.topLevelScope) return;
25
- if (HarmonyExports.isEnabled(parser.state)) {
26
- const dep = new ConstDependency(
27
- "undefined",
28
- /** @type {Range} */ (node.range),
29
- null
30
- );
31
- dep.loc = /** @type {DependencyLocation} */ (node.loc);
32
- parser.state.module.addPresentationalDependency(dep);
33
- return true;
34
- }
35
- });
23
+ parser.hooks.expression.for("this").tap(PLUGIN_NAME, node => {
24
+ if (!parser.scope.topLevelScope) return;
25
+ if (HarmonyExports.isEnabled(parser.state)) {
26
+ const dep = new ConstDependency(
27
+ "undefined",
28
+ /** @type {Range} */ (node.range),
29
+ null
30
+ );
31
+ dep.loc = /** @type {DependencyLocation} */ (node.loc);
32
+ parser.state.module.addPresentationalDependency(dep);
33
+ return true;
34
+ }
35
+ });
36
36
  }
37
37
  }
38
38
 
@@ -52,6 +52,8 @@ function createError(msg, loc) {
52
52
  return error;
53
53
  }
54
54
 
55
+ const PLUGIN_NAME = "ImportMetaContextDependencyParserPlugin";
56
+
55
57
  module.exports = class ImportMetaContextDependencyParserPlugin {
56
58
  /**
57
59
  * @param {JavascriptParser} parser the parser
@@ -60,7 +62,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
60
62
  apply(parser) {
61
63
  parser.hooks.evaluateIdentifier
62
64
  .for("import.meta.webpackContext")
63
- .tap("ImportMetaContextDependencyParserPlugin", expr =>
65
+ .tap(PLUGIN_NAME, expr =>
64
66
  evaluateToIdentifier(
65
67
  "import.meta.webpackContext",
66
68
  "import.meta",
@@ -70,7 +72,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
70
72
  );
71
73
  parser.hooks.call
72
74
  .for("import.meta.webpackContext")
73
- .tap("ImportMetaContextDependencyParserPlugin", expr => {
75
+ .tap(PLUGIN_NAME, expr => {
74
76
  if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
75
77
  const [directoryNode, optionsNode] = expr.arguments;
76
78
  if (optionsNode && optionsNode.type !== "ObjectExpression") return;
@@ -31,6 +31,8 @@ const LoaderImportDependency = require("./LoaderImportDependency");
31
31
  * @property {string=} baseUri target base uri
32
32
  */
33
33
 
34
+ const PLUGIN_NAME = "LoaderPlugin";
35
+
34
36
  class LoaderPlugin {
35
37
  /**
36
38
  * Apply the plugin
@@ -39,7 +41,7 @@ class LoaderPlugin {
39
41
  */
40
42
  apply(compiler) {
41
43
  compiler.hooks.compilation.tap(
42
- "LoaderPlugin",
44
+ PLUGIN_NAME,
43
45
  (compilation, { normalModuleFactory }) => {
44
46
  compilation.dependencyFactories.set(
45
47
  LoaderDependency,
@@ -52,10 +54,10 @@ class LoaderPlugin {
52
54
  }
53
55
  );
54
56
 
55
- compiler.hooks.compilation.tap("LoaderPlugin", compilation => {
57
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
56
58
  const moduleGraph = compilation.moduleGraph;
57
59
  NormalModule.getCompilationHooks(compilation).loader.tap(
58
- "LoaderPlugin",
60
+ PLUGIN_NAME,
59
61
  loaderContext => {
60
62
  loaderContext.loadModule = (request, callback) => {
61
63
  const dep = new LoaderDependency(request);
@@ -12,58 +12,58 @@ const RequireContextDependency = require("./RequireContextDependency");
12
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
14
 
15
+ const PLUGIN_NAME = "RequireContextDependencyParserPlugin";
16
+
15
17
  module.exports = class RequireContextDependencyParserPlugin {
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @returns {void}
19
21
  */
20
22
  apply(parser) {
21
- parser.hooks.call
22
- .for("require.context")
23
- .tap("RequireContextDependencyParserPlugin", expr => {
24
- let regExp = /^\.\/.*$/;
25
- let recursive = true;
26
- /** @type {ContextMode} */
27
- let mode = "sync";
28
- switch (expr.arguments.length) {
29
- case 4: {
30
- const modeExpr = parser.evaluateExpression(expr.arguments[3]);
31
- if (!modeExpr.isString()) return;
32
- mode = /** @type {ContextMode} */ (modeExpr.string);
33
- }
34
- // falls through
35
- case 3: {
36
- const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
37
- if (!regExpExpr.isRegExp()) return;
38
- regExp = /** @type {RegExp} */ (regExpExpr.regExp);
39
- }
40
- // falls through
41
- case 2: {
42
- const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
43
- if (!recursiveExpr.isBoolean()) return;
44
- recursive = /** @type {boolean} */ (recursiveExpr.bool);
45
- }
46
- // falls through
47
- case 1: {
48
- const requestExpr = parser.evaluateExpression(expr.arguments[0]);
49
- if (!requestExpr.isString()) return;
50
- const dep = new RequireContextDependency(
51
- {
52
- request: /** @type {string} */ (requestExpr.string),
53
- recursive,
54
- regExp,
55
- mode,
56
- category: "commonjs"
57
- },
58
- /** @type {Range} */
59
- (expr.range)
60
- );
61
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
62
- dep.optional = Boolean(parser.scope.inTry);
63
- parser.state.current.addDependency(dep);
64
- return true;
65
- }
23
+ parser.hooks.call.for("require.context").tap(PLUGIN_NAME, expr => {
24
+ let regExp = /^\.\/.*$/;
25
+ let recursive = true;
26
+ /** @type {ContextMode} */
27
+ let mode = "sync";
28
+ switch (expr.arguments.length) {
29
+ case 4: {
30
+ const modeExpr = parser.evaluateExpression(expr.arguments[3]);
31
+ if (!modeExpr.isString()) return;
32
+ mode = /** @type {ContextMode} */ (modeExpr.string);
33
+ }
34
+ // falls through
35
+ case 3: {
36
+ const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
37
+ if (!regExpExpr.isRegExp()) return;
38
+ regExp = /** @type {RegExp} */ (regExpExpr.regExp);
39
+ }
40
+ // falls through
41
+ case 2: {
42
+ const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
43
+ if (!recursiveExpr.isBoolean()) return;
44
+ recursive = /** @type {boolean} */ (recursiveExpr.bool);
45
+ }
46
+ // falls through
47
+ case 1: {
48
+ const requestExpr = parser.evaluateExpression(expr.arguments[0]);
49
+ if (!requestExpr.isString()) return;
50
+ const dep = new RequireContextDependency(
51
+ {
52
+ request: /** @type {string} */ (requestExpr.string),
53
+ recursive,
54
+ regExp,
55
+ mode,
56
+ category: "commonjs"
57
+ },
58
+ /** @type {Range} */
59
+ (expr.range)
60
+ );
61
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
62
+ dep.optional = Boolean(parser.scope.inTry);
63
+ parser.state.current.addDependency(dep);
64
+ return true;
66
65
  }
67
- });
66
+ }
67
+ });
68
68
  }
69
69
  };
@@ -80,7 +80,8 @@ class RequireContextPlugin {
80
80
  cachedSetProperty(
81
81
  options.resolveOptions || EMPTY_RESOLVE_OPTIONS,
82
82
  "dependencyType",
83
- /** @type {string} */ (options.category)
83
+ /** @type {string} */
84
+ (options.category)
84
85
  )
85
86
  ).options;
86
87
 
@@ -17,128 +17,122 @@ const getFunctionExpression = require("./getFunctionExpression");
17
17
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
18
18
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
19
 
20
+ const PLUGIN_NAME = "RequireEnsureDependenciesBlockParserPlugin";
21
+
20
22
  module.exports = class RequireEnsureDependenciesBlockParserPlugin {
21
23
  /**
22
24
  * @param {JavascriptParser} parser the parser
23
25
  * @returns {void}
24
26
  */
25
27
  apply(parser) {
26
- parser.hooks.call
27
- .for("require.ensure")
28
- .tap("RequireEnsureDependenciesBlockParserPlugin", expr => {
29
- /** @type {string | GroupOptions | null} */
30
- let chunkName = null;
31
- let errorExpressionArg = null;
32
- let errorExpression = null;
33
- switch (expr.arguments.length) {
34
- case 4: {
35
- const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
28
+ parser.hooks.call.for("require.ensure").tap(PLUGIN_NAME, expr => {
29
+ /** @type {string | GroupOptions | null} */
30
+ let chunkName = null;
31
+ let errorExpressionArg = null;
32
+ let errorExpression = null;
33
+ switch (expr.arguments.length) {
34
+ case 4: {
35
+ const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
36
+ if (!chunkNameExpr.isString()) return;
37
+ chunkName =
38
+ /** @type {string} */
39
+ (chunkNameExpr.string);
40
+ }
41
+ // falls through
42
+ case 3: {
43
+ errorExpressionArg = expr.arguments[2];
44
+ errorExpression = getFunctionExpression(errorExpressionArg);
45
+
46
+ if (!errorExpression && !chunkName) {
47
+ const chunkNameExpr = parser.evaluateExpression(expr.arguments[2]);
36
48
  if (!chunkNameExpr.isString()) return;
37
49
  chunkName =
38
50
  /** @type {string} */
39
51
  (chunkNameExpr.string);
40
52
  }
41
- // falls through
42
- case 3: {
43
- errorExpressionArg = expr.arguments[2];
44
- errorExpression = getFunctionExpression(errorExpressionArg);
53
+ }
54
+ // falls through
55
+ case 2: {
56
+ const dependenciesExpr = parser.evaluateExpression(expr.arguments[0]);
57
+ const dependenciesItems = /** @type {BasicEvaluatedExpression[]} */ (
58
+ dependenciesExpr.isArray()
59
+ ? dependenciesExpr.items
60
+ : [dependenciesExpr]
61
+ );
62
+ const successExpressionArg = expr.arguments[1];
63
+ const successExpression = getFunctionExpression(successExpressionArg);
45
64
 
46
- if (!errorExpression && !chunkName) {
47
- const chunkNameExpr = parser.evaluateExpression(
48
- expr.arguments[2]
49
- );
50
- if (!chunkNameExpr.isString()) return;
51
- chunkName =
52
- /** @type {string} */
53
- (chunkNameExpr.string);
54
- }
65
+ if (successExpression) {
66
+ parser.walkExpressions(successExpression.expressions);
67
+ }
68
+ if (errorExpression) {
69
+ parser.walkExpressions(errorExpression.expressions);
55
70
  }
56
- // falls through
57
- case 2: {
58
- const dependenciesExpr = parser.evaluateExpression(
59
- expr.arguments[0]
60
- );
61
- const dependenciesItems =
62
- /** @type {BasicEvaluatedExpression[]} */ (
63
- dependenciesExpr.isArray()
64
- ? dependenciesExpr.items
65
- : [dependenciesExpr]
66
- );
67
- const successExpressionArg = expr.arguments[1];
68
- const successExpression =
69
- getFunctionExpression(successExpressionArg);
70
-
71
- if (successExpression) {
72
- parser.walkExpressions(successExpression.expressions);
73
- }
74
- if (errorExpression) {
75
- parser.walkExpressions(errorExpression.expressions);
76
- }
77
71
 
78
- const depBlock = new RequireEnsureDependenciesBlock(
79
- chunkName,
80
- /** @type {DependencyLocation} */
81
- (expr.loc)
82
- );
83
- const errorCallbackExists =
84
- expr.arguments.length === 4 ||
85
- (!chunkName && expr.arguments.length === 3);
86
- const dep = new RequireEnsureDependency(
87
- /** @type {Range} */ (expr.range),
88
- /** @type {Range} */ (expr.arguments[1].range),
89
- errorCallbackExists &&
90
- /** @type {Range} */ (expr.arguments[2].range)
91
- );
92
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
93
- depBlock.addDependency(dep);
94
- const old = parser.state.current;
95
- parser.state.current = /** @type {TODO} */ (depBlock);
96
- try {
97
- let failed = false;
98
- parser.inScope([], () => {
99
- for (const ee of dependenciesItems) {
100
- if (ee.isString()) {
101
- const ensureDependency = new RequireEnsureItemDependency(
102
- /** @type {string} */ (ee.string)
103
- );
104
- ensureDependency.loc =
105
- /** @type {DependencyLocation} */
106
- (expr.loc);
107
- depBlock.addDependency(ensureDependency);
108
- } else {
109
- failed = true;
110
- }
111
- }
112
- });
113
- if (failed) {
114
- return;
115
- }
116
- if (successExpression) {
117
- if (successExpression.fn.body.type === "BlockStatement") {
118
- parser.walkStatement(successExpression.fn.body);
72
+ const depBlock = new RequireEnsureDependenciesBlock(
73
+ chunkName,
74
+ /** @type {DependencyLocation} */
75
+ (expr.loc)
76
+ );
77
+ const errorCallbackExists =
78
+ expr.arguments.length === 4 ||
79
+ (!chunkName && expr.arguments.length === 3);
80
+ const dep = new RequireEnsureDependency(
81
+ /** @type {Range} */ (expr.range),
82
+ /** @type {Range} */ (expr.arguments[1].range),
83
+ errorCallbackExists &&
84
+ /** @type {Range} */ (expr.arguments[2].range)
85
+ );
86
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
87
+ depBlock.addDependency(dep);
88
+ const old = parser.state.current;
89
+ parser.state.current = /** @type {TODO} */ (depBlock);
90
+ try {
91
+ let failed = false;
92
+ parser.inScope([], () => {
93
+ for (const ee of dependenciesItems) {
94
+ if (ee.isString()) {
95
+ const ensureDependency = new RequireEnsureItemDependency(
96
+ /** @type {string} */ (ee.string)
97
+ );
98
+ ensureDependency.loc =
99
+ /** @type {DependencyLocation} */
100
+ (expr.loc);
101
+ depBlock.addDependency(ensureDependency);
119
102
  } else {
120
- parser.walkExpression(successExpression.fn.body);
103
+ failed = true;
121
104
  }
122
105
  }
123
- old.addBlock(depBlock);
124
- } finally {
125
- parser.state.current = old;
126
- }
127
- if (!successExpression) {
128
- parser.walkExpression(successExpressionArg);
106
+ });
107
+ if (failed) {
108
+ return;
129
109
  }
130
- if (errorExpression) {
131
- if (errorExpression.fn.body.type === "BlockStatement") {
132
- parser.walkStatement(errorExpression.fn.body);
110
+ if (successExpression) {
111
+ if (successExpression.fn.body.type === "BlockStatement") {
112
+ parser.walkStatement(successExpression.fn.body);
133
113
  } else {
134
- parser.walkExpression(errorExpression.fn.body);
114
+ parser.walkExpression(successExpression.fn.body);
135
115
  }
136
- } else if (errorExpressionArg) {
137
- parser.walkExpression(errorExpressionArg);
138
116
  }
139
- return true;
117
+ old.addBlock(depBlock);
118
+ } finally {
119
+ parser.state.current = old;
120
+ }
121
+ if (!successExpression) {
122
+ parser.walkExpression(successExpressionArg);
123
+ }
124
+ if (errorExpression) {
125
+ if (errorExpression.fn.body.type === "BlockStatement") {
126
+ parser.walkStatement(errorExpression.fn.body);
127
+ } else {
128
+ parser.walkExpression(errorExpression.fn.body);
129
+ }
130
+ } else if (errorExpressionArg) {
131
+ parser.walkExpression(errorExpressionArg);
140
132
  }
133
+ return true;
141
134
  }
142
- });
135
+ }
136
+ });
143
137
  }
144
138
  };
@@ -34,6 +34,7 @@ const WorkerDependency = require("./WorkerDependency");
34
34
  /** @typedef {import("estree").Property} Property */
35
35
  /** @typedef {import("estree").SpreadElement} SpreadElement */
36
36
  /** @typedef {import("../../declarations/WebpackOptions").ChunkLoading} ChunkLoading */
37
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
37
38
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
38
39
  /** @typedef {import("../../declarations/WebpackOptions").OutputModule} OutputModule */
39
40
  /** @typedef {import("../../declarations/WebpackOptions").WasmLoading} WasmLoading */
@@ -47,7 +48,6 @@ const WorkerDependency = require("./WorkerDependency");
47
48
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
48
49
  /** @typedef {import("../javascript/JavascriptParser")} Parser */
49
50
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
50
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
51
51
  /** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
52
52
 
53
53
  /**
@@ -376,7 +376,7 @@ class WorkerPlugin {
376
376
  parser.state.module.identifier()
377
377
  )}|${i}`;
378
378
  const hash = createHash(
379
- /** @type {Algorithm} */
379
+ /** @type {HashFunction} */
380
380
  (compilation.outputOptions.hashFunction)
381
381
  );
382
382
  hash.update(name);
@@ -12,6 +12,8 @@ const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModu
12
12
  /** @typedef {import("../Chunk")} Chunk */
13
13
  /** @typedef {import("../Compiler")} Compiler */
14
14
 
15
+ const PLUGIN_NAME = "ModuleChunkLoadingPlugin";
16
+
15
17
  class ModuleChunkLoadingPlugin {
16
18
  /**
17
19
  * Apply the plugin
@@ -19,88 +21,85 @@ class ModuleChunkLoadingPlugin {
19
21
  * @returns {void}
20
22
  */
21
23
  apply(compiler) {
22
- compiler.hooks.thisCompilation.tap(
23
- "ModuleChunkLoadingPlugin",
24
- compilation => {
25
- const globalChunkLoading = compilation.outputOptions.chunkLoading;
26
- /**
27
- * @param {Chunk} chunk chunk to check
28
- * @returns {boolean} true, when the plugin is enabled for the chunk
29
- */
30
- const isEnabledForChunk = chunk => {
31
- const options = chunk.getEntryOptions();
32
- const chunkLoading =
33
- options && options.chunkLoading !== undefined
34
- ? options.chunkLoading
35
- : globalChunkLoading;
36
- return chunkLoading === "import";
37
- };
38
- const onceForChunkSet = new WeakSet();
39
- /**
40
- * @param {Chunk} chunk chunk to check
41
- * @param {Set<string>} set runtime requirements
42
- */
43
- const handler = (chunk, set) => {
44
- if (onceForChunkSet.has(chunk)) return;
45
- onceForChunkSet.add(chunk);
24
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
25
+ const globalChunkLoading = compilation.outputOptions.chunkLoading;
26
+ /**
27
+ * @param {Chunk} chunk chunk to check
28
+ * @returns {boolean} true, when the plugin is enabled for the chunk
29
+ */
30
+ const isEnabledForChunk = chunk => {
31
+ const options = chunk.getEntryOptions();
32
+ const chunkLoading =
33
+ options && options.chunkLoading !== undefined
34
+ ? options.chunkLoading
35
+ : globalChunkLoading;
36
+ return chunkLoading === "import";
37
+ };
38
+ const onceForChunkSet = new WeakSet();
39
+ /**
40
+ * @param {Chunk} chunk chunk to check
41
+ * @param {Set<string>} set runtime requirements
42
+ */
43
+ const handler = (chunk, set) => {
44
+ if (onceForChunkSet.has(chunk)) return;
45
+ onceForChunkSet.add(chunk);
46
+ if (!isEnabledForChunk(chunk)) return;
47
+ set.add(RuntimeGlobals.moduleFactoriesAddOnly);
48
+ set.add(RuntimeGlobals.hasOwnProperty);
49
+ compilation.addRuntimeModule(
50
+ chunk,
51
+ new ModuleChunkLoadingRuntimeModule(set)
52
+ );
53
+ };
54
+ compilation.hooks.runtimeRequirementInTree
55
+ .for(RuntimeGlobals.ensureChunkHandlers)
56
+ .tap(PLUGIN_NAME, handler);
57
+ compilation.hooks.runtimeRequirementInTree
58
+ .for(RuntimeGlobals.baseURI)
59
+ .tap(PLUGIN_NAME, handler);
60
+ compilation.hooks.runtimeRequirementInTree
61
+ .for(RuntimeGlobals.externalInstallChunk)
62
+ .tap(PLUGIN_NAME, handler);
63
+ compilation.hooks.runtimeRequirementInTree
64
+ .for(RuntimeGlobals.onChunksLoaded)
65
+ .tap(PLUGIN_NAME, handler);
66
+ compilation.hooks.runtimeRequirementInTree
67
+ .for(RuntimeGlobals.externalInstallChunk)
68
+ .tap(PLUGIN_NAME, (chunk, set) => {
46
69
  if (!isEnabledForChunk(chunk)) return;
47
- set.add(RuntimeGlobals.moduleFactoriesAddOnly);
48
- set.add(RuntimeGlobals.hasOwnProperty);
49
70
  compilation.addRuntimeModule(
50
71
  chunk,
51
- new ModuleChunkLoadingRuntimeModule(set)
72
+ new ExportWebpackRequireRuntimeModule()
52
73
  );
53
- };
54
- compilation.hooks.runtimeRequirementInTree
55
- .for(RuntimeGlobals.ensureChunkHandlers)
56
- .tap("ModuleChunkLoadingPlugin", handler);
57
- compilation.hooks.runtimeRequirementInTree
58
- .for(RuntimeGlobals.baseURI)
59
- .tap("ModuleChunkLoadingPlugin", handler);
60
- compilation.hooks.runtimeRequirementInTree
61
- .for(RuntimeGlobals.externalInstallChunk)
62
- .tap("ModuleChunkLoadingPlugin", handler);
63
- compilation.hooks.runtimeRequirementInTree
64
- .for(RuntimeGlobals.onChunksLoaded)
65
- .tap("ModuleChunkLoadingPlugin", handler);
66
- compilation.hooks.runtimeRequirementInTree
67
- .for(RuntimeGlobals.externalInstallChunk)
68
- .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
69
- if (!isEnabledForChunk(chunk)) return;
70
- compilation.addRuntimeModule(
71
- chunk,
72
- new ExportWebpackRequireRuntimeModule()
73
- );
74
- });
74
+ });
75
75
 
76
- // We need public path only when we prefetch/preload chunk or public path is not `auto`
77
- compilation.hooks.runtimeRequirementInTree
78
- .for(RuntimeGlobals.prefetchChunkHandlers)
79
- .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
80
- if (!isEnabledForChunk(chunk)) return;
81
- set.add(RuntimeGlobals.publicPath);
82
- });
76
+ // We need public path only when we prefetch/preload chunk or public path is not `auto`
77
+ compilation.hooks.runtimeRequirementInTree
78
+ .for(RuntimeGlobals.prefetchChunkHandlers)
79
+ .tap(PLUGIN_NAME, (chunk, set) => {
80
+ if (!isEnabledForChunk(chunk)) return;
81
+ set.add(RuntimeGlobals.publicPath);
82
+ });
83
83
 
84
- compilation.hooks.runtimeRequirementInTree
85
- .for(RuntimeGlobals.preloadChunkHandlers)
86
- .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
87
- if (!isEnabledForChunk(chunk)) return;
88
- set.add(RuntimeGlobals.publicPath);
89
- });
84
+ compilation.hooks.runtimeRequirementInTree
85
+ .for(RuntimeGlobals.preloadChunkHandlers)
86
+ .tap(PLUGIN_NAME, (chunk, set) => {
87
+ if (!isEnabledForChunk(chunk)) return;
88
+ set.add(RuntimeGlobals.publicPath);
89
+ });
90
90
 
91
- compilation.hooks.runtimeRequirementInTree
92
- .for(RuntimeGlobals.ensureChunkHandlers)
93
- .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
94
- if (!isEnabledForChunk(chunk)) return;
91
+ compilation.hooks.runtimeRequirementInTree
92
+ .for(RuntimeGlobals.ensureChunkHandlers)
93
+ .tap(PLUGIN_NAME, (chunk, set) => {
94
+ if (!isEnabledForChunk(chunk)) return;
95
95
 
96
- if (compilation.outputOptions.publicPath !== "auto") {
97
- set.add(RuntimeGlobals.publicPath);
98
- }
96
+ if (compilation.outputOptions.publicPath !== "auto") {
97
+ set.add(RuntimeGlobals.publicPath);
98
+ }
99
99
 
100
- set.add(RuntimeGlobals.getChunkScriptFilename);
101
- });
102
- }
103
- );
100
+ set.add(RuntimeGlobals.getChunkScriptFilename);
101
+ });
102
+ });
104
103
  }
105
104
  }
106
105
 
@@ -69,7 +69,6 @@ module.exports = function () {
69
69
  me.children.push(request);
70
70
  }
71
71
  } else {
72
- // eslint-disable-next-line no-console
73
72
  console.warn(
74
73
  "[HMR] unexpected require(" +
75
74
  request +
@@ -109,7 +109,6 @@ module.exports = function () {
109
109
  var appliedUpdate = {};
110
110
 
111
111
  var warnUnexpectedRequire = function warnUnexpectedRequire(module) {
112
- // eslint-disable-next-line no-console
113
112
  console.warn(
114
113
  "[HMR] unexpected require(" + module.id + ") to disposed module"
115
114
  );
@@ -118,7 +117,6 @@ module.exports = function () {
118
117
  for (var moduleId in currentUpdate) {
119
118
  if ($hasOwnProperty$(currentUpdate, moduleId)) {
120
119
  var newModuleFactory = currentUpdate[moduleId];
121
- /** @type {TODO} */
122
120
  var result = newModuleFactory
123
121
  ? getAffectedModuleEffects(moduleId)
124
122
  : {