webpack 5.99.9 → 5.100.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.
Files changed (308) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +11 -4
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +5 -2
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +34 -20
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RawModule.js +14 -0
  70. package/lib/RecordIdsPlugin.js +3 -3
  71. package/lib/RuntimeGlobals.js +175 -155
  72. package/lib/RuntimeModule.js +1 -0
  73. package/lib/RuntimePlugin.js +33 -7
  74. package/lib/RuntimeTemplate.js +111 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  76. package/lib/SourceMapDevToolPlugin.js +19 -17
  77. package/lib/Template.js +2 -2
  78. package/lib/TemplatedPathPlugin.js +1 -1
  79. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  80. package/lib/WatchIgnorePlugin.js +4 -3
  81. package/lib/WebpackIsIncludedPlugin.js +2 -1
  82. package/lib/WebpackOptionsApply.js +115 -27
  83. package/lib/asset/AssetGenerator.js +15 -11
  84. package/lib/asset/AssetModulesPlugin.js +19 -17
  85. package/lib/asset/AssetSourceGenerator.js +4 -4
  86. package/lib/asset/RawDataUrlModule.js +4 -2
  87. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  88. package/lib/buildChunkGraph.js +6 -3
  89. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  90. package/lib/cache/IdleFileCachePlugin.js +7 -4
  91. package/lib/cache/MemoryCachePlugin.js +1 -0
  92. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  93. package/lib/cache/PackFileCacheStrategy.js +26 -20
  94. package/lib/cache/ResolverCachePlugin.js +16 -8
  95. package/lib/cli.js +15 -10
  96. package/lib/config/browserslistTargetHandler.js +3 -3
  97. package/lib/config/defaults.js +25 -17
  98. package/lib/config/normalization.js +2 -1
  99. package/lib/config/target.js +6 -5
  100. package/lib/container/ContainerPlugin.js +1 -1
  101. package/lib/container/ContainerReferencePlugin.js +1 -1
  102. package/lib/container/FallbackModule.js +2 -1
  103. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  104. package/lib/container/ModuleFederationPlugin.js +2 -2
  105. package/lib/container/RemoteModule.js +1 -1
  106. package/lib/css/CssGenerator.js +9 -6
  107. package/lib/css/CssModulesPlugin.js +44 -31
  108. package/lib/css/CssParser.js +6 -4
  109. package/lib/css/walkCssTokens.js +33 -37
  110. package/lib/debug/ProfilingPlugin.js +6 -6
  111. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  112. package/lib/dependencies/AMDPlugin.js +12 -8
  113. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  114. package/lib/dependencies/CachedConstDependency.js +1 -5
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  116. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  117. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  118. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  119. package/lib/dependencies/CommonJsPlugin.js +15 -16
  120. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  121. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  123. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  124. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  125. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  126. package/lib/dependencies/DynamicExports.js +9 -9
  127. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  128. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  129. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  130. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  131. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  132. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  133. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  134. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  135. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  136. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  137. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  138. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  139. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  140. package/lib/dependencies/ImportParserPlugin.js +40 -9
  141. package/lib/dependencies/ImportPlugin.js +3 -1
  142. package/lib/dependencies/LoaderPlugin.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +3 -1
  144. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  145. package/lib/dependencies/RequireContextPlugin.js +3 -1
  146. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  147. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  148. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  149. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  150. package/lib/dependencies/SystemPlugin.js +1 -1
  151. package/lib/dependencies/URLContextDependency.js +65 -0
  152. package/lib/dependencies/URLPlugin.js +17 -157
  153. package/lib/dependencies/WorkerPlugin.js +23 -10
  154. package/lib/dependencies/processExportInfo.js +2 -1
  155. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  156. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  157. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  158. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  159. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  160. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  161. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  162. package/lib/hmr/lazyCompilationBackend.js +4 -2
  163. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  164. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  165. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  166. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  167. package/lib/ids/IdHelpers.js +21 -17
  168. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  169. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  170. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  171. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  172. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  173. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  174. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  175. package/lib/index.js +13 -3
  176. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  177. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  178. package/lib/javascript/ChunkHelpers.js +1 -0
  179. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  180. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  181. package/lib/javascript/JavascriptGenerator.js +14 -2
  182. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  183. package/lib/javascript/JavascriptParser.js +117 -76
  184. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  185. package/lib/javascript/StartupHelpers.js +17 -17
  186. package/lib/json/JsonGenerator.js +4 -2
  187. package/lib/json/JsonModulesPlugin.js +2 -2
  188. package/lib/json/JsonParser.js +1 -1
  189. package/lib/library/AbstractLibraryPlugin.js +6 -2
  190. package/lib/library/AssignLibraryPlugin.js +21 -6
  191. package/lib/library/EnableLibraryPlugin.js +23 -3
  192. package/lib/library/UmdLibraryPlugin.js +15 -6
  193. package/lib/logging/createConsoleLogger.js +3 -3
  194. package/lib/logging/runtime.js +9 -9
  195. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  196. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  197. package/lib/node/nodeConsole.js +4 -2
  198. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  199. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  200. package/lib/optimize/ConcatenatedModule.js +227 -57
  201. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  202. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  203. package/lib/optimize/InnerGraph.js +115 -112
  204. package/lib/optimize/InnerGraphPlugin.js +2 -2
  205. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  206. package/lib/optimize/MangleExportsPlugin.js +4 -3
  207. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  208. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  209. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  210. package/lib/optimize/RealContentHashPlugin.js +26 -20
  211. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  212. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  213. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  214. package/lib/optimize/SplitChunksPlugin.js +16 -13
  215. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  216. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  217. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  218. package/lib/rules/RuleSetCompiler.js +19 -5
  219. package/lib/rules/UseEffectRulePlugin.js +17 -9
  220. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  221. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  222. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  223. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  224. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  225. package/lib/schemes/FileUriPlugin.js +1 -1
  226. package/lib/schemes/HttpUriPlugin.js +27 -19
  227. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  228. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  229. package/lib/serialization/BinaryMiddleware.js +5 -4
  230. package/lib/serialization/FileMiddleware.js +7 -4
  231. package/lib/serialization/ObjectMiddleware.js +14 -8
  232. package/lib/serialization/Serializer.js +5 -3
  233. package/lib/serialization/SerializerMiddleware.js +2 -0
  234. package/lib/sharing/ConsumeSharedModule.js +1 -1
  235. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  236. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  237. package/lib/sharing/ProvideSharedModule.js +1 -1
  238. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  239. package/lib/sharing/SharePlugin.js +2 -1
  240. package/lib/sharing/ShareRuntimeModule.js +3 -5
  241. package/lib/sharing/utils.js +34 -34
  242. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  243. package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
  244. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  245. package/lib/stats/StatsFactory.js +6 -3
  246. package/lib/stats/StatsPrinter.js +6 -7
  247. package/lib/url/URLParserPlugin.js +266 -0
  248. package/lib/util/ArrayQueue.js +1 -1
  249. package/lib/util/AsyncQueue.js +1 -1
  250. package/lib/util/Hash.js +2 -0
  251. package/lib/util/IterableHelpers.js +1 -1
  252. package/lib/util/LazyBucketSortedSet.js +2 -1
  253. package/lib/util/LazySet.js +11 -6
  254. package/lib/util/ParallelismFactorCalculator.js +1 -1
  255. package/lib/util/SetHelpers.js +3 -3
  256. package/lib/util/SortableSet.js +2 -2
  257. package/lib/util/StackedCacheMap.js +3 -1
  258. package/lib/util/StackedMap.js +2 -2
  259. package/lib/util/StringXor.js +1 -0
  260. package/lib/util/TupleSet.js +1 -0
  261. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  262. package/lib/util/cleverMerge.js +95 -58
  263. package/lib/util/comparators.js +154 -127
  264. package/lib/util/compileBooleanMatcher.js +8 -3
  265. package/lib/util/concatenate.js +8 -7
  266. package/lib/util/conventions.js +72 -73
  267. package/lib/util/create-schema-validation.js +2 -1
  268. package/lib/util/createHash.js +10 -4
  269. package/lib/util/deprecation.js +69 -66
  270. package/lib/util/deterministicGrouping.js +4 -2
  271. package/lib/util/extractUrlAndGlobal.js +1 -1
  272. package/lib/util/findGraphRoots.js +2 -2
  273. package/lib/util/fs.js +30 -23
  274. package/lib/util/hash/md4.js +2 -2
  275. package/lib/util/hash/wasm-hash.js +4 -2
  276. package/lib/util/identifier.js +13 -12
  277. package/lib/util/internalSerializables.js +2 -0
  278. package/lib/util/magicComment.js +5 -5
  279. package/lib/util/processAsyncTree.js +1 -1
  280. package/lib/util/propertyAccess.js +1 -1
  281. package/lib/util/propertyName.js +1 -1
  282. package/lib/util/registerExternalSerializer.js +1 -2
  283. package/lib/util/removeBOM.js +1 -1
  284. package/lib/util/runtime.js +29 -21
  285. package/lib/util/semver.js +1 -1
  286. package/lib/util/serialization.js +3 -0
  287. package/lib/util/source.js +3 -2
  288. package/lib/validateSchema.js +1 -0
  289. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  290. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  291. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  292. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  293. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  294. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  295. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  296. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  297. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  298. package/lib/webpack.js +4 -5
  299. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  300. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  301. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  302. package/package.json +119 -113
  303. package/schemas/WebpackOptions.check.js +1 -1
  304. package/schemas/WebpackOptions.json +17 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  306. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  307. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  308. package/types.d.ts +1243 -409
@@ -42,6 +42,8 @@ const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency
42
42
  const createRequireSpecifierTag = Symbol("createRequire");
43
43
  const createdRequireIdentifierTag = Symbol("createRequire()");
44
44
 
45
+ const PLUGIN_NAME = "CommonJsImportsParserPlugin";
46
+
45
47
  class CommonJsImportsParserPlugin {
46
48
  /**
47
49
  * @param {JavascriptParserOptions} options parser options
@@ -73,16 +75,16 @@ class CommonJsImportsParserPlugin {
73
75
  parser.hooks.typeof
74
76
  .for(expression)
75
77
  .tap(
76
- "CommonJsImportsParserPlugin",
78
+ PLUGIN_NAME,
77
79
  toConstantDependency(parser, JSON.stringify("function"))
78
80
  );
79
81
  parser.hooks.evaluateTypeof
80
82
  .for(expression)
81
- .tap("CommonJsImportsParserPlugin", evaluateToString("function"));
83
+ .tap(PLUGIN_NAME, evaluateToString("function"));
82
84
  parser.hooks.evaluateIdentifier
83
85
  .for(expression)
84
86
  .tap(
85
- "CommonJsImportsParserPlugin",
87
+ PLUGIN_NAME,
86
88
  evaluateToIdentifier(expression, "require", getMembers, true)
87
89
  );
88
90
  };
@@ -93,12 +95,12 @@ class CommonJsImportsParserPlugin {
93
95
  parser.hooks.typeof
94
96
  .for(tag)
95
97
  .tap(
96
- "CommonJsImportsParserPlugin",
98
+ PLUGIN_NAME,
97
99
  toConstantDependency(parser, JSON.stringify("function"))
98
100
  );
99
101
  parser.hooks.evaluateTypeof
100
102
  .for(tag)
101
- .tap("CommonJsImportsParserPlugin", evaluateToString("function"));
103
+ .tap(PLUGIN_NAME, evaluateToString("function"));
102
104
  };
103
105
  tapRequireExpression("require", () => []);
104
106
  tapRequireExpression("require.resolve", () => ["resolve"]);
@@ -106,21 +108,19 @@ class CommonJsImportsParserPlugin {
106
108
  // #endregion
107
109
 
108
110
  // Weird stuff //
109
- parser.hooks.assign
110
- .for("require")
111
- .tap("CommonJsImportsParserPlugin", expr => {
112
- // to not leak to global "require", we need to define a local require here.
113
- const dep = new ConstDependency("var require;", 0);
114
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
115
- parser.state.module.addPresentationalDependency(dep);
116
- return true;
117
- });
111
+ parser.hooks.assign.for("require").tap(PLUGIN_NAME, expr => {
112
+ // to not leak to global "require", we need to define a local require here.
113
+ const dep = new ConstDependency("var require;", 0);
114
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
115
+ parser.state.module.addPresentationalDependency(dep);
116
+ return true;
117
+ });
118
118
 
119
119
  // #region Unsupported
120
120
  parser.hooks.expression
121
121
  .for("require.main")
122
122
  .tap(
123
- "CommonJsImportsParserPlugin",
123
+ PLUGIN_NAME,
124
124
  expressionIsUnsupported(
125
125
  parser,
126
126
  "require.main is not supported by webpack."
@@ -129,7 +129,7 @@ class CommonJsImportsParserPlugin {
129
129
  parser.hooks.call
130
130
  .for("require.main.require")
131
131
  .tap(
132
- "CommonJsImportsParserPlugin",
132
+ PLUGIN_NAME,
133
133
  expressionIsUnsupported(
134
134
  parser,
135
135
  "require.main.require is not supported by webpack."
@@ -138,7 +138,7 @@ class CommonJsImportsParserPlugin {
138
138
  parser.hooks.expression
139
139
  .for("module.parent.require")
140
140
  .tap(
141
- "CommonJsImportsParserPlugin",
141
+ PLUGIN_NAME,
142
142
  expressionIsUnsupported(
143
143
  parser,
144
144
  "module.parent.require is not supported by webpack."
@@ -147,7 +147,7 @@ class CommonJsImportsParserPlugin {
147
147
  parser.hooks.call
148
148
  .for("module.parent.require")
149
149
  .tap(
150
- "CommonJsImportsParserPlugin",
150
+ PLUGIN_NAME,
151
151
  expressionIsUnsupported(
152
152
  parser,
153
153
  "module.parent.require is not supported by webpack."
@@ -170,12 +170,8 @@ class CommonJsImportsParserPlugin {
170
170
  parser.state.module.addPresentationalDependency(dep);
171
171
  return false;
172
172
  };
173
- parser.hooks.canRename
174
- .for("require")
175
- .tap("CommonJsImportsParserPlugin", () => true);
176
- parser.hooks.rename
177
- .for("require")
178
- .tap("CommonJsImportsParserPlugin", defineUndefined);
173
+ parser.hooks.canRename.for("require").tap(PLUGIN_NAME, () => true);
174
+ parser.hooks.rename.for("require").tap(PLUGIN_NAME, defineUndefined);
179
175
  // #endregion
180
176
 
181
177
  // #region Inspection
@@ -189,9 +185,7 @@ class CommonJsImportsParserPlugin {
189
185
  ]
190
186
  );
191
187
 
192
- parser.hooks.expression
193
- .for("require.cache")
194
- .tap("CommonJsImportsParserPlugin", requireCache);
188
+ parser.hooks.expression.for("require.cache").tap(PLUGIN_NAME, requireCache);
195
189
  // #endregion
196
190
 
197
191
  // #region Require as expression
@@ -222,7 +216,7 @@ class CommonJsImportsParserPlugin {
222
216
  };
223
217
  parser.hooks.expression
224
218
  .for("require")
225
- .tap("CommonJsImportsParserPlugin", requireAsExpressionHandler);
219
+ .tap(PLUGIN_NAME, requireAsExpressionHandler);
226
220
  // #endregion
227
221
 
228
222
  // #region Require
@@ -357,16 +351,16 @@ class CommonJsImportsParserPlugin {
357
351
  };
358
352
  parser.hooks.call
359
353
  .for("require")
360
- .tap("CommonJsImportsParserPlugin", createRequireHandler(false));
354
+ .tap(PLUGIN_NAME, createRequireHandler(false));
361
355
  parser.hooks.new
362
356
  .for("require")
363
- .tap("CommonJsImportsParserPlugin", createRequireHandler(true));
357
+ .tap(PLUGIN_NAME, createRequireHandler(true));
364
358
  parser.hooks.call
365
359
  .for("module.require")
366
- .tap("CommonJsImportsParserPlugin", createRequireHandler(false));
360
+ .tap(PLUGIN_NAME, createRequireHandler(false));
367
361
  parser.hooks.new
368
362
  .for("module.require")
369
- .tap("CommonJsImportsParserPlugin", createRequireHandler(true));
363
+ .tap(PLUGIN_NAME, createRequireHandler(true));
370
364
  // #endregion
371
365
 
372
366
  // #region Require with property access
@@ -446,16 +440,16 @@ class CommonJsImportsParserPlugin {
446
440
  };
447
441
  parser.hooks.memberChainOfCallMemberChain
448
442
  .for("require")
449
- .tap("CommonJsImportsParserPlugin", chainHandler);
443
+ .tap(PLUGIN_NAME, chainHandler);
450
444
  parser.hooks.memberChainOfCallMemberChain
451
445
  .for("module.require")
452
- .tap("CommonJsImportsParserPlugin", chainHandler);
446
+ .tap(PLUGIN_NAME, chainHandler);
453
447
  parser.hooks.callMemberChainOfCallMemberChain
454
448
  .for("require")
455
- .tap("CommonJsImportsParserPlugin", callChainHandler);
449
+ .tap(PLUGIN_NAME, callChainHandler);
456
450
  parser.hooks.callMemberChainOfCallMemberChain
457
451
  .for("module.require")
458
- .tap("CommonJsImportsParserPlugin", callChainHandler);
452
+ .tap(PLUGIN_NAME, callChainHandler);
459
453
  // #endregion
460
454
 
461
455
  // #region Require.resolve
@@ -573,10 +567,10 @@ class CommonJsImportsParserPlugin {
573
567
 
574
568
  parser.hooks.call
575
569
  .for("require.resolve")
576
- .tap("CommonJsImportsParserPlugin", expr => processResolve(expr, false));
570
+ .tap(PLUGIN_NAME, expr => processResolve(expr, false));
577
571
  parser.hooks.call
578
572
  .for("require.resolveWeak")
579
- .tap("CommonJsImportsParserPlugin", expr => processResolve(expr, true));
573
+ .tap(PLUGIN_NAME, expr => processResolve(expr, true));
580
574
  // #endregion
581
575
 
582
576
  // #region Create require
@@ -613,7 +607,7 @@ class CommonJsImportsParserPlugin {
613
607
  tapRequireExpressionTag(createRequireSpecifierTag);
614
608
  parser.hooks.evaluateCallExpression
615
609
  .for(createRequireSpecifierTag)
616
- .tap("CommonJsImportsParserPlugin", expr => {
610
+ .tap(PLUGIN_NAME, expr => {
617
611
  const context = parseCreateRequireArguments(expr);
618
612
  if (context === undefined) return;
619
613
  const ident = parser.evaluatedVariable({
@@ -629,7 +623,7 @@ class CommonJsImportsParserPlugin {
629
623
  });
630
624
  parser.hooks.unhandledExpressionMemberChain
631
625
  .for(createdRequireIdentifierTag)
632
- .tap("CommonJsImportsParserPlugin", (expr, members) =>
626
+ .tap(PLUGIN_NAME, (expr, members) =>
633
627
  expressionIsUnsupported(
634
628
  parser,
635
629
  `createRequire().${members.join(".")} is not supported by webpack.`
@@ -637,19 +631,19 @@ class CommonJsImportsParserPlugin {
637
631
  );
638
632
  parser.hooks.canRename
639
633
  .for(createdRequireIdentifierTag)
640
- .tap("CommonJsImportsParserPlugin", () => true);
634
+ .tap(PLUGIN_NAME, () => true);
641
635
  parser.hooks.canRename
642
636
  .for(createRequireSpecifierTag)
643
- .tap("CommonJsImportsParserPlugin", () => true);
637
+ .tap(PLUGIN_NAME, () => true);
644
638
  parser.hooks.rename
645
639
  .for(createRequireSpecifierTag)
646
- .tap("CommonJsImportsParserPlugin", defineUndefined);
640
+ .tap(PLUGIN_NAME, defineUndefined);
647
641
  parser.hooks.expression
648
642
  .for(createdRequireIdentifierTag)
649
- .tap("CommonJsImportsParserPlugin", requireAsExpressionHandler);
643
+ .tap(PLUGIN_NAME, requireAsExpressionHandler);
650
644
  parser.hooks.call
651
645
  .for(createdRequireIdentifierTag)
652
- .tap("CommonJsImportsParserPlugin", createRequireHandler(false));
646
+ .tap(PLUGIN_NAME, createRequireHandler(false));
653
647
  /**
654
648
  * @param {CallExpression} expr call expression
655
649
  * @returns {string | void} context
@@ -683,7 +677,7 @@ class CommonJsImportsParserPlugin {
683
677
 
684
678
  parser.hooks.import.tap(
685
679
  {
686
- name: "CommonJsImportsParserPlugin",
680
+ name: PLUGIN_NAME,
687
681
  stage: -10
688
682
  },
689
683
  (statement, source) => {
@@ -693,8 +687,9 @@ class CommonJsImportsParserPlugin {
693
687
  statement.specifiers[0].type !== "ImportSpecifier" ||
694
688
  statement.specifiers[0].imported.type !== "Identifier" ||
695
689
  statement.specifiers[0].imported.name !== specifierName
696
- )
690
+ ) {
697
691
  return;
692
+ }
698
693
  // clear for 'import { createRequire as x } from "module"'
699
694
  // if any other specifier was used import module
700
695
  const clearDep = new ConstDependency(
@@ -711,7 +706,7 @@ class CommonJsImportsParserPlugin {
711
706
  );
712
707
  parser.hooks.importSpecifier.tap(
713
708
  {
714
- name: "CommonJsImportsParserPlugin",
709
+ name: PLUGIN_NAME,
715
710
  stage: -10
716
711
  },
717
712
  (statement, source, id, name) => {
@@ -720,70 +715,62 @@ class CommonJsImportsParserPlugin {
720
715
  return true;
721
716
  }
722
717
  );
723
- parser.hooks.preDeclarator.tap(
724
- "CommonJsImportsParserPlugin",
725
- declarator => {
726
- if (
727
- declarator.id.type !== "Identifier" ||
728
- !declarator.init ||
729
- declarator.init.type !== "CallExpression" ||
730
- declarator.init.callee.type !== "Identifier"
731
- )
732
- return;
733
- const variableInfo = parser.getVariableInfo(
734
- declarator.init.callee.name
735
- );
736
- if (
737
- variableInfo instanceof VariableInfo &&
738
- variableInfo.tagInfo &&
739
- variableInfo.tagInfo.tag === createRequireSpecifierTag
740
- ) {
741
- const context = parseCreateRequireArguments(declarator.init);
742
- if (context === undefined) return;
743
- parser.tagVariable(declarator.id.name, createdRequireIdentifierTag, {
744
- name: declarator.id.name,
745
- context
746
- });
747
- return true;
748
- }
718
+ parser.hooks.preDeclarator.tap(PLUGIN_NAME, declarator => {
719
+ if (
720
+ declarator.id.type !== "Identifier" ||
721
+ !declarator.init ||
722
+ declarator.init.type !== "CallExpression" ||
723
+ declarator.init.callee.type !== "Identifier"
724
+ ) {
725
+ return;
749
726
  }
750
- );
727
+ const variableInfo = parser.getVariableInfo(declarator.init.callee.name);
728
+ if (
729
+ variableInfo instanceof VariableInfo &&
730
+ variableInfo.tagInfo &&
731
+ variableInfo.tagInfo.tag === createRequireSpecifierTag
732
+ ) {
733
+ const context = parseCreateRequireArguments(declarator.init);
734
+ if (context === undefined) return;
735
+ parser.tagVariable(declarator.id.name, createdRequireIdentifierTag, {
736
+ name: declarator.id.name,
737
+ context
738
+ });
739
+ return true;
740
+ }
741
+ });
751
742
 
752
743
  parser.hooks.memberChainOfCallMemberChain
753
744
  .for(createRequireSpecifierTag)
754
- .tap(
755
- "CommonJsImportsParserPlugin",
756
- (expr, calleeMembers, callExpr, members) => {
757
- if (
758
- calleeMembers.length !== 0 ||
759
- members.length !== 1 ||
760
- members[0] !== "cache"
761
- )
762
- return;
763
- // createRequire().cache
764
- const context = parseCreateRequireArguments(callExpr);
765
- if (context === undefined) return;
766
- return requireCache(expr);
745
+ .tap(PLUGIN_NAME, (expr, calleeMembers, callExpr, members) => {
746
+ if (
747
+ calleeMembers.length !== 0 ||
748
+ members.length !== 1 ||
749
+ members[0] !== "cache"
750
+ ) {
751
+ return;
767
752
  }
768
- );
753
+ // createRequire().cache
754
+ const context = parseCreateRequireArguments(callExpr);
755
+ if (context === undefined) return;
756
+ return requireCache(expr);
757
+ });
769
758
  parser.hooks.callMemberChainOfCallMemberChain
770
759
  .for(createRequireSpecifierTag)
771
- .tap(
772
- "CommonJsImportsParserPlugin",
773
- (expr, calleeMembers, innerCallExpression, members) => {
774
- if (
775
- calleeMembers.length !== 0 ||
776
- members.length !== 1 ||
777
- members[0] !== "resolve"
778
- )
779
- return;
780
- // createRequire().resolve()
781
- return processResolve(expr, false);
760
+ .tap(PLUGIN_NAME, (expr, calleeMembers, innerCallExpression, members) => {
761
+ if (
762
+ calleeMembers.length !== 0 ||
763
+ members.length !== 1 ||
764
+ members[0] !== "resolve"
765
+ ) {
766
+ return;
782
767
  }
783
- );
768
+ // createRequire().resolve()
769
+ return processResolve(expr, false);
770
+ });
784
771
  parser.hooks.expressionMemberChain
785
772
  .for(createdRequireIdentifierTag)
786
- .tap("CommonJsImportsParserPlugin", (expr, members) => {
773
+ .tap(PLUGIN_NAME, (expr, members) => {
787
774
  // require.cache
788
775
  if (members.length === 1 && members[0] === "cache") {
789
776
  return requireCache(expr);
@@ -791,24 +778,23 @@ class CommonJsImportsParserPlugin {
791
778
  });
792
779
  parser.hooks.callMemberChain
793
780
  .for(createdRequireIdentifierTag)
794
- .tap("CommonJsImportsParserPlugin", (expr, members) => {
781
+ .tap(PLUGIN_NAME, (expr, members) => {
795
782
  // require.resolve()
796
783
  if (members.length === 1 && members[0] === "resolve") {
797
784
  return processResolve(expr, false);
798
785
  }
799
786
  });
800
- parser.hooks.call
801
- .for(createRequireSpecifierTag)
802
- .tap("CommonJsImportsParserPlugin", expr => {
803
- const clearDep = new ConstDependency(
804
- "/* createRequire() */ undefined",
805
- /** @type {Range} */ (expr.range)
806
- );
807
- clearDep.loc = /** @type {DependencyLocation} */ (expr.loc);
808
- parser.state.module.addPresentationalDependency(clearDep);
809
- return true;
810
- });
787
+ parser.hooks.call.for(createRequireSpecifierTag).tap(PLUGIN_NAME, expr => {
788
+ const clearDep = new ConstDependency(
789
+ "/* createRequire() */ undefined",
790
+ /** @type {Range} */ (expr.range)
791
+ );
792
+ clearDep.loc = /** @type {DependencyLocation} */ (expr.loc);
793
+ parser.state.module.addPresentationalDependency(clearDep);
794
+ return true;
795
+ });
811
796
  // #endregion
812
797
  }
813
798
  }
799
+
814
800
  module.exports = CommonJsImportsParserPlugin;
@@ -5,12 +5,23 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC
11
+ } = require("../ModuleTypeConstants");
8
12
  const RuntimeGlobals = require("../RuntimeGlobals");
9
13
  const RuntimeModule = require("../RuntimeModule");
10
14
  const SelfModuleFactory = require("../SelfModuleFactory");
11
15
  const Template = require("../Template");
16
+ const {
17
+ evaluateToIdentifier,
18
+ toConstantDependency
19
+ } = require("../javascript/JavascriptParserHelpers");
20
+ const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
12
21
  const CommonJsExportsDependency = require("./CommonJsExportsDependency");
22
+ const CommonJsExportsParserPlugin = require("./CommonJsExportsParserPlugin");
13
23
  const CommonJsFullRequireDependency = require("./CommonJsFullRequireDependency");
24
+ const CommonJsImportsParserPlugin = require("./CommonJsImportsParserPlugin");
14
25
  const CommonJsRequireContextDependency = require("./CommonJsRequireContextDependency");
15
26
  const CommonJsRequireDependency = require("./CommonJsRequireDependency");
16
27
  const CommonJsSelfReferenceDependency = require("./CommonJsSelfReferenceDependency");
@@ -21,19 +32,6 @@ const RequireResolveDependency = require("./RequireResolveDependency");
21
32
  const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency");
22
33
  const RuntimeRequirementsDependency = require("./RuntimeRequirementsDependency");
23
34
 
24
- const CommonJsExportsParserPlugin = require("./CommonJsExportsParserPlugin");
25
- const CommonJsImportsParserPlugin = require("./CommonJsImportsParserPlugin");
26
-
27
- const {
28
- JAVASCRIPT_MODULE_TYPE_AUTO,
29
- JAVASCRIPT_MODULE_TYPE_DYNAMIC
30
- } = require("../ModuleTypeConstants");
31
- const {
32
- evaluateToIdentifier,
33
- toConstantDependency
34
- } = require("../javascript/JavascriptParserHelpers");
35
- const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
36
-
37
35
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
38
36
  /** @typedef {import("../Compilation")} Compilation */
39
37
  /** @typedef {import("../Compiler")} Compiler */
@@ -158,7 +156,7 @@ class CommonJsPlugin {
158
156
 
159
157
  compilation.hooks.runtimeRequirementInTree
160
158
  .for(RuntimeGlobals.harmonyModuleDecorator)
161
- .tap(PLUGIN_NAME, (chunk, set) => {
159
+ .tap(PLUGIN_NAME, (chunk, _set) => {
162
160
  compilation.addRuntimeModule(
163
161
  chunk,
164
162
  new HarmonyModuleDecoratorRuntimeModule()
@@ -167,7 +165,7 @@ class CommonJsPlugin {
167
165
 
168
166
  compilation.hooks.runtimeRequirementInTree
169
167
  .for(RuntimeGlobals.nodeModuleDecorator)
170
- .tap(PLUGIN_NAME, (chunk, set) => {
168
+ .tap(PLUGIN_NAME, (chunk, _set) => {
171
169
  compilation.addRuntimeModule(
172
170
  chunk,
173
171
  new NodeModuleDecoratorRuntimeModule()
@@ -180,8 +178,9 @@ class CommonJsPlugin {
180
178
  * @returns {void}
181
179
  */
182
180
  const handler = (parser, parserOptions) => {
183
- if (parserOptions.commonjs !== undefined && !parserOptions.commonjs)
181
+ if (parserOptions.commonjs !== undefined && !parserOptions.commonjs) {
184
182
  return;
183
+ }
185
184
  parser.hooks.typeof
186
185
  .for("module")
187
186
  .tap(
@@ -236,11 +236,12 @@ module.exports.create = (
236
236
 
237
237
  if (parser && param.wrappedInnerExpressions) {
238
238
  for (const part of param.wrappedInnerExpressions) {
239
- if (part.expression)
239
+ if (part.expression) {
240
240
  parser.walkExpression(
241
241
  /** @type {Expression} */
242
242
  (part.expression)
243
243
  );
244
+ }
244
245
  }
245
246
  }
246
247
 
@@ -59,4 +59,5 @@ class ContextDependencyTemplateAsId extends ContextDependency.Template {
59
59
  }
60
60
  }
61
61
  }
62
+
62
63
  module.exports = ContextDependencyTemplateAsId;
@@ -56,4 +56,5 @@ class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template
56
56
  }
57
57
  }
58
58
  }
59
+
59
60
  module.exports = ContextDependencyTemplateAsRequireCall;
@@ -145,7 +145,7 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
145
145
  .filter(Boolean)
146
146
  );
147
147
 
148
- for (const used of usedNames.concat(names)) {
148
+ for (const used of [...usedNames, ...names]) {
149
149
  cssData.exports.set(used, dep.value);
150
150
  }
151
151
  }
@@ -222,7 +222,7 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
222
222
  (generator.convention)
223
223
  );
224
224
  const usedNames =
225
- /** @type {(string)[]} */
225
+ /** @type {string[]} */
226
226
  (
227
227
  names
228
228
  .map(name =>
@@ -239,7 +239,7 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
239
239
 
240
240
  source.replace(dep.range[0], dep.range[1] - 1, identifier);
241
241
 
242
- for (const used of usedNames.concat(names)) {
242
+ for (const used of [...usedNames, ...names]) {
243
243
  cssData.exports.set(used, getCssParser().unescapeIdentifier(identifier));
244
244
  }
245
245
  }
@@ -63,8 +63,9 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
63
63
  * @returns {(string[] | ReferencedExport)[]} referenced exports
64
64
  */
65
65
  getReferencedExports(moduleGraph, runtime) {
66
- if (this.declaredSet && !this.declaredSet.has(this.name))
66
+ if (this.declaredSet && !this.declaredSet.has(this.name)) {
67
67
  return Dependency.NO_EXPORTS_REFERENCED;
68
+ }
68
69
  return [[this.name]];
69
70
  }
70
71
 
@@ -42,14 +42,11 @@ module.exports.enable = parserState => {
42
42
 
43
43
  /**
44
44
  * @param {ParserState} parserState parser state
45
- * @returns {void}
45
+ * @returns {boolean} true, when enabled
46
46
  */
47
- module.exports.setFlagged = parserState => {
47
+ module.exports.isEnabled = parserState => {
48
48
  const value = parserStateExportsState.get(parserState);
49
- if (value !== true) return;
50
- const buildMeta = /** @type {BuildMeta} */ (parserState.module.buildMeta);
51
- if (buildMeta.exportsType === "dynamic") return;
52
- buildMeta.exportsType = "flagged";
49
+ return value === true;
53
50
  };
54
51
 
55
52
  /**
@@ -65,9 +62,12 @@ module.exports.setDynamic = parserState => {
65
62
 
66
63
  /**
67
64
  * @param {ParserState} parserState parser state
68
- * @returns {boolean} true, when enabled
65
+ * @returns {void}
69
66
  */
70
- module.exports.isEnabled = parserState => {
67
+ module.exports.setFlagged = parserState => {
71
68
  const value = parserStateExportsState.get(parserState);
72
- return value === true;
69
+ if (value !== true) return;
70
+ const buildMeta = /** @type {BuildMeta} */ (parserState.module.buildMeta);
71
+ if (buildMeta.exportsType === "dynamic") return;
72
+ buildMeta.exportsType = "flagged";
73
73
  };
@@ -49,7 +49,7 @@ const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
49
49
  ) {
50
50
  return usedExports;
51
51
  }
52
- return Array.from(usedExports).sort();
52
+ return [...usedExports].sort();
53
53
  }
54
54
  }
55
55
  }