webpack 5.100.2 → 5.101.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 (309) hide show
  1. package/README.md +12 -10
  2. package/bin/webpack.js +7 -7
  3. package/lib/APIPlugin.js +12 -14
  4. package/lib/AutomaticPrefetchPlugin.js +2 -2
  5. package/lib/BannerPlugin.js +4 -4
  6. package/lib/Cache.js +1 -1
  7. package/lib/CacheFacade.js +7 -7
  8. package/lib/CaseSensitiveModulesWarning.js +2 -2
  9. package/lib/Chunk.js +3 -3
  10. package/lib/ChunkGraph.js +63 -18
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/CleanPlugin.js +19 -53
  13. package/lib/CodeGenerationResults.js +3 -3
  14. package/lib/CompatibilityPlugin.js +6 -6
  15. package/lib/Compilation.js +168 -116
  16. package/lib/Compiler.js +37 -37
  17. package/lib/ConcatenationScope.js +39 -1
  18. package/lib/ConstPlugin.js +11 -11
  19. package/lib/ContextExclusionPlugin.js +3 -3
  20. package/lib/ContextModule.js +12 -11
  21. package/lib/ContextModuleFactory.js +11 -11
  22. package/lib/ContextReplacementPlugin.js +5 -5
  23. package/lib/DefinePlugin.js +24 -22
  24. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  25. package/lib/Dependency.js +2 -1
  26. package/lib/DllEntryPlugin.js +1 -1
  27. package/lib/DllReferencePlugin.js +1 -1
  28. package/lib/DynamicEntryPlugin.js +3 -3
  29. package/lib/EntryPlugin.js +1 -1
  30. package/lib/EnvironmentPlugin.js +1 -1
  31. package/lib/ErrorHelpers.js +2 -2
  32. package/lib/EvalDevToolModulePlugin.js +2 -2
  33. package/lib/EvalSourceMapDevToolPlugin.js +5 -5
  34. package/lib/ExportsInfo.js +9 -9
  35. package/lib/ExportsInfoApiPlugin.js +2 -2
  36. package/lib/ExternalModule.js +163 -48
  37. package/lib/ExternalModuleFactoryPlugin.js +2 -2
  38. package/lib/ExternalsPlugin.js +45 -0
  39. package/lib/FileSystemInfo.js +64 -61
  40. package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
  41. package/lib/FlagDependencyExportsPlugin.js +7 -7
  42. package/lib/FlagDependencyUsagePlugin.js +4 -4
  43. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  44. package/lib/HotModuleReplacementPlugin.js +27 -27
  45. package/lib/IgnorePlugin.js +3 -3
  46. package/lib/IgnoreWarningsPlugin.js +4 -4
  47. package/lib/InitFragment.js +6 -0
  48. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  49. package/lib/JavascriptMetaInfoPlugin.js +1 -1
  50. package/lib/LibManifestPlugin.js +2 -2
  51. package/lib/LoaderOptionsPlugin.js +1 -1
  52. package/lib/LoaderTargetPlugin.js +2 -2
  53. package/lib/MainTemplate.js +1 -1
  54. package/lib/Module.js +3 -2
  55. package/lib/ModuleFilenameHelpers.js +3 -3
  56. package/lib/ModuleGraph.js +23 -38
  57. package/lib/ModuleInfoHeaderPlugin.js +3 -3
  58. package/lib/ModuleParseError.js +5 -3
  59. package/lib/ModuleTemplate.js +3 -2
  60. package/lib/MultiCompiler.js +29 -24
  61. package/lib/MultiStats.js +18 -13
  62. package/lib/MultiWatching.js +1 -1
  63. package/lib/NoEmitOnErrorsPlugin.js +2 -2
  64. package/lib/NodeStuffPlugin.js +27 -15
  65. package/lib/NormalModule.js +23 -23
  66. package/lib/NormalModuleFactory.js +23 -21
  67. package/lib/NormalModuleReplacementPlugin.js +3 -3
  68. package/lib/PrefetchPlugin.js +1 -1
  69. package/lib/ProgressPlugin.js +11 -11
  70. package/lib/ProvidePlugin.js +2 -2
  71. package/lib/RecordIdsPlugin.js +3 -3
  72. package/lib/ResolverFactory.js +3 -3
  73. package/lib/RuntimeGlobals.js +20 -0
  74. package/lib/RuntimePlugin.js +16 -16
  75. package/lib/RuntimeTemplate.js +35 -26
  76. package/lib/SizeFormatHelpers.js +1 -1
  77. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -4
  78. package/lib/SourceMapDevToolPlugin.js +9 -9
  79. package/lib/Stats.js +2 -2
  80. package/lib/Template.js +1 -1
  81. package/lib/TemplatedPathPlugin.js +2 -2
  82. package/lib/UseStrictPlugin.js +1 -1
  83. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -1
  84. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  85. package/lib/WarnNoModeSetPlugin.js +1 -1
  86. package/lib/WatchIgnorePlugin.js +2 -2
  87. package/lib/Watching.js +12 -14
  88. package/lib/WebpackIsIncludedPlugin.js +2 -2
  89. package/lib/WebpackOptionsApply.js +3 -3
  90. package/lib/asset/AssetGenerator.js +1 -1
  91. package/lib/asset/AssetModulesPlugin.js +6 -6
  92. package/lib/async-modules/AsyncModuleHelpers.js +1 -1
  93. package/lib/async-modules/AwaitDependenciesInitFragment.js +36 -24
  94. package/lib/async-modules/InferAsyncModulesPlugin.js +3 -3
  95. package/lib/buildChunkGraph.js +5 -5
  96. package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
  97. package/lib/cache/IdleFileCachePlugin.js +5 -5
  98. package/lib/cache/PackFileCacheStrategy.js +20 -20
  99. package/lib/cache/ResolverCachePlugin.js +4 -4
  100. package/lib/cli.js +196 -14
  101. package/lib/config/browserslistTargetHandler.js +6 -6
  102. package/lib/config/defaults.js +23 -14
  103. package/lib/config/normalization.js +41 -38
  104. package/lib/config/target.js +4 -4
  105. package/lib/container/ContainerEntryModule.js +3 -3
  106. package/lib/container/ContainerPlugin.js +3 -3
  107. package/lib/container/ContainerReferencePlugin.js +3 -3
  108. package/lib/container/FallbackModule.js +1 -1
  109. package/lib/container/HoistContainerReferencesPlugin.js +7 -7
  110. package/lib/container/options.js +4 -4
  111. package/lib/css/CssGenerator.js +5 -3
  112. package/lib/css/CssLoadingRuntimeModule.js +1 -1
  113. package/lib/css/CssModulesPlugin.js +25 -22
  114. package/lib/css/CssParser.js +5 -5
  115. package/lib/css/walkCssTokens.js +9 -9
  116. package/lib/debug/ProfilingPlugin.js +5 -5
  117. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -4
  118. package/lib/dependencies/AMDPlugin.js +3 -3
  119. package/lib/dependencies/AMDRequireArrayDependency.js +1 -1
  120. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +3 -3
  121. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -2
  122. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -10
  123. package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -19
  124. package/lib/dependencies/CommonJsPlugin.js +2 -2
  125. package/lib/dependencies/ContextDependency.js +1 -1
  126. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  127. package/lib/dependencies/CssIcssExportDependency.js +2 -2
  128. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  129. package/lib/dependencies/CssUrlDependency.js +4 -4
  130. package/lib/dependencies/DynamicExports.js +5 -5
  131. package/lib/dependencies/HarmonyAcceptDependency.js +91 -5
  132. package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
  133. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +17 -13
  134. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -8
  135. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  136. package/lib/dependencies/HarmonyExports.js +1 -1
  137. package/lib/dependencies/HarmonyImportDependency.js +28 -9
  138. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +56 -48
  139. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -5
  140. package/lib/dependencies/HarmonyImportSpecifierDependency.js +3 -4
  141. package/lib/dependencies/HarmonyModulesPlugin.js +2 -8
  142. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  143. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -4
  144. package/lib/dependencies/ImportMetaPlugin.js +7 -7
  145. package/lib/dependencies/ImportParserPlugin.js +4 -4
  146. package/lib/dependencies/JsonExportsDependency.js +7 -2
  147. package/lib/dependencies/LoaderPlugin.js +4 -4
  148. package/lib/dependencies/ModuleDependency.js +2 -1
  149. package/lib/dependencies/ProvidedDependency.js +2 -2
  150. package/lib/dependencies/PureExpressionDependency.js +1 -1
  151. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  152. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
  153. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -3
  154. package/lib/dependencies/SystemPlugin.js +3 -3
  155. package/lib/dependencies/WorkerPlugin.js +5 -5
  156. package/lib/dependencies/getFunctionExpression.js +1 -1
  157. package/lib/esm/ExportWebpackRequireRuntimeModule.js +8 -1
  158. package/lib/esm/ModuleChunkFormatPlugin.js +35 -69
  159. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -6
  160. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -11
  161. package/lib/formatLocation.js +2 -2
  162. package/lib/hmr/HotModuleReplacement.runtime.js +39 -27
  163. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -32
  164. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -1
  165. package/lib/hmr/LazyCompilationPlugin.js +6 -6
  166. package/lib/hmr/lazyCompilationBackend.js +6 -6
  167. package/lib/ids/ChunkModuleIdRangePlugin.js +4 -4
  168. package/lib/ids/DeterministicChunkIdsPlugin.js +5 -4
  169. package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
  170. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  171. package/lib/ids/IdHelpers.js +9 -9
  172. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  173. package/lib/ids/NamedModuleIdsPlugin.js +2 -2
  174. package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
  175. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  176. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  177. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -4
  178. package/lib/ids/SyncModuleIdsPlugin.js +4 -4
  179. package/lib/index.js +18 -6
  180. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
  181. package/lib/javascript/BasicEvaluatedExpression.js +3 -3
  182. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  183. package/lib/javascript/CommonJsChunkFormatPlugin.js +10 -21
  184. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -1
  185. package/lib/javascript/JavascriptGenerator.js +1 -1
  186. package/lib/javascript/JavascriptModulesPlugin.js +108 -54
  187. package/lib/javascript/JavascriptParser.js +80 -78
  188. package/lib/javascript/JavascriptParserHelpers.js +3 -3
  189. package/lib/javascript/StartupHelpers.js +2 -2
  190. package/lib/json/JsonGenerator.js +2 -2
  191. package/lib/json/JsonModulesPlugin.js +2 -2
  192. package/lib/library/AbstractLibraryPlugin.js +30 -3
  193. package/lib/library/AmdLibraryPlugin.js +3 -3
  194. package/lib/library/AssignLibraryPlugin.js +2 -2
  195. package/lib/library/EnableLibraryPlugin.js +2 -2
  196. package/lib/library/ModuleLibraryPlugin.js +49 -31
  197. package/lib/library/SystemLibraryPlugin.js +6 -4
  198. package/lib/library/UmdLibraryPlugin.js +14 -14
  199. package/lib/logging/createConsoleLogger.js +4 -4
  200. package/lib/logging/runtime.js +3 -3
  201. package/lib/logging/truncateArgs.js +4 -4
  202. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
  203. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  204. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +16 -14
  205. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +7 -7
  206. package/lib/node/ReadFileCompileWasmPlugin.js +7 -7
  207. package/lib/node/RequireChunkLoadingRuntimeModule.js +13 -6
  208. package/lib/node/nodeConsole.js +2 -2
  209. package/lib/optimize/AggressiveMergingPlugin.js +2 -2
  210. package/lib/optimize/AggressiveSplittingPlugin.js +10 -10
  211. package/lib/optimize/ConcatenatedModule.js +186 -77
  212. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -2
  213. package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
  214. package/lib/optimize/InnerGraph.js +5 -5
  215. package/lib/optimize/InnerGraphPlugin.js +14 -12
  216. package/lib/optimize/LimitChunkCountPlugin.js +5 -5
  217. package/lib/optimize/MangleExportsPlugin.js +5 -5
  218. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  219. package/lib/optimize/MinChunkSizePlugin.js +3 -3
  220. package/lib/optimize/ModuleConcatenationPlugin.js +45 -38
  221. package/lib/optimize/RealContentHashPlugin.js +23 -23
  222. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
  223. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  224. package/lib/optimize/RuntimeChunkPlugin.js +2 -2
  225. package/lib/optimize/SideEffectsFlagPlugin.js +5 -5
  226. package/lib/optimize/SplitChunksPlugin.js +20 -20
  227. package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
  228. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  229. package/lib/performance/SizeLimitsPlugin.js +4 -4
  230. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
  231. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -3
  232. package/lib/rules/BasicMatcherRulePlugin.js +1 -1
  233. package/lib/rules/RuleSetCompiler.js +10 -10
  234. package/lib/rules/UseEffectRulePlugin.js +2 -2
  235. package/lib/runtime/GetChunkFilenameRuntimeModule.js +19 -15
  236. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  237. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  238. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
  239. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
  240. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
  241. package/lib/schemes/DataUriPlugin.js +3 -3
  242. package/lib/schemes/FileUriPlugin.js +1 -1
  243. package/lib/schemes/HttpUriPlugin.js +40 -36
  244. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  245. package/lib/serialization/BinaryMiddleware.js +11 -11
  246. package/lib/serialization/FileMiddleware.js +18 -17
  247. package/lib/serialization/ObjectMiddleware.js +8 -8
  248. package/lib/serialization/Serializer.js +2 -2
  249. package/lib/serialization/SerializerMiddleware.js +2 -2
  250. package/lib/sharing/ConsumeSharedPlugin.js +4 -4
  251. package/lib/sharing/ProvideSharedPlugin.js +4 -4
  252. package/lib/sharing/SharePlugin.js +1 -1
  253. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  254. package/lib/stats/DefaultStatsFactoryPlugin.js +85 -80
  255. package/lib/stats/DefaultStatsPresetPlugin.js +15 -15
  256. package/lib/stats/DefaultStatsPrinterPlugin.js +87 -87
  257. package/lib/stats/StatsFactory.js +7 -7
  258. package/lib/stats/StatsPrinter.js +9 -9
  259. package/lib/url/URLParserPlugin.js +5 -5
  260. package/lib/util/AsyncQueue.js +4 -4
  261. package/lib/util/IterableHelpers.js +2 -2
  262. package/lib/util/LazyBucketSortedSet.js +3 -3
  263. package/lib/util/SetHelpers.js +2 -2
  264. package/lib/util/StackedCacheMap.js +1 -1
  265. package/lib/util/StackedMap.js +1 -1
  266. package/lib/util/TupleSet.js +1 -1
  267. package/lib/util/WeakTupleMap.js +1 -1
  268. package/lib/util/cleverMerge.js +8 -8
  269. package/lib/util/comparators.js +10 -10
  270. package/lib/util/compileBooleanMatcher.js +20 -20
  271. package/lib/util/concatenate.js +3 -3
  272. package/lib/util/conventions.js +4 -4
  273. package/lib/util/create-schema-validation.js +1 -1
  274. package/lib/util/createHash.js +1 -1
  275. package/lib/util/deprecation.js +4 -4
  276. package/lib/util/deterministicGrouping.js +7 -7
  277. package/lib/util/findGraphRoots.js +1 -1
  278. package/lib/util/fs.js +4 -4
  279. package/lib/util/identifier.js +14 -14
  280. package/lib/util/magicComment.js +5 -1
  281. package/lib/util/memoize.js +1 -1
  282. package/lib/util/processAsyncTree.js +2 -2
  283. package/lib/util/propertyName.js +1 -1
  284. package/lib/util/removeBOM.js +1 -1
  285. package/lib/util/runtime.js +6 -6
  286. package/lib/util/semver.js +16 -16
  287. package/lib/util/serialization.js +5 -5
  288. package/lib/util/smartGrouping.js +1 -1
  289. package/lib/validateSchema.js +2 -2
  290. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
  291. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  292. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  293. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -4
  294. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -9
  295. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
  296. package/lib/wasm-sync/WebAssemblyGenerator.js +16 -17
  297. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -2
  298. package/lib/wasm-sync/WebAssemblyParser.js +2 -2
  299. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
  300. package/lib/web/FetchCompileWasmPlugin.js +4 -4
  301. package/lib/web/JsonpChunkLoadingPlugin.js +2 -2
  302. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  303. package/lib/webpack.js +17 -12
  304. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -2
  305. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  306. package/package.json +16 -16
  307. package/schemas/WebpackOptions.check.js +1 -1
  308. package/schemas/WebpackOptions.json +4 -0
  309. package/types.d.ts +275 -64
package/lib/cli.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const path = require("path");
9
+ const tty = require("tty");
9
10
  const webpackSchema = require("../schemas/WebpackOptions.json");
10
11
 
11
12
  /** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */
@@ -82,7 +83,7 @@ const getArguments = (schema = webpackSchema) => {
82
83
  * @param {string} input input
83
84
  * @returns {string} result
84
85
  */
85
- const pathToArgumentName = input =>
86
+ const pathToArgumentName = (input) =>
86
87
  input
87
88
  .replace(/\./g, "-")
88
89
  .replace(/\[\]/g, "")
@@ -97,7 +98,7 @@ const getArguments = (schema = webpackSchema) => {
97
98
  * @param {string} path path
98
99
  * @returns {Schema} schema part
99
100
  */
100
- const getSchemaPart = path => {
101
+ const getSchemaPart = (path) => {
101
102
  const newPath = path.split("/");
102
103
 
103
104
  let schemaPart = schema;
@@ -119,7 +120,7 @@ const getArguments = (schema = webpackSchema) => {
119
120
  * @param {PathItem[]} path path in the schema
120
121
  * @returns {string | undefined} description
121
122
  */
122
- const getDescription = path => {
123
+ const getDescription = (path) => {
123
124
  for (const { schema } of path) {
124
125
  if (schema.cli) {
125
126
  if (schema.cli.helper) continue;
@@ -133,7 +134,7 @@ const getArguments = (schema = webpackSchema) => {
133
134
  * @param {PathItem[]} path path in the schema
134
135
  * @returns {string | undefined} negative description
135
136
  */
136
- const getNegatedDescription = path => {
137
+ const getNegatedDescription = (path) => {
137
138
  for (const { schema } of path) {
138
139
  if (schema.cli) {
139
140
  if (schema.cli.helper) continue;
@@ -146,7 +147,7 @@ const getArguments = (schema = webpackSchema) => {
146
147
  * @param {PathItem[]} path path in the schema
147
148
  * @returns {string | undefined} reset description
148
149
  */
149
- const getResetDescription = path => {
150
+ const getResetDescription = (path) => {
150
151
  for (const { schema } of path) {
151
152
  if (schema.cli) {
152
153
  if (schema.cli.helper) continue;
@@ -159,7 +160,7 @@ const getArguments = (schema = webpackSchema) => {
159
160
  * @param {Schema} schemaPart schema
160
161
  * @returns {Pick<ArgumentConfig, "type" | "values"> | undefined} partial argument config
161
162
  */
162
- const schemaToArgumentConfig = schemaPart => {
163
+ const schemaToArgumentConfig = (schemaPart) => {
163
164
  if (schemaPart.enum) {
164
165
  return {
165
166
  type: "enum",
@@ -192,7 +193,7 @@ const getArguments = (schema = webpackSchema) => {
192
193
  * @param {PathItem[]} path path in the schema
193
194
  * @returns {void}
194
195
  */
195
- const addResetFlag = path => {
196
+ const addResetFlag = (path) => {
196
197
  const schemaPath = path[0].path;
197
198
  const name = pathToArgumentName(`${schemaPath}.reset`);
198
199
  const description =
@@ -253,7 +254,7 @@ const getArguments = (schema = webpackSchema) => {
253
254
 
254
255
  if (
255
256
  flags[name].configs.some(
256
- item => JSON.stringify(item) === JSON.stringify(argConfig)
257
+ (item) => JSON.stringify(item) === JSON.stringify(argConfig)
257
258
  )
258
259
  ) {
259
260
  return 0;
@@ -261,7 +262,7 @@ const getArguments = (schema = webpackSchema) => {
261
262
 
262
263
  if (
263
264
  flags[name].configs.some(
264
- item => item.type === argConfig.type && item.multiple !== multiple
265
+ (item) => item.type === argConfig.type && item.multiple !== multiple
265
266
  )
266
267
  ) {
267
268
  if (multiple) {
@@ -411,8 +412,8 @@ const getArguments = (schema = webpackSchema) => {
411
412
  /** @type {NonNullable<ArgumentConfig["values"]>} */
412
413
  (argConfig.values);
413
414
 
414
- if (values.every(v => typeof v === "boolean")) type = "boolean";
415
- if (values.every(v => typeof v === "number")) type = "number";
415
+ if (values.every((v) => typeof v === "boolean")) type = "boolean";
416
+ if (values.every((v) => typeof v === "number")) type = "number";
416
417
  break;
417
418
  }
418
419
  }
@@ -420,7 +421,7 @@ const getArguments = (schema = webpackSchema) => {
420
421
  return t === type ? t : "string";
421
422
  }, /** @type {SimpleType | undefined} */ (undefined))
422
423
  );
423
- argument.multiple = argument.configs.some(c => c.multiple);
424
+ argument.multiple = argument.configs.some((c) => c.multiple);
424
425
  }
425
426
 
426
427
  return flags;
@@ -580,7 +581,7 @@ const processArgumentConfig = (argConfig, config, value, index) => {
580
581
  * @param {ArgumentConfig} argConfig processing instructions
581
582
  * @returns {string | undefined} expected message
582
583
  */
583
- const getExpectedValue = argConfig => {
584
+ const getExpectedValue = (argConfig) => {
584
585
  switch (argConfig.type) {
585
586
  case "boolean":
586
587
  return "true | false";
@@ -590,7 +591,7 @@ const getExpectedValue = argConfig => {
590
591
  return /** @type {NonNullable<ArgumentConfig["values"]>} */ (
591
592
  argConfig.values
592
593
  )
593
- .map(v => `${v}`)
594
+ .map((v) => `${v}`)
594
595
  .join(" | ");
595
596
  case "reset":
596
597
  return "true (will reset the previous value to an empty array)";
@@ -712,5 +713,186 @@ const processArguments = (args, config, values) => {
712
713
  return problems;
713
714
  };
714
715
 
716
+ /**
717
+ * @returns {boolean} true when colors supported, otherwise false
718
+ */
719
+ const isColorSupported = () => {
720
+ const { env = {}, argv = [], platform = "" } = process;
721
+
722
+ const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
723
+ const isForced = "FORCE_COLOR" in env || argv.includes("--color");
724
+ const isWindows = platform === "win32";
725
+ const isDumbTerminal = env.TERM === "dumb";
726
+
727
+ const isCompatibleTerminal = tty.isatty(1) && env.TERM && !isDumbTerminal;
728
+
729
+ const isCI =
730
+ "CI" in env &&
731
+ ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
732
+
733
+ return (
734
+ !isDisabled &&
735
+ (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI)
736
+ );
737
+ };
738
+
739
+ /**
740
+ * @param {number} index index
741
+ * @param {string} string string
742
+ * @param {string} close close
743
+ * @param {string=} replace replace
744
+ * @param {string=} head head
745
+ * @param {string=} tail tail
746
+ * @param {number=} next next
747
+ * @returns {string} result
748
+ */
749
+ const replaceClose = (
750
+ index,
751
+ string,
752
+ close,
753
+ replace,
754
+ head = string.slice(0, Math.max(0, index)) + replace,
755
+ tail = string.slice(Math.max(0, index + close.length)),
756
+ next = tail.indexOf(close)
757
+ ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
758
+
759
+ /**
760
+ * @param {number} index index to replace
761
+ * @param {string} string string
762
+ * @param {string} open open string
763
+ * @param {string} close close string
764
+ * @param {string=} replace extra replace
765
+ * @returns {string} result
766
+ */
767
+ const clearBleed = (index, string, open, close, replace) =>
768
+ index < 0
769
+ ? open + string + close
770
+ : open + replaceClose(index, string, close, replace) + close;
771
+
772
+ /** @typedef {(value: EXPECTED_ANY) => string} PrintFunction */
773
+
774
+ /**
775
+ * @param {string} open open string
776
+ * @param {string} close close string
777
+ * @param {string=} replace extra replace
778
+ * @param {number=} at at
779
+ * @returns {PrintFunction} function to create color
780
+ */
781
+ const filterEmpty =
782
+ (open, close, replace = open, at = open.length + 1) =>
783
+ (string) =>
784
+ string || !(string === "" || string === undefined)
785
+ ? clearBleed(`${string}`.indexOf(close, at), string, open, close, replace)
786
+ : "";
787
+
788
+ /**
789
+ * @param {number} open open code
790
+ * @param {number} close close code
791
+ * @param {string=} replace extra replace
792
+ * @returns {PrintFunction} result
793
+ */
794
+ const init = (open, close, replace) =>
795
+ filterEmpty(`\u001B[${open}m`, `\u001B[${close}m`, replace);
796
+
797
+ /**
798
+ * @typedef {{
799
+ * reset: PrintFunction
800
+ * bold: PrintFunction
801
+ * dim: PrintFunction
802
+ * italic: PrintFunction
803
+ * underline: PrintFunction
804
+ * inverse: PrintFunction
805
+ * hidden: PrintFunction
806
+ * strikethrough: PrintFunction
807
+ * black: PrintFunction
808
+ * red: PrintFunction
809
+ * green: PrintFunction
810
+ * yellow: PrintFunction
811
+ * blue: PrintFunction
812
+ * magenta: PrintFunction
813
+ * cyan: PrintFunction
814
+ * white: PrintFunction
815
+ * gray: PrintFunction
816
+ * bgBlack: PrintFunction
817
+ * bgRed: PrintFunction
818
+ * bgGreen: PrintFunction
819
+ * bgYellow: PrintFunction
820
+ * bgBlue: PrintFunction
821
+ * bgMagenta: PrintFunction
822
+ * bgCyan: PrintFunction
823
+ * bgWhite: PrintFunction
824
+ * blackBright: PrintFunction
825
+ * redBright: PrintFunction
826
+ * greenBright: PrintFunction
827
+ * yellowBright: PrintFunction
828
+ * blueBright: PrintFunction
829
+ * magentaBright: PrintFunction
830
+ * cyanBright: PrintFunction
831
+ * whiteBright: PrintFunction
832
+ * bgBlackBright: PrintFunction
833
+ * bgRedBright: PrintFunction
834
+ * bgGreenBright: PrintFunction
835
+ * bgYellowBright: PrintFunction
836
+ * bgBlueBright: PrintFunction
837
+ * bgMagentaBright: PrintFunction
838
+ * bgCyanBright: PrintFunction
839
+ * bgWhiteBright: PrintFunction
840
+ }} Colors */
841
+
842
+ /**
843
+ * @typedef {object} ColorsOptions
844
+ * @property {boolean=} useColor force use colors
845
+ */
846
+
847
+ /**
848
+ * @param {ColorsOptions=} options options
849
+ * @returns {Colors} colors
850
+ */
851
+ const createColors = ({ useColor = isColorSupported() } = {}) => ({
852
+ reset: useColor ? init(0, 0) : String,
853
+ bold: useColor ? init(1, 22, "\u001B[22m\u001B[1m") : String,
854
+ dim: useColor ? init(2, 22, "\u001B[22m\u001B[2m") : String,
855
+ italic: useColor ? init(3, 23) : String,
856
+ underline: useColor ? init(4, 24) : String,
857
+ inverse: useColor ? init(7, 27) : String,
858
+ hidden: useColor ? init(8, 28) : String,
859
+ strikethrough: useColor ? init(9, 29) : String,
860
+ black: useColor ? init(30, 39) : String,
861
+ red: useColor ? init(31, 39) : String,
862
+ green: useColor ? init(32, 39) : String,
863
+ yellow: useColor ? init(33, 39) : String,
864
+ blue: useColor ? init(34, 39) : String,
865
+ magenta: useColor ? init(35, 39) : String,
866
+ cyan: useColor ? init(36, 39) : String,
867
+ white: useColor ? init(37, 39) : String,
868
+ gray: useColor ? init(90, 39) : String,
869
+ bgBlack: useColor ? init(40, 49) : String,
870
+ bgRed: useColor ? init(41, 49) : String,
871
+ bgGreen: useColor ? init(42, 49) : String,
872
+ bgYellow: useColor ? init(43, 49) : String,
873
+ bgBlue: useColor ? init(44, 49) : String,
874
+ bgMagenta: useColor ? init(45, 49) : String,
875
+ bgCyan: useColor ? init(46, 49) : String,
876
+ bgWhite: useColor ? init(47, 49) : String,
877
+ blackBright: useColor ? init(90, 39) : String,
878
+ redBright: useColor ? init(91, 39) : String,
879
+ greenBright: useColor ? init(92, 39) : String,
880
+ yellowBright: useColor ? init(93, 39) : String,
881
+ blueBright: useColor ? init(94, 39) : String,
882
+ magentaBright: useColor ? init(95, 39) : String,
883
+ cyanBright: useColor ? init(96, 39) : String,
884
+ whiteBright: useColor ? init(97, 39) : String,
885
+ bgBlackBright: useColor ? init(100, 49) : String,
886
+ bgRedBright: useColor ? init(101, 49) : String,
887
+ bgGreenBright: useColor ? init(102, 49) : String,
888
+ bgYellowBright: useColor ? init(103, 49) : String,
889
+ bgBlueBright: useColor ? init(104, 49) : String,
890
+ bgMagentaBright: useColor ? init(105, 49) : String,
891
+ bgCyanBright: useColor ? init(106, 49) : String,
892
+ bgWhiteBright: useColor ? init(107, 49) : String
893
+ });
894
+
895
+ module.exports.createColors = createColors;
715
896
  module.exports.getArguments = getArguments;
897
+ module.exports.isColorSupported = isColorSupported;
716
898
  module.exports.processArguments = processArguments;
@@ -74,14 +74,14 @@ const load = (input, context) => {
74
74
  * @param {string[]} browsers supported browsers list
75
75
  * @returns {EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties} target properties
76
76
  */
77
- const resolve = browsers => {
77
+ const resolve = (browsers) => {
78
78
  /**
79
79
  * Checks all against a version number
80
80
  * @param {Record<string, number | [number, number]>} versions first supported version
81
81
  * @returns {boolean} true if supports
82
82
  */
83
- const rawChecker = versions =>
84
- browsers.every(v => {
83
+ const rawChecker = (versions) =>
84
+ browsers.every((v) => {
85
85
  const [name, parsedVersion] = v.split(" ");
86
86
  if (!name) return false;
87
87
  const requiredVersion = versions[name];
@@ -100,8 +100,8 @@ const resolve = browsers => {
100
100
  ? Number(parserMinor) >= requiredVersion[1]
101
101
  : Number(parsedMajor) > requiredVersion[0];
102
102
  });
103
- const anyNode = browsers.some(b => b.startsWith("node "));
104
- const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
103
+ const anyNode = browsers.some((b) => b.startsWith("node "));
104
+ const anyBrowser = browsers.some((b) => /^(?!node)/.test(b));
105
105
  const browserProperty = !anyBrowser ? false : anyNode ? null : true;
106
106
  const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
107
107
  // Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
@@ -349,7 +349,7 @@ const resolve = browsers => {
349
349
  nodeBuiltins: nodeProperty,
350
350
  nodePrefixForCoreModules:
351
351
  nodeProperty &&
352
- !browsers.some(b => b.startsWith("node 15")) &&
352
+ !browsers.some((b) => b.startsWith("node 15")) &&
353
353
  rawChecker({
354
354
  node: [14, 18]
355
355
  }),
@@ -159,7 +159,7 @@ const A = (obj, prop, factory) => {
159
159
  * @param {WebpackOptionsNormalized} options options to be modified
160
160
  * @returns {void}
161
161
  */
162
- const applyWebpackOptionsBaseDefaults = options => {
162
+ const applyWebpackOptionsBaseDefaults = (options) => {
163
163
  F(options, "context", () => process.cwd());
164
164
  applyInfrastructureLoggingDefaults(options.infrastructureLogging);
165
165
  };
@@ -242,7 +242,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
242
242
  target === undefined ||
243
243
  (typeof target === "string" && target.startsWith("browserslist")) ||
244
244
  (Array.isArray(target) &&
245
- target.some(target => target.startsWith("browserslist"))),
245
+ target.some((target) => target.startsWith("browserslist"))),
246
246
  outputModule:
247
247
  /** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
248
248
  (options.experiments.outputModule),
@@ -265,6 +265,9 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
265
265
  css:
266
266
  /** @type {NonNullable<ExperimentsNormalized["css"]>} */
267
267
  (options.experiments.css),
268
+ deferImport:
269
+ /** @type {NonNullable<ExperimentsNormalized["deferImport"]>} */
270
+ (options.experiments.deferImport),
268
271
  futureDefaults,
269
272
  isNode: targetProperties && targetProperties.node === true,
270
273
  uniqueName: /** @type {string} */ (options.output.uniqueName),
@@ -384,6 +387,7 @@ const applyExperimentsDefaults = (
384
387
  D(experiments, "lazyCompilation", undefined);
385
388
  D(experiments, "buildHttp", undefined);
386
389
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
390
+ D(experiments, "deferImport", false);
387
391
  F(experiments, "css", () => (experiments.futureDefaults ? true : undefined));
388
392
 
389
393
  // TODO webpack 6: remove this. topLevelAwait should be enabled by default
@@ -561,12 +565,13 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
561
565
  * @param {JavascriptParserOptions} parserOptions parser options
562
566
  * @param {object} options options
563
567
  * @param {boolean} options.futureDefaults is future defaults enabled
568
+ * @param {boolean} options.deferImport is defer import enabled
564
569
  * @param {boolean} options.isNode is node target platform
565
570
  * @returns {void}
566
571
  */
567
572
  const applyJavascriptParserOptionsDefaults = (
568
573
  parserOptions,
569
- { futureDefaults, isNode }
574
+ { futureDefaults, deferImport, isNode }
570
575
  ) => {
571
576
  D(parserOptions, "unknownContextRequest", ".");
572
577
  D(parserOptions, "unknownContextRegExp", false);
@@ -587,6 +592,7 @@ const applyJavascriptParserOptionsDefaults = (
587
592
  D(parserOptions, "dynamicImportFetchPriority", false);
588
593
  D(parserOptions, "createRequire", isNode);
589
594
  D(parserOptions, "dynamicUrl", true);
595
+ D(parserOptions, "deferImport", deferImport);
590
596
  if (futureDefaults) D(parserOptions, "exportsPresence", "error");
591
597
  };
592
598
 
@@ -594,7 +600,7 @@ const applyJavascriptParserOptionsDefaults = (
594
600
  * @param {JsonGeneratorOptions} generatorOptions generator options
595
601
  * @returns {void}
596
602
  */
597
- const applyJsonGeneratorOptionsDefaults = generatorOptions => {
603
+ const applyJsonGeneratorOptionsDefaults = (generatorOptions) => {
598
604
  D(generatorOptions, "JSONParse", true);
599
605
  };
600
606
 
@@ -626,6 +632,7 @@ const applyCssGeneratorOptionsDefaults = (
626
632
  * @param {boolean} options.futureDefaults is future defaults enabled
627
633
  * @param {string} options.uniqueName the unique name
628
634
  * @param {boolean} options.isNode is node target platform
635
+ * @param {boolean} options.deferImport is defer import enabled
629
636
  * @param {TargetProperties | false} options.targetProperties target properties
630
637
  * @param {Mode | undefined} options.mode mode
631
638
  * @returns {void}
@@ -641,7 +648,8 @@ const applyModuleDefaults = (
641
648
  isNode,
642
649
  uniqueName,
643
650
  targetProperties,
644
- mode
651
+ mode,
652
+ deferImport
645
653
  }
646
654
  ) => {
647
655
  if (cache) {
@@ -652,7 +660,7 @@ const applyModuleDefaults = (
652
660
  * @param {Module} module module
653
661
  * @returns {boolean} true, if we want to cache the module
654
662
  */
655
- module => {
663
+ (module) => {
656
664
  const name = module.nameForCondition();
657
665
  if (!name) {
658
666
  return false;
@@ -699,6 +707,7 @@ const applyModuleDefaults = (
699
707
  (module.parser.javascript),
700
708
  {
701
709
  futureDefaults,
710
+ deferImport,
702
711
  isNode
703
712
  }
704
713
  );
@@ -964,7 +973,7 @@ const applyOutputDefaults = (
964
973
  * @param {Library=} library the library option
965
974
  * @returns {string} a readable library name
966
975
  */
967
- const getLibraryName = library => {
976
+ const getLibraryName = (library) => {
968
977
  const libraryName =
969
978
  typeof library === "object" &&
970
979
  library &&
@@ -1015,7 +1024,7 @@ const applyOutputDefaults = (
1015
1024
  * @param {boolean | undefined} v value
1016
1025
  * @returns {boolean} true, when v is truthy or undefined
1017
1026
  */
1018
- const optimistic = v => v || v === undefined;
1027
+ const optimistic = (v) => v || v === undefined;
1019
1028
  /**
1020
1029
  * @param {boolean | undefined} v value
1021
1030
  * @param {boolean | undefined} c condition
@@ -1322,7 +1331,7 @@ const applyOutputDefaults = (
1322
1331
  * @param {(entryDescription: EntryDescription) => void} fn iterator
1323
1332
  * @returns {void}
1324
1333
  */
1325
- const forEachEntry = fn => {
1334
+ const forEachEntry = (fn) => {
1326
1335
  for (const name of Object.keys(entry)) {
1327
1336
  fn(/** @type {{[k: string] : EntryDescription}} */ (entry)[name]);
1328
1337
  }
@@ -1333,7 +1342,7 @@ const applyOutputDefaults = (
1333
1342
  if (output.library) {
1334
1343
  enabledLibraryTypes.push(output.library.type);
1335
1344
  }
1336
- forEachEntry(desc => {
1345
+ forEachEntry((desc) => {
1337
1346
  if (desc.library) {
1338
1347
  enabledLibraryTypes.push(desc.library.type);
1339
1348
  }
@@ -1349,7 +1358,7 @@ const applyOutputDefaults = (
1349
1358
  if (output.workerChunkLoading) {
1350
1359
  enabledChunkLoadingTypes.add(output.workerChunkLoading);
1351
1360
  }
1352
- forEachEntry(desc => {
1361
+ forEachEntry((desc) => {
1353
1362
  if (desc.chunkLoading) {
1354
1363
  enabledChunkLoadingTypes.add(desc.chunkLoading);
1355
1364
  }
@@ -1365,7 +1374,7 @@ const applyOutputDefaults = (
1365
1374
  if (output.workerWasmLoading) {
1366
1375
  enabledWasmLoadingTypes.add(output.workerWasmLoading);
1367
1376
  }
1368
- forEachEntry(desc => {
1377
+ forEachEntry((desc) => {
1369
1378
  if (desc.wasmLoading) {
1370
1379
  enabledWasmLoadingTypes.add(desc.wasmLoading);
1371
1380
  }
@@ -1553,7 +1562,7 @@ const applyOptimizationDefaults = (
1553
1562
  D(optimization, "minimize", production);
1554
1563
  A(optimization, "minimizer", () => [
1555
1564
  {
1556
- apply: compiler => {
1565
+ apply: (compiler) => {
1557
1566
  // Lazy load the Terser plugin
1558
1567
  const TerserPlugin = require("terser-webpack-plugin");
1559
1568
 
@@ -1735,7 +1744,7 @@ const getResolveLoaderDefaults = ({ cache }) => {
1735
1744
  * @param {InfrastructureLogging} infrastructureLogging options
1736
1745
  * @returns {void}
1737
1746
  */
1738
- const applyInfrastructureLoggingDefaults = infrastructureLogging => {
1747
+ const applyInfrastructureLoggingDefaults = (infrastructureLogging) => {
1739
1748
  F(infrastructureLogging, "stream", () => process.stderr);
1740
1749
  const tty =
1741
1750
  /** @type {NonNullable<InfrastructureLogging["stream"]>} */