webpack 5.99.9 → 5.100.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 (306) 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 +6 -1
  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 +1 -1
  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 +29 -19
  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/RecordIdsPlugin.js +3 -3
  70. package/lib/RuntimeGlobals.js +175 -155
  71. package/lib/RuntimeModule.js +1 -0
  72. package/lib/RuntimePlugin.js +33 -7
  73. package/lib/RuntimeTemplate.js +111 -11
  74. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  75. package/lib/SourceMapDevToolPlugin.js +19 -17
  76. package/lib/Template.js +2 -2
  77. package/lib/TemplatedPathPlugin.js +1 -1
  78. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  79. package/lib/WatchIgnorePlugin.js +4 -3
  80. package/lib/WebpackIsIncludedPlugin.js +2 -1
  81. package/lib/WebpackOptionsApply.js +115 -27
  82. package/lib/asset/AssetGenerator.js +15 -11
  83. package/lib/asset/AssetModulesPlugin.js +19 -17
  84. package/lib/asset/AssetSourceGenerator.js +4 -4
  85. package/lib/asset/RawDataUrlModule.js +4 -2
  86. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  87. package/lib/buildChunkGraph.js +6 -3
  88. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  89. package/lib/cache/IdleFileCachePlugin.js +7 -4
  90. package/lib/cache/MemoryCachePlugin.js +1 -0
  91. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  92. package/lib/cache/PackFileCacheStrategy.js +26 -20
  93. package/lib/cache/ResolverCachePlugin.js +16 -8
  94. package/lib/cli.js +15 -10
  95. package/lib/config/browserslistTargetHandler.js +3 -3
  96. package/lib/config/defaults.js +25 -17
  97. package/lib/config/normalization.js +2 -1
  98. package/lib/config/target.js +6 -5
  99. package/lib/container/ContainerPlugin.js +1 -1
  100. package/lib/container/ContainerReferencePlugin.js +1 -1
  101. package/lib/container/FallbackModule.js +2 -1
  102. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  103. package/lib/container/ModuleFederationPlugin.js +2 -2
  104. package/lib/container/RemoteModule.js +1 -1
  105. package/lib/css/CssGenerator.js +9 -6
  106. package/lib/css/CssModulesPlugin.js +44 -31
  107. package/lib/css/CssParser.js +6 -4
  108. package/lib/css/walkCssTokens.js +33 -37
  109. package/lib/debug/ProfilingPlugin.js +6 -6
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  111. package/lib/dependencies/AMDPlugin.js +12 -8
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  113. package/lib/dependencies/CachedConstDependency.js +1 -5
  114. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  115. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  118. package/lib/dependencies/CommonJsPlugin.js +15 -16
  119. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  121. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  122. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  123. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  124. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  125. package/lib/dependencies/DynamicExports.js +9 -9
  126. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  127. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  128. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  129. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  130. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  131. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  132. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  133. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  134. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  135. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  136. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  137. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  138. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  139. package/lib/dependencies/ImportParserPlugin.js +40 -9
  140. package/lib/dependencies/ImportPlugin.js +3 -1
  141. package/lib/dependencies/LoaderPlugin.js +1 -0
  142. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  143. package/lib/dependencies/RequireContextPlugin.js +3 -1
  144. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  145. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  146. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  147. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  148. package/lib/dependencies/SystemPlugin.js +1 -1
  149. package/lib/dependencies/URLContextDependency.js +65 -0
  150. package/lib/dependencies/URLPlugin.js +17 -157
  151. package/lib/dependencies/WorkerPlugin.js +23 -10
  152. package/lib/dependencies/processExportInfo.js +2 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  156. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  157. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  158. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  159. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  160. package/lib/hmr/lazyCompilationBackend.js +4 -2
  161. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  162. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  163. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  164. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  165. package/lib/ids/IdHelpers.js +21 -17
  166. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  167. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  168. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  169. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  170. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  171. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  172. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  173. package/lib/index.js +13 -3
  174. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  175. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  176. package/lib/javascript/ChunkHelpers.js +1 -0
  177. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  178. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  179. package/lib/javascript/JavascriptGenerator.js +14 -2
  180. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  181. package/lib/javascript/JavascriptParser.js +117 -76
  182. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  183. package/lib/javascript/StartupHelpers.js +17 -17
  184. package/lib/json/JsonGenerator.js +4 -2
  185. package/lib/json/JsonModulesPlugin.js +2 -2
  186. package/lib/json/JsonParser.js +1 -1
  187. package/lib/library/AbstractLibraryPlugin.js +6 -2
  188. package/lib/library/AssignLibraryPlugin.js +21 -6
  189. package/lib/library/EnableLibraryPlugin.js +23 -3
  190. package/lib/library/UmdLibraryPlugin.js +15 -6
  191. package/lib/logging/createConsoleLogger.js +3 -3
  192. package/lib/logging/runtime.js +9 -9
  193. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  194. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  195. package/lib/node/nodeConsole.js +4 -2
  196. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  197. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  198. package/lib/optimize/ConcatenatedModule.js +227 -57
  199. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  200. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  201. package/lib/optimize/InnerGraph.js +115 -112
  202. package/lib/optimize/InnerGraphPlugin.js +2 -2
  203. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  204. package/lib/optimize/MangleExportsPlugin.js +4 -3
  205. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  206. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  207. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  208. package/lib/optimize/RealContentHashPlugin.js +26 -20
  209. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  210. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  211. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  212. package/lib/optimize/SplitChunksPlugin.js +16 -13
  213. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  214. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  215. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  216. package/lib/rules/RuleSetCompiler.js +6 -3
  217. package/lib/rules/UseEffectRulePlugin.js +3 -1
  218. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  219. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  220. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  221. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  222. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  223. package/lib/schemes/FileUriPlugin.js +1 -1
  224. package/lib/schemes/HttpUriPlugin.js +27 -19
  225. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  226. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +5 -4
  228. package/lib/serialization/FileMiddleware.js +7 -4
  229. package/lib/serialization/ObjectMiddleware.js +14 -8
  230. package/lib/serialization/Serializer.js +5 -3
  231. package/lib/serialization/SerializerMiddleware.js +2 -0
  232. package/lib/sharing/ConsumeSharedModule.js +1 -1
  233. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  234. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  235. package/lib/sharing/ProvideSharedModule.js +1 -1
  236. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  237. package/lib/sharing/SharePlugin.js +2 -1
  238. package/lib/sharing/ShareRuntimeModule.js +3 -5
  239. package/lib/sharing/utils.js +34 -34
  240. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  241. package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
  242. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  243. package/lib/stats/StatsFactory.js +4 -2
  244. package/lib/stats/StatsPrinter.js +3 -2
  245. package/lib/url/URLParserPlugin.js +266 -0
  246. package/lib/util/ArrayQueue.js +1 -1
  247. package/lib/util/AsyncQueue.js +1 -1
  248. package/lib/util/Hash.js +2 -0
  249. package/lib/util/IterableHelpers.js +1 -1
  250. package/lib/util/LazyBucketSortedSet.js +2 -1
  251. package/lib/util/LazySet.js +11 -6
  252. package/lib/util/ParallelismFactorCalculator.js +1 -1
  253. package/lib/util/SetHelpers.js +3 -3
  254. package/lib/util/SortableSet.js +2 -2
  255. package/lib/util/StackedCacheMap.js +3 -1
  256. package/lib/util/StackedMap.js +2 -2
  257. package/lib/util/StringXor.js +1 -0
  258. package/lib/util/TupleSet.js +1 -0
  259. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  260. package/lib/util/cleverMerge.js +12 -8
  261. package/lib/util/comparators.js +154 -127
  262. package/lib/util/compileBooleanMatcher.js +8 -3
  263. package/lib/util/concatenate.js +8 -7
  264. package/lib/util/conventions.js +72 -73
  265. package/lib/util/create-schema-validation.js +2 -1
  266. package/lib/util/createHash.js +10 -4
  267. package/lib/util/deprecation.js +69 -66
  268. package/lib/util/deterministicGrouping.js +4 -2
  269. package/lib/util/extractUrlAndGlobal.js +1 -1
  270. package/lib/util/findGraphRoots.js +2 -2
  271. package/lib/util/fs.js +30 -23
  272. package/lib/util/hash/md4.js +2 -2
  273. package/lib/util/hash/wasm-hash.js +4 -2
  274. package/lib/util/identifier.js +13 -12
  275. package/lib/util/internalSerializables.js +2 -0
  276. package/lib/util/magicComment.js +5 -5
  277. package/lib/util/processAsyncTree.js +1 -1
  278. package/lib/util/propertyAccess.js +1 -1
  279. package/lib/util/propertyName.js +1 -1
  280. package/lib/util/registerExternalSerializer.js +1 -2
  281. package/lib/util/removeBOM.js +1 -1
  282. package/lib/util/runtime.js +29 -21
  283. package/lib/util/semver.js +1 -1
  284. package/lib/util/serialization.js +3 -0
  285. package/lib/util/source.js +3 -2
  286. package/lib/validateSchema.js +1 -0
  287. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  288. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  289. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  290. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  291. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  292. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  293. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  294. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  295. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  296. package/lib/webpack.js +4 -5
  297. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  298. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  299. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  300. package/package.json +119 -113
  301. package/schemas/WebpackOptions.check.js +1 -1
  302. package/schemas/WebpackOptions.json +17 -0
  303. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  304. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  306. package/types.d.ts +1230 -360
package/bin/webpack.js CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ "use strict";
4
+
3
5
  /**
4
6
  * @param {string} command process to run
5
7
  * @param {string[]} args command line arguments
@@ -7,6 +9,7 @@
7
9
  */
8
10
  const runCommand = (command, args) => {
9
11
  const cp = require("child_process");
12
+
10
13
  return new Promise((resolve, reject) => {
11
14
  const executedCommand = cp.spawn(command, args, {
12
15
  stdio: "inherit",
@@ -75,7 +78,9 @@ const isInstalled = packageName => {
75
78
  */
76
79
  const runCli = cli => {
77
80
  const path = require("path");
81
+
78
82
  const pkgPath = require.resolve(`${cli.package}/package.json`);
83
+
79
84
  const pkg = require(pkgPath);
80
85
 
81
86
  if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
@@ -171,8 +176,9 @@ if (!cli.installed) {
171
176
  );
172
177
 
173
178
  runCommand(
174
- /** @type {string} */ (packageManager),
175
- installOptions.concat(cli.package)
179
+ /** @type {string} */
180
+ (packageManager),
181
+ [...installOptions, cli.package]
176
182
  )
177
183
  .then(() => {
178
184
  runCli(cli);
package/hot/log.js CHANGED
@@ -45,6 +45,21 @@ module.exports = function (level, msg) {
45
45
  }
46
46
  };
47
47
 
48
+ /**
49
+ * @param {Error} err error
50
+ * @returns {string} formatted error
51
+ */
52
+ module.exports.formatError = function (err) {
53
+ var message = err.message;
54
+ var stack = err.stack;
55
+ if (!stack) {
56
+ return message;
57
+ } else if (stack.indexOf(message) < 0) {
58
+ return message + "\n" + stack;
59
+ }
60
+ return stack;
61
+ };
62
+
48
63
  var group = console.group || dummy;
49
64
  var groupCollapsed = console.groupCollapsed || dummy;
50
65
  var groupEnd = console.groupEnd || dummy;
@@ -61,18 +76,3 @@ module.exports.groupEnd = logGroup(groupEnd);
61
76
  module.exports.setLogLevel = function (level) {
62
77
  logLevel = level;
63
78
  };
64
-
65
- /**
66
- * @param {Error} err error
67
- * @returns {string} formatted error
68
- */
69
- module.exports.formatError = function (err) {
70
- var message = err.message;
71
- var stack = err.stack;
72
- if (!stack) {
73
- return message;
74
- } else if (stack.indexOf(message) < 0) {
75
- return message + "\n" + stack;
76
- }
77
- return stack;
78
- };
package/hot/poll.js CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  /* globals __resourceQuery */
6
6
  if (module.hot) {
7
+ // eslint-disable-next-line no-implicit-coercion
7
8
  var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
8
9
  var log = require("./log");
9
10
 
package/lib/APIPlugin.js CHANGED
@@ -17,8 +17,8 @@ const ConstDependency = require("./dependencies/ConstDependency");
17
17
  const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
18
18
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
19
19
  const {
20
- toConstantDependency,
21
- evaluateToString
20
+ evaluateToString,
21
+ toConstantDependency
22
22
  } = require("./javascript/JavascriptParserHelpers");
23
23
  const ChunkNameRuntimeModule = require("./runtime/ChunkNameRuntimeModule");
24
24
  const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
@@ -179,7 +179,7 @@ class APIPlugin {
179
179
 
180
180
  compilation.hooks.runtimeRequirementInTree
181
181
  .for(RuntimeGlobals.getFullHash)
182
- .tap(PLUGIN_NAME, (chunk, set) => {
182
+ .tap(PLUGIN_NAME, (chunk, _set) => {
183
183
  compilation.addRuntimeModule(chunk, new GetFullHashRuntimeModule());
184
184
  return true;
185
185
  });
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const WebpackError = require("./WebpackError");
9
+
9
10
  const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
10
11
 
11
12
  /**
@@ -62,4 +62,5 @@ class AutomaticPrefetchPlugin {
62
62
  });
63
63
  }
64
64
  }
65
+
65
66
  module.exports = AutomaticPrefetchPlugin;
@@ -20,7 +20,7 @@ const createSchemaValidation = require("./util/create-schema-validation");
20
20
 
21
21
  const validate = createSchemaValidation(
22
22
  /** @type {((value: typeof import("../schemas/plugins/BannerPlugin.json")) => boolean)} */
23
- (require("../schemas/plugins/BannerPlugin.check.js")),
23
+ (require("../schemas/plugins/BannerPlugin.check")),
24
24
  () => require("../schemas/plugins/BannerPlugin.json"),
25
25
  {
26
26
  name: "Banner Plugin",
@@ -35,9 +35,9 @@ const createModulesListMessage = (modules, moduleGraph) =>
35
35
  modules
36
36
  .map(m => {
37
37
  let message = `* ${m.identifier()}`;
38
- const validReasons = Array.from(
39
- moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
40
- ).filter(Boolean);
38
+ const validReasons = [
39
+ ...moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
40
+ ].filter(Boolean);
41
41
 
42
42
  if (validReasons.length > 0) {
43
43
  message += `\n Used by ${validReasons.length} module(s), i. e.`;
@@ -56,7 +56,7 @@ class CaseSensitiveModulesWarning extends WebpackError {
56
56
  * @param {ModuleGraph} moduleGraph the module graph
57
57
  */
58
58
  constructor(modules, moduleGraph) {
59
- const sortedModules = sortModules(Array.from(modules));
59
+ const sortedModules = sortModules([...modules]);
60
60
  const modulesList = createModulesListMessage(sortedModules, moduleGraph);
61
61
  super(`There are multiple modules with names that only differ in casing.
62
62
  This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
package/lib/Chunk.js CHANGED
@@ -11,9 +11,9 @@ const { intersect } = require("./util/SetHelpers");
11
11
  const SortableSet = require("./util/SortableSet");
12
12
  const StringXor = require("./util/StringXor");
13
13
  const {
14
- compareModulesByIdentifier,
15
14
  compareChunkGroupsByIndex,
16
- compareModulesById
15
+ compareModulesById,
16
+ compareModulesByIdentifier
17
17
  } = require("./util/comparators");
18
18
  const { createArrayToSetDeprecationSet } = require("./util/deprecation");
19
19
  const { mergeRuntime } = require("./util/runtime");
@@ -116,13 +116,13 @@ class Chunk {
116
116
  // TODO remove in webpack 6
117
117
  // BACKWARD-COMPAT START
118
118
  get entryModule() {
119
- const entryModules = Array.from(
120
- ChunkGraph.getChunkGraphForChunk(
119
+ const entryModules = [
120
+ ...ChunkGraph.getChunkGraphForChunk(
121
121
  this,
122
122
  "Chunk.entryModule",
123
123
  "DEP_WEBPACK_CHUNK_ENTRY_MODULE"
124
124
  ).getChunkEntryModulesIterable(this)
125
- );
125
+ ];
126
126
  if (entryModules.length === 0) {
127
127
  return undefined;
128
128
  } else if (entryModules.length === 1) {
@@ -747,7 +747,7 @@ class Chunk {
747
747
  }
748
748
  }
749
749
  if (chunkIdSet.size > 0) {
750
- result[name] = Array.from(chunkIdSet);
750
+ result[name] = [...chunkIdSet];
751
751
  }
752
752
  }
753
753
  return result;
package/lib/ChunkGraph.js CHANGED
@@ -12,21 +12,21 @@ const { DEFAULTS } = require("./config/defaults");
12
12
  const { first } = require("./util/SetHelpers");
13
13
  const SortableSet = require("./util/SortableSet");
14
14
  const {
15
- compareModulesById,
15
+ compareIds,
16
16
  compareIterables,
17
+ compareModulesById,
17
18
  compareModulesByIdentifier,
18
- concatComparators,
19
19
  compareSelect,
20
- compareIds
20
+ concatComparators
21
21
  } = require("./util/comparators");
22
22
  const createHash = require("./util/createHash");
23
23
  const findGraphRoots = require("./util/findGraphRoots");
24
24
  const {
25
25
  RuntimeSpecMap,
26
26
  RuntimeSpecSet,
27
- runtimeToString,
27
+ forEachRuntime,
28
28
  mergeRuntime,
29
- forEachRuntime
29
+ runtimeToString
30
30
  } = require("./util/runtime");
31
31
 
32
32
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
@@ -76,7 +76,7 @@ class ModuleHashInfo {
76
76
  * @param {SortableSet<T>} set the set
77
77
  * @returns {T[]} set as array
78
78
  */
79
- const getArray = set => Array.from(set);
79
+ const getArray = set => [...set];
80
80
 
81
81
  /**
82
82
  * @param {SortableSet<Chunk>} chunks the chunks
@@ -141,7 +141,7 @@ const createOrderedArrayFunction = comparator => {
141
141
  if (fn !== undefined) return fn;
142
142
  fn = set => {
143
143
  set.sortWith(comparator);
144
- return Array.from(set);
144
+ return [...set];
145
145
  };
146
146
  createOrderedArrayFunctionMap.set(comparator, fn);
147
147
  return fn;
@@ -310,8 +310,8 @@ class ChunkGraph {
310
310
  */
311
311
  _getGraphRoots(set) {
312
312
  const { moduleGraph } = this;
313
- return Array.from(
314
- findGraphRoots(set, module => {
313
+ return [
314
+ ...findGraphRoots(set, module => {
315
315
  /** @type {Set<Module>} */
316
316
  const set = new Set();
317
317
  /**
@@ -332,7 +332,7 @@ class ChunkGraph {
332
332
  addDependencies(module);
333
333
  return set;
334
334
  })
335
- ).sort(compareModulesByIdentifier);
335
+ ].sort(compareModulesByIdentifier);
336
336
  }
337
337
 
338
338
  /**
@@ -420,8 +420,9 @@ class ChunkGraph {
420
420
  */
421
421
  attachDependentHashModules(chunk, modules) {
422
422
  const cgc = this._getChunkGraphChunk(chunk);
423
- if (cgc.dependentHashModules === undefined)
423
+ if (cgc.dependentHashModules === undefined) {
424
424
  cgc.dependentHashModules = new Set();
425
+ }
425
426
  for (const module of modules) {
426
427
  cgc.dependentHashModules.add(module);
427
428
  }
@@ -1021,9 +1022,10 @@ class ChunkGraph {
1021
1022
  this.connectChunkAndModule(chunkA, module);
1022
1023
  }
1023
1024
 
1024
- for (const [module, chunkGroup] of Array.from(
1025
- this.getChunkEntryModulesWithChunkGroupIterable(chunkB)
1026
- )) {
1025
+ for (const [
1026
+ module,
1027
+ chunkGroup
1028
+ ] of this.getChunkEntryModulesWithChunkGroupIterable(chunkB)) {
1027
1029
  this.disconnectChunkAndEntryModule(chunkB, module);
1028
1030
  this.connectChunkAndEntryModule(
1029
1031
  chunkA,
@@ -1117,8 +1119,9 @@ class ChunkGraph {
1117
1119
  */
1118
1120
  addDependentHashModuleToChunk(chunk, module) {
1119
1121
  const cgc = this._getChunkGraphChunk(chunk);
1120
- if (cgc.dependentHashModules === undefined)
1122
+ if (cgc.dependentHashModules === undefined) {
1121
1123
  cgc.dependentHashModules = new Set();
1124
+ }
1122
1125
  cgc.dependentHashModules.add(module);
1123
1126
  }
1124
1127
 
@@ -1266,7 +1269,7 @@ class ChunkGraph {
1266
1269
  */
1267
1270
  getChunkRuntimeModulesInOrder(chunk) {
1268
1271
  const cgc = this._getChunkGraphChunk(chunk);
1269
- const array = Array.from(cgc.runtimeModules);
1272
+ const array = [...cgc.runtimeModules];
1270
1273
  array.sort(
1271
1274
  concatComparators(
1272
1275
  compareSelect(r => /** @type {RuntimeModule} */ (r).stage, compareIds),
@@ -1646,8 +1649,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1646
1649
  const module = connection.module;
1647
1650
  stateInfo += module.getExportsType(this.moduleGraph, strict);
1648
1651
  // cspell:word Tnamespace
1649
- if (stateInfo === "Tnamespace") activeNamespaceModules.add(module);
1650
- else {
1652
+ if (stateInfo === "Tnamespace") {
1653
+ activeNamespaceModules.add(module);
1654
+ } else {
1651
1655
  const oldModule = connectedModules.get(stateInfo);
1652
1656
  if (oldModule === undefined) {
1653
1657
  connectedModules.set(stateInfo, module);
@@ -1687,11 +1691,12 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1687
1691
  }
1688
1692
  }
1689
1693
  // cspell:word Tnamespace
1690
- if (activeNamespaceModules.size === 0 && connectedModules.size === 0)
1694
+ if (activeNamespaceModules.size === 0 && connectedModules.size === 0) {
1691
1695
  return graphHash;
1696
+ }
1692
1697
  const connectedModulesInOrder =
1693
1698
  connectedModules.size > 1
1694
- ? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1))
1699
+ ? [...connectedModules].sort(([a], [b]) => (a < b ? -1 : 1))
1695
1700
  : connectedModules;
1696
1701
  const hash = createHash(this._hashFunction);
1697
1702
  /**
@@ -1712,22 +1717,21 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1712
1717
  const addModulesToHash = modules => {
1713
1718
  let xor = ZERO_BIG_INT;
1714
1719
  for (const m of modules) {
1715
- xor =
1716
- xor ^
1717
- this._getModuleGraphHashBigInt(
1718
- this._getChunkGraphModule(m),
1719
- m,
1720
- runtime
1721
- );
1720
+ xor ^= this._getModuleGraphHashBigInt(
1721
+ this._getChunkGraphModule(m),
1722
+ m,
1723
+ runtime
1724
+ );
1722
1725
  }
1723
1726
  hash.update(xor.toString(16));
1724
1727
  };
1725
- if (activeNamespaceModules.size === 1)
1728
+ if (activeNamespaceModules.size === 1) {
1726
1729
  addModuleToHash(
1727
1730
  /** @type {Module} */ (activeNamespaceModules.values().next().value)
1728
1731
  );
1729
- else if (activeNamespaceModules.size > 1)
1732
+ } else if (activeNamespaceModules.size > 1) {
1730
1733
  addModulesToHash(activeNamespaceModules);
1734
+ }
1731
1735
  for (const [stateInfo, modules] of connectedModulesInOrder) {
1732
1736
  hash.update(stateInfo);
1733
1737
  if (modules instanceof Set) {
@@ -1767,12 +1771,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1767
1771
  */
1768
1772
  module => {
1769
1773
  const chunkGraph = chunkGraphForModuleMap.get(module);
1770
- if (!chunkGraph)
1774
+ if (!chunkGraph) {
1771
1775
  throw new Error(
1772
1776
  `${
1773
1777
  deprecateMessage
1774
1778
  }: There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)`
1775
1779
  );
1780
+ }
1776
1781
  return chunkGraph;
1777
1782
  },
1778
1783
  `${deprecateMessage}: Use new ChunkGraph API`,
@@ -1818,12 +1823,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1818
1823
  */
1819
1824
  chunk => {
1820
1825
  const chunkGraph = chunkGraphForChunkMap.get(chunk);
1821
- if (!chunkGraph)
1826
+ if (!chunkGraph) {
1822
1827
  throw new Error(
1823
1828
  `${
1824
1829
  deprecateMessage
1825
1830
  }There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)`
1826
1831
  );
1832
+ }
1827
1833
  return chunkGraph;
1828
1834
  },
1829
1835
  `${deprecateMessage}: Use new ChunkGraph API`,
package/lib/ChunkGroup.js CHANGED
@@ -8,9 +8,9 @@
8
8
  const util = require("util");
9
9
  const SortableSet = require("./util/SortableSet");
10
10
  const {
11
- compareLocations,
12
11
  compareChunks,
13
- compareIterables
12
+ compareIterables,
13
+ compareLocations
14
14
  } = require("./util/comparators");
15
15
 
16
16
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
@@ -40,7 +40,7 @@ let debugId = 5000;
40
40
  * @param {SortableSet<T>} set set to convert to array.
41
41
  * @returns {T[]} the array format of existing set
42
42
  */
43
- const getArray = set => Array.from(set);
43
+ const getArray = set => [...set];
44
44
 
45
45
  /**
46
46
  * A convenience method used to sort chunks based on their id's
@@ -436,7 +436,7 @@ class ChunkGroup {
436
436
  }
437
437
  }
438
438
 
439
- return Array.from(files);
439
+ return [...files];
440
440
  }
441
441
 
442
442
  /**
@@ -170,7 +170,7 @@ Object.defineProperty(ChunkTemplate.prototype, "outputOptions", {
170
170
  * @this {ChunkTemplate}
171
171
  * @returns {OutputOptions} output options
172
172
  */
173
- function () {
173
+ function outputOptions() {
174
174
  return this._outputOptions;
175
175
  },
176
176
  "ChunkTemplate.outputOptions is deprecated (use Compilation.outputOptions instead)",
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const path = require("path");
8
9
  const asyncLib = require("neo-async");
9
10
  const { SyncBailHook } = require("tapable");
10
11
  const Compilation = require("./Compilation");
@@ -36,6 +37,7 @@ const validate = createSchemaValidation(
36
37
  undefined,
37
38
  () => {
38
39
  const { definitions } = require("../schemas/WebpackOptions.json");
40
+
39
41
  return {
40
42
  definitions,
41
43
  oneOf: [{ $ref: "#/definitions/CleanOptions" }]
@@ -61,6 +63,62 @@ const mergeAssets = (as1, as2) => {
61
63
  }
62
64
  };
63
65
 
66
+ /**
67
+ * @param {Map<string, number>} assets current assets
68
+ * @returns {Set<string>} Set of directory paths
69
+ */
70
+ function getDirectories(assets) {
71
+ const directories = new Set();
72
+ /**
73
+ * @param {string} filename asset filename
74
+ */
75
+ const addDirectory = filename => {
76
+ directories.add(path.dirname(filename));
77
+ };
78
+
79
+ // get directories of assets
80
+ for (const [asset] of assets) {
81
+ addDirectory(asset);
82
+ }
83
+ // and all parent directories
84
+ for (const directory of directories) {
85
+ addDirectory(directory);
86
+ }
87
+ return directories;
88
+ }
89
+
90
+ /**
91
+ * @param {string} a First directory path to compare
92
+ * @param {string} b Second directory path to compare
93
+ * @returns {boolean} True if both paths have the same parent directory
94
+ */
95
+ function isEqualPath(a, b) {
96
+ return path.normalize(a) === path.normalize(b);
97
+ }
98
+
99
+ /**
100
+ * @param {Map<string, number>|Set<string>} files Collection of files to check against
101
+ * @param {string} file File path to check
102
+ * @returns {boolean} True if the file or its parent exists in the collection
103
+ */
104
+ function hasFile(files, file) {
105
+ if (files instanceof Set) {
106
+ for (const dir of files) {
107
+ if (isEqualPath(dir, file)) {
108
+ return true;
109
+ }
110
+ }
111
+ }
112
+ if (files instanceof Map) {
113
+ for (const dir of files.keys()) {
114
+ if (isEqualPath(dir, file)) {
115
+ return true;
116
+ }
117
+ }
118
+ }
119
+ return false;
120
+ }
121
+
64
122
  /** @typedef {Set<string>} Diff */
65
123
 
66
124
  /**
@@ -71,15 +129,7 @@ const mergeAssets = (as1, as2) => {
71
129
  * @returns {void}
72
130
  */
73
131
  const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
74
- const directories = new Set();
75
- // get directories of assets
76
- for (const [asset] of currentAssets) {
77
- directories.add(asset.replace(/(^|\/)[^/]*$/, ""));
78
- }
79
- // and all parent directories
80
- for (const directory of directories) {
81
- directories.add(directory.replace(/(^|\/)[^/]*$/, ""));
82
- }
132
+ const directories = getDirectories(currentAssets);
83
133
  const diff = new Set();
84
134
  asyncLib.forEachLimit(
85
135
  directories,
@@ -98,7 +148,10 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
98
148
  for (const entry of /** @type {string[]} */ (entries)) {
99
149
  const file = entry;
100
150
  const filename = directory ? `${directory}/${file}` : file;
101
- if (!directories.has(filename) && !currentAssets.has(filename)) {
151
+ if (
152
+ !hasFile(directories, filename) &&
153
+ !hasFile(currentAssets, filename)
154
+ ) {
102
155
  diff.add(filename);
103
156
  }
104
157
  }
@@ -177,22 +230,43 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
177
230
  jobs,
178
231
  10,
179
232
  ({ type, filename, parent }, push, callback) => {
233
+ const path = join(fs, outputPath, filename);
180
234
  /**
181
235
  * @param {Error & { code?: string }} err error
182
236
  * @returns {void}
183
237
  */
184
238
  const handleError = err => {
185
- if (err.code === "ENOENT") {
186
- log(`${filename} was removed during cleaning by something else`);
187
- handleParent();
188
- return callback();
189
- }
190
- return callback(err);
239
+ const isAlreadyRemoved = () =>
240
+ new Promise(resolve => {
241
+ if (err.code === "ENOENT") {
242
+ resolve(true);
243
+ } else if (err.code === "EPERM") {
244
+ // https://github.com/isaacs/rimraf/blob/main/src/fix-eperm.ts#L37
245
+ // fs.existsSync(path) === false https://github.com/webpack/webpack/actions/runs/15493412975/job/43624272783?pr=19586
246
+ doStat(fs, path, err => {
247
+ if (err) {
248
+ resolve(err.code === "ENOENT");
249
+ } else {
250
+ resolve(false);
251
+ }
252
+ });
253
+ } else {
254
+ resolve(false);
255
+ }
256
+ });
257
+
258
+ isAlreadyRemoved().then(isRemoved => {
259
+ if (isRemoved) {
260
+ log(`${filename} was removed during cleaning by something else`);
261
+ handleParent();
262
+ return callback();
263
+ }
264
+ return callback(err);
265
+ });
191
266
  };
192
267
  const handleParent = () => {
193
268
  if (parent && --parent.remaining === 0) push(parent.job);
194
269
  };
195
- const path = join(fs, outputPath, filename);
196
270
  switch (type) {
197
271
  case "check":
198
272
  if (isKept(filename)) {
@@ -443,3 +517,6 @@ class CleanPlugin {
443
517
  }
444
518
 
445
519
  module.exports = CleanPlugin;
520
+ module.exports._getDirectories = getDirectories;
521
+ module.exports._hasFile = hasFile;
522
+ module.exports._isEqualPath = isEqualPath;
@@ -9,7 +9,7 @@ const { DEFAULTS } = require("./config/defaults");
9
9
  const { getOrInsert } = require("./util/MapHelpers");
10
10
  const { first } = require("./util/SetHelpers");
11
11
  const createHash = require("./util/createHash");
12
- const { runtimeToString, RuntimeSpecMap } = require("./util/runtime");
12
+ const { RuntimeSpecMap, runtimeToString } = require("./util/runtime");
13
13
 
14
14
  /** @typedef {import("webpack-sources").Source} Source */
15
15
  /** @typedef {import("./Module")} Module */
@@ -44,8 +44,9 @@ class CompatibilityPlugin {
44
44
  if (
45
45
  parserOptions.browserify !== undefined &&
46
46
  !parserOptions.browserify
47
- )
47
+ ) {
48
48
  return;
49
+ }
49
50
 
50
51
  parser.hooks.call.for("require").tap(
51
52
  PLUGIN_NAME,
@@ -75,8 +76,9 @@ class CompatibilityPlugin {
75
76
  last.options.request === "." &&
76
77
  last.userRequest === "." &&
77
78
  last.options.recursive
78
- )
79
+ ) {
79
80
  parser.state.current.dependencies.pop();
81
+ }
80
82
  }
81
83
  parser.state.module.addPresentationalDependency(dep);
82
84
  return true;
@@ -191,4 +193,5 @@ class CompatibilityPlugin {
191
193
  );
192
194
  }
193
195
  }
196
+
194
197
  module.exports = CompatibilityPlugin;