webpack 5.93.0 → 5.95.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 (344) hide show
  1. package/README.md +8 -5
  2. package/bin/webpack.js +6 -7
  3. package/hot/log.js +1 -2
  4. package/hot/only-dev-server.js +1 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +4 -3
  8. package/lib/AbstractMethodError.js +10 -5
  9. package/lib/AutomaticPrefetchPlugin.js +1 -1
  10. package/lib/BannerPlugin.js +12 -6
  11. package/lib/Cache.js +8 -10
  12. package/lib/CacheFacade.js +3 -3
  13. package/lib/CaseSensitiveModulesWarning.js +5 -7
  14. package/lib/Chunk.js +14 -11
  15. package/lib/ChunkGraph.js +58 -36
  16. package/lib/ChunkGroup.js +2 -3
  17. package/lib/ChunkTemplate.js +43 -0
  18. package/lib/CleanPlugin.js +10 -11
  19. package/lib/CodeGenerationResults.js +6 -5
  20. package/lib/CommentCompilationWarning.js +0 -1
  21. package/lib/Compilation.js +223 -191
  22. package/lib/Compiler.js +81 -82
  23. package/lib/ConcatenationScope.js +3 -6
  24. package/lib/ConditionalInitFragment.js +6 -7
  25. package/lib/ConstPlugin.js +7 -15
  26. package/lib/ContextExclusionPlugin.js +3 -3
  27. package/lib/ContextModule.js +33 -20
  28. package/lib/ContextModuleFactory.js +89 -44
  29. package/lib/ContextReplacementPlugin.js +10 -9
  30. package/lib/DefinePlugin.js +75 -68
  31. package/lib/DelegatedModule.js +7 -3
  32. package/lib/DelegatedModuleFactoryPlugin.js +36 -22
  33. package/lib/DelegatedPlugin.js +4 -0
  34. package/lib/DependenciesBlock.js +0 -1
  35. package/lib/Dependency.js +10 -14
  36. package/lib/DllEntryPlugin.js +4 -2
  37. package/lib/DllModuleFactory.js +1 -0
  38. package/lib/DllPlugin.js +9 -7
  39. package/lib/DllReferencePlugin.js +30 -15
  40. package/lib/EntryPlugin.js +1 -3
  41. package/lib/EnvironmentPlugin.js +6 -2
  42. package/lib/ErrorHelpers.js +11 -12
  43. package/lib/EvalDevToolModulePlugin.js +10 -12
  44. package/lib/EvalSourceMapDevToolPlugin.js +15 -13
  45. package/lib/ExportsInfo.js +185 -120
  46. package/lib/ExternalModule.js +41 -15
  47. package/lib/ExternalModuleFactoryPlugin.js +23 -10
  48. package/lib/FileSystemInfo.js +791 -422
  49. package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
  50. package/lib/FlagDependencyExportsPlugin.js +12 -11
  51. package/lib/FlagDependencyUsagePlugin.js +1 -1
  52. package/lib/Generator.js +2 -5
  53. package/lib/GraphHelpers.js +3 -2
  54. package/lib/HookWebpackError.js +8 -10
  55. package/lib/HotModuleReplacementPlugin.js +78 -64
  56. package/lib/IgnoreErrorModuleFactory.js +3 -3
  57. package/lib/IgnorePlugin.js +1 -3
  58. package/lib/IgnoreWarningsPlugin.js +6 -9
  59. package/lib/InitFragment.js +2 -3
  60. package/lib/LibManifestPlugin.js +4 -3
  61. package/lib/MainTemplate.js +72 -19
  62. package/lib/Module.js +25 -9
  63. package/lib/ModuleBuildError.js +4 -11
  64. package/lib/ModuleDependencyError.js +5 -5
  65. package/lib/ModuleDependencyWarning.js +5 -5
  66. package/lib/ModuleError.js +1 -5
  67. package/lib/ModuleFilenameHelpers.js +29 -46
  68. package/lib/ModuleGraph.js +7 -6
  69. package/lib/ModuleGraphConnection.js +6 -6
  70. package/lib/ModuleInfoHeaderPlugin.js +82 -30
  71. package/lib/ModuleParseError.js +8 -9
  72. package/lib/ModuleRestoreError.js +1 -1
  73. package/lib/ModuleStoreError.js +1 -1
  74. package/lib/ModuleTemplate.js +33 -1
  75. package/lib/ModuleTypeConstants.js +21 -22
  76. package/lib/ModuleWarning.js +1 -5
  77. package/lib/MultiCompiler.js +24 -26
  78. package/lib/MultiStats.js +73 -31
  79. package/lib/MultiWatching.js +1 -1
  80. package/lib/NormalModule.js +130 -69
  81. package/lib/NormalModuleFactory.js +53 -49
  82. package/lib/OptimizationStages.js +3 -3
  83. package/lib/ProgressPlugin.js +9 -9
  84. package/lib/ProvidePlugin.js +4 -4
  85. package/lib/RuntimeGlobals.js +71 -70
  86. package/lib/RuntimeModule.js +1 -1
  87. package/lib/RuntimePlugin.js +24 -12
  88. package/lib/RuntimeTemplate.js +40 -44
  89. package/lib/SizeFormatHelpers.js +2 -4
  90. package/lib/SourceMapDevToolPlugin.js +42 -34
  91. package/lib/Stats.js +5 -11
  92. package/lib/Template.js +18 -24
  93. package/lib/TemplatedPathPlugin.js +21 -13
  94. package/lib/WarnDeprecatedOptionPlugin.js +0 -1
  95. package/lib/WatchIgnorePlugin.js +26 -9
  96. package/lib/Watching.js +10 -5
  97. package/lib/WebpackOptionsApply.js +84 -62
  98. package/lib/asset/AssetGenerator.js +107 -42
  99. package/lib/asset/AssetModulesPlugin.js +29 -23
  100. package/lib/asset/AssetSourceGenerator.js +2 -7
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
  102. package/lib/buildChunkGraph.js +93 -81
  103. package/lib/cache/IdleFileCachePlugin.js +4 -4
  104. package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
  105. package/lib/cache/PackFileCacheStrategy.js +51 -50
  106. package/lib/cache/ResolverCachePlugin.js +6 -6
  107. package/lib/cache/mergeEtags.js +16 -21
  108. package/lib/cli.js +148 -104
  109. package/lib/config/browserslistTargetHandler.js +16 -13
  110. package/lib/config/defaults.js +32 -28
  111. package/lib/config/normalization.js +335 -344
  112. package/lib/config/target.js +42 -52
  113. package/lib/container/ContainerEntryModule.js +2 -2
  114. package/lib/container/ContainerPlugin.js +1 -1
  115. package/lib/container/RemoteRuntimeModule.js +11 -8
  116. package/lib/container/options.js +18 -4
  117. package/lib/css/CssExportsGenerator.js +26 -24
  118. package/lib/css/CssGenerator.js +9 -4
  119. package/lib/css/CssLoadingRuntimeModule.js +10 -10
  120. package/lib/css/CssModulesPlugin.js +127 -47
  121. package/lib/css/CssParser.js +20 -18
  122. package/lib/css/walkCssTokens.js +80 -95
  123. package/lib/debug/ProfilingPlugin.js +19 -20
  124. package/lib/dependencies/AMDDefineDependency.js +1 -1
  125. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
  126. package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
  127. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
  128. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  129. package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
  130. package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
  131. package/lib/dependencies/CommonJsExportsDependency.js +0 -1
  132. package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
  133. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  134. package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
  135. package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
  136. package/lib/dependencies/ConstDependency.js +1 -1
  137. package/lib/dependencies/ContextDependency.js +7 -2
  138. package/lib/dependencies/ContextDependencyHelpers.js +31 -34
  139. package/lib/dependencies/ContextElementDependency.js +35 -8
  140. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  141. package/lib/dependencies/CssExportDependency.js +7 -7
  142. package/lib/dependencies/CssImportDependency.js +0 -2
  143. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
  144. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  145. package/lib/dependencies/CssUrlDependency.js +4 -5
  146. package/lib/dependencies/DynamicExports.js +5 -5
  147. package/lib/dependencies/ExportsInfoDependency.js +1 -2
  148. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
  149. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
  150. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
  151. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  152. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
  153. package/lib/dependencies/HarmonyExports.js +2 -2
  154. package/lib/dependencies/HarmonyImportDependency.js +2 -4
  155. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
  156. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
  157. package/lib/dependencies/ImportDependency.js +1 -1
  158. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
  159. package/lib/dependencies/ImportMetaPlugin.js +11 -13
  160. package/lib/dependencies/ImportParserPlugin.js +39 -44
  161. package/lib/dependencies/JsonExportsDependency.js +22 -18
  162. package/lib/dependencies/LoaderPlugin.js +47 -36
  163. package/lib/dependencies/LocalModule.js +1 -1
  164. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  165. package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
  166. package/lib/dependencies/ProvidedDependency.js +1 -1
  167. package/lib/dependencies/PureExpressionDependency.js +6 -6
  168. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  170. package/lib/dependencies/SystemPlugin.js +1 -1
  171. package/lib/dependencies/URLDependency.js +3 -3
  172. package/lib/dependencies/URLPlugin.js +66 -12
  173. package/lib/dependencies/WorkerPlugin.js +25 -24
  174. package/lib/dependencies/processExportInfo.js +3 -1
  175. package/lib/electron/ElectronTargetPlugin.js +1 -0
  176. package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
  178. package/lib/formatLocation.js +1 -2
  179. package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
  180. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  181. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
  182. package/lib/hmr/LazyCompilationPlugin.js +27 -12
  183. package/lib/hmr/lazyCompilationBackend.js +64 -40
  184. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
  185. package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
  186. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  187. package/lib/ids/HashedModuleIdsPlugin.js +5 -1
  188. package/lib/ids/IdHelpers.js +29 -39
  189. package/lib/ids/SyncModuleIdsPlugin.js +7 -2
  190. package/lib/index.js +1 -5
  191. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
  192. package/lib/javascript/BasicEvaluatedExpression.js +4 -19
  193. package/lib/javascript/ChunkHelpers.js +1 -1
  194. package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
  195. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
  196. package/lib/javascript/JavascriptGenerator.js +23 -7
  197. package/lib/javascript/JavascriptModulesPlugin.js +133 -86
  198. package/lib/javascript/JavascriptParser.js +179 -200
  199. package/lib/javascript/JavascriptParserHelpers.js +20 -21
  200. package/lib/javascript/StartupHelpers.js +41 -13
  201. package/lib/json/JsonGenerator.js +7 -13
  202. package/lib/json/JsonModulesPlugin.js +1 -4
  203. package/lib/json/JsonParser.js +5 -3
  204. package/lib/library/AmdLibraryPlugin.js +12 -16
  205. package/lib/library/AssignLibraryPlugin.js +8 -10
  206. package/lib/library/EnableLibraryPlugin.js +15 -14
  207. package/lib/library/JsonpLibraryPlugin.js +2 -1
  208. package/lib/library/ModernModuleLibraryPlugin.js +8 -6
  209. package/lib/library/ModuleLibraryPlugin.js +2 -1
  210. package/lib/library/SystemLibraryPlugin.js +2 -1
  211. package/lib/library/UmdLibraryPlugin.js +66 -92
  212. package/lib/logging/Logger.js +32 -4
  213. package/lib/logging/createConsoleLogger.js +12 -13
  214. package/lib/logging/runtime.js +7 -8
  215. package/lib/logging/truncateArgs.js +5 -8
  216. package/lib/node/NodeWatchFileSystem.js +3 -18
  217. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  218. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  219. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  220. package/lib/node/nodeConsole.js +22 -22
  221. package/lib/optimize/AggressiveMergingPlugin.js +2 -4
  222. package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
  223. package/lib/optimize/ConcatenatedModule.js +81 -51
  224. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  225. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
  226. package/lib/optimize/InnerGraph.js +17 -17
  227. package/lib/optimize/InnerGraphPlugin.js +8 -7
  228. package/lib/optimize/LimitChunkCountPlugin.js +2 -3
  229. package/lib/optimize/MangleExportsPlugin.js +1 -0
  230. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  231. package/lib/optimize/MinMaxSizeWarning.js +1 -1
  232. package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
  233. package/lib/optimize/RealContentHashPlugin.js +7 -10
  234. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  235. package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
  236. package/lib/optimize/SplitChunksPlugin.js +34 -30
  237. package/lib/performance/SizeLimitsPlugin.js +2 -2
  238. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  239. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  240. package/lib/rules/BasicEffectRulePlugin.js +3 -1
  241. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  242. package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
  243. package/lib/rules/RuleSetCompiler.js +41 -22
  244. package/lib/rules/UseEffectRulePlugin.js +36 -32
  245. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  246. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  247. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  248. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
  251. package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
  252. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
  253. package/lib/schemes/DataUriPlugin.js +1 -1
  254. package/lib/schemes/HttpUriPlugin.js +241 -126
  255. package/lib/serialization/BinaryMiddleware.js +44 -28
  256. package/lib/serialization/DateObjectSerializer.js +1 -0
  257. package/lib/serialization/ErrorObjectSerializer.js +2 -0
  258. package/lib/serialization/FileMiddleware.js +154 -106
  259. package/lib/serialization/MapObjectSerializer.js +2 -1
  260. package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
  261. package/lib/serialization/ObjectMiddleware.js +52 -56
  262. package/lib/serialization/PlainObjectSerializer.js +32 -6
  263. package/lib/serialization/RegExpObjectSerializer.js +1 -0
  264. package/lib/serialization/Serializer.js +4 -5
  265. package/lib/serialization/SerializerMiddleware.js +6 -6
  266. package/lib/serialization/SetObjectSerializer.js +2 -1
  267. package/lib/sharing/ConsumeSharedPlugin.js +116 -97
  268. package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
  269. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  270. package/lib/sharing/ProvideSharedPlugin.js +2 -2
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  272. package/lib/sharing/utils.js +15 -27
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
  274. package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
  275. package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
  276. package/lib/stats/StatsFactory.js +127 -56
  277. package/lib/stats/StatsPrinter.js +75 -44
  278. package/lib/util/ArrayHelpers.js +8 -4
  279. package/lib/util/ArrayQueue.js +1 -1
  280. package/lib/util/AsyncQueue.js +31 -12
  281. package/lib/util/IterableHelpers.js +3 -4
  282. package/lib/util/LazyBucketSortedSet.js +60 -44
  283. package/lib/util/LazySet.js +13 -0
  284. package/lib/util/MapHelpers.js +1 -3
  285. package/lib/util/ParallelismFactorCalculator.js +1 -1
  286. package/lib/util/Queue.js +1 -1
  287. package/lib/util/Semaphore.js +4 -7
  288. package/lib/util/SetHelpers.js +5 -5
  289. package/lib/util/SortableSet.js +4 -3
  290. package/lib/util/StackedCacheMap.js +4 -6
  291. package/lib/util/StackedMap.js +1 -3
  292. package/lib/util/StringXor.js +0 -5
  293. package/lib/util/TupleQueue.js +1 -1
  294. package/lib/util/TupleSet.js +15 -5
  295. package/lib/util/URLAbsoluteSpecifier.js +7 -7
  296. package/lib/util/WeakTupleMap.js +19 -21
  297. package/lib/util/binarySearchBounds.js +5 -12
  298. package/lib/util/chainedImports.js +1 -1
  299. package/lib/util/cleverMerge.js +21 -19
  300. package/lib/util/comparators.js +57 -52
  301. package/lib/util/compileBooleanMatcher.js +3 -6
  302. package/lib/util/conventions.js +8 -11
  303. package/lib/util/createHash.js +9 -6
  304. package/lib/util/deprecation.js +22 -12
  305. package/lib/util/deterministicGrouping.js +19 -26
  306. package/lib/util/findGraphRoots.js +2 -2
  307. package/lib/util/fs.js +32 -32
  308. package/lib/util/hash/md4.js +2 -2
  309. package/lib/util/hash/wasm-hash.js +7 -7
  310. package/lib/util/hash/xxhash64.js +2 -2
  311. package/lib/util/identifier.js +81 -59
  312. package/lib/util/memoize.js +8 -10
  313. package/lib/util/mergeScope.js +6 -9
  314. package/lib/util/nonNumericOnlyHash.js +2 -2
  315. package/lib/util/numberHash.js +1 -6
  316. package/lib/util/objectToMap.js +0 -1
  317. package/lib/util/propertyAccess.js +2 -5
  318. package/lib/util/propertyName.js +1 -3
  319. package/lib/util/registerExternalSerializer.js +1 -1
  320. package/lib/util/runtime.js +109 -113
  321. package/lib/util/semver.js +29 -27
  322. package/lib/util/serialization.js +16 -1
  323. package/lib/util/smartGrouping.js +5 -5
  324. package/lib/util/source.js +1 -1
  325. package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
  326. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  327. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
  328. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  329. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
  330. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
  331. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  333. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
  334. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  335. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  336. package/package.json +18 -17
  337. package/schemas/WebpackOptions.check.js +1 -1
  338. package/schemas/WebpackOptions.json +5 -0
  339. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  340. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  341. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  342. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  343. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  344. package/types.d.ts +681 -355
@@ -34,27 +34,23 @@ const mergeEtags = (a, b) => {
34
34
  if (typeof a === "string") {
35
35
  if (typeof b === "string") {
36
36
  return `${a}|${b}`;
37
- } else {
38
- const temp = b;
39
- b = a;
40
- a = temp;
41
37
  }
42
- } else {
43
- if (typeof b !== "string") {
44
- // both a and b are objects
45
- let map = dualObjectMap.get(a);
46
- if (map === undefined) {
47
- dualObjectMap.set(a, (map = new WeakMap()));
48
- }
49
- const mergedEtag = map.get(b);
50
- if (mergedEtag === undefined) {
51
- const newMergedEtag = new MergedEtag(a, b);
52
- map.set(b, newMergedEtag);
53
- return newMergedEtag;
54
- } else {
55
- return mergedEtag;
56
- }
38
+ const temp = b;
39
+ b = a;
40
+ a = temp;
41
+ } else if (typeof b !== "string") {
42
+ // both a and b are objects
43
+ let map = dualObjectMap.get(a);
44
+ if (map === undefined) {
45
+ dualObjectMap.set(a, (map = new WeakMap()));
57
46
  }
47
+ const mergedEtag = map.get(b);
48
+ if (mergedEtag === undefined) {
49
+ const newMergedEtag = new MergedEtag(a, b);
50
+ map.set(b, newMergedEtag);
51
+ return newMergedEtag;
52
+ }
53
+ return mergedEtag;
58
54
  }
59
55
  // a is object, b is string
60
56
  let map = objectStringMap.get(a);
@@ -66,9 +62,8 @@ const mergeEtags = (a, b) => {
66
62
  const newMergedEtag = new MergedEtag(a, b);
67
63
  map.set(b, newMergedEtag);
68
64
  return newMergedEtag;
69
- } else {
70
- return mergedEtag;
71
65
  }
66
+ return mergedEtag;
72
67
  };
73
68
 
74
69
  module.exports = mergeEtags;
package/lib/cli.js CHANGED
@@ -8,6 +8,8 @@
8
8
  const path = require("path");
9
9
  const webpackSchema = require("../schemas/WebpackOptions.json");
10
10
 
11
+ /** @typedef {TODO & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean } }} Schema */
12
+
11
13
  // TODO add originPath to PathItem for better errors
12
14
  /**
13
15
  * @typedef {object} PathItem
@@ -36,7 +38,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
36
38
 
37
39
  /**
38
40
  * @typedef {object} ArgumentConfig
39
- * @property {string} description
41
+ * @property {string | undefined} description
40
42
  * @property {string} [negatedDescription]
41
43
  * @property {string} path
42
44
  * @property {boolean} multiple
@@ -44,24 +46,34 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
44
46
  * @property {any[]=} values
45
47
  */
46
48
 
49
+ /** @typedef {"string" | "number" | "boolean"} SimpleType */
50
+
47
51
  /**
48
52
  * @typedef {object} Argument
49
- * @property {string} description
50
- * @property {"string"|"number"|"boolean"} simpleType
53
+ * @property {string | undefined} description
54
+ * @property {SimpleType} simpleType
51
55
  * @property {boolean} multiple
52
56
  * @property {ArgumentConfig[]} configs
53
57
  */
54
58
 
59
+ /** @typedef {string | number | boolean | RegExp | (string | number | boolean | RegExp)} Value */
60
+
61
+ /** @typedef {Record<string, Argument>} Flags */
62
+
55
63
  /**
56
- * @param {any=} schema a json schema to create arguments for (by default webpack schema is used)
57
- * @returns {Record<string, Argument>} object of arguments
64
+ * @param {Schema=} schema a json schema to create arguments for (by default webpack schema is used)
65
+ * @returns {Flags} object of arguments
58
66
  */
59
67
  const getArguments = (schema = webpackSchema) => {
60
- /** @type {Record<string, Argument>} */
68
+ /** @type {Flags} */
61
69
  const flags = {};
62
70
 
63
- const pathToArgumentName = input => {
64
- return input
71
+ /**
72
+ * @param {string} input input
73
+ * @returns {string} result
74
+ */
75
+ const pathToArgumentName = input =>
76
+ input
65
77
  .replace(/\./g, "-")
66
78
  .replace(/\[\]/g, "")
67
79
  .replace(
@@ -70,8 +82,11 @@ const getArguments = (schema = webpackSchema) => {
70
82
  )
71
83
  .replace(/-?[^\p{Uppercase_Letter}\p{Lowercase_Letter}\d]+/gu, "-")
72
84
  .toLowerCase();
73
- };
74
85
 
86
+ /**
87
+ * @param {string} path path
88
+ * @returns {Schema} schema part
89
+ */
75
90
  const getSchemaPart = path => {
76
91
  const newPath = path.split("/");
77
92
 
@@ -91,7 +106,6 @@ const getArguments = (schema = webpackSchema) => {
91
106
  };
92
107
 
93
108
  /**
94
- *
95
109
  * @param {PathItem[]} path path in the schema
96
110
  * @returns {string | undefined} description
97
111
  */
@@ -106,7 +120,6 @@ const getArguments = (schema = webpackSchema) => {
106
120
  };
107
121
 
108
122
  /**
109
- *
110
123
  * @param {PathItem[]} path path in the schema
111
124
  * @returns {string | undefined} negative description
112
125
  */
@@ -120,7 +133,6 @@ const getArguments = (schema = webpackSchema) => {
120
133
  };
121
134
 
122
135
  /**
123
- *
124
136
  * @param {PathItem[]} path path in the schema
125
137
  * @returns {string | undefined} reset description
126
138
  */
@@ -134,9 +146,8 @@ const getArguments = (schema = webpackSchema) => {
134
146
  };
135
147
 
136
148
  /**
137
- *
138
- * @param {any} schemaPart schema
139
- * @returns {Pick<ArgumentConfig, "type"|"values">} partial argument config
149
+ * @param {Schema} schemaPart schema
150
+ * @returns {Pick<ArgumentConfig, "type"|"values"> | undefined} partial argument config
140
151
  */
141
152
  const schemaToArgumentConfig = schemaPart => {
142
153
  if (schemaPart.enum) {
@@ -189,8 +200,10 @@ const getArguments = (schema = webpackSchema) => {
189
200
  }
190
201
  ],
191
202
  description: undefined,
192
- simpleType: undefined,
193
- multiple: undefined
203
+ simpleType:
204
+ /** @type {SimpleType} */
205
+ (/** @type {unknown} */ (undefined)),
206
+ multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined))
194
207
  };
195
208
  };
196
209
 
@@ -221,8 +234,10 @@ const getArguments = (schema = webpackSchema) => {
221
234
  flags[name] = {
222
235
  configs: [],
223
236
  description: undefined,
224
- simpleType: undefined,
225
- multiple: undefined
237
+ simpleType:
238
+ /** @type {SimpleType} */
239
+ (/** @type {unknown} */ (undefined)),
240
+ multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined))
226
241
  };
227
242
  }
228
243
 
@@ -255,8 +270,7 @@ const getArguments = (schema = webpackSchema) => {
255
270
  // TODO support `not` and `if/then/else`
256
271
  // TODO support `const`, but we don't use it on our schema
257
272
  /**
258
- *
259
- * @param {object} schemaPart the current schema
273
+ * @param {Schema} schemaPart the current schema
260
274
  * @param {string} schemaPath the current path in the schema
261
275
  * @param {{schema: object, path: string}[]} path all previous visited schemaParts
262
276
  * @param {string | null} inArray if inside of an array, the path to the array
@@ -281,13 +295,14 @@ const getArguments = (schema = webpackSchema) => {
281
295
 
282
296
  let addedArguments = 0;
283
297
 
284
- addedArguments += addFlag(fullPath, !!inArray);
298
+ addedArguments += addFlag(fullPath, Boolean(inArray));
285
299
 
286
300
  if (schemaPart.type === "object") {
287
301
  if (schemaPart.properties) {
288
302
  for (const property of Object.keys(schemaPart.properties)) {
289
303
  addedArguments += traverse(
290
- schemaPart.properties[property],
304
+ /** @type {Schema} */
305
+ (schemaPart.properties[property]),
291
306
  schemaPath ? `${schemaPath}.${property}` : property,
292
307
  fullPath,
293
308
  inArray
@@ -303,10 +318,11 @@ const getArguments = (schema = webpackSchema) => {
303
318
  return 0;
304
319
  }
305
320
  if (Array.isArray(schemaPart.items)) {
306
- let i = 0;
321
+ const i = 0;
307
322
  for (const item of schemaPart.items) {
308
323
  addedArguments += traverse(
309
- item,
324
+ /** @type {Schema} */
325
+ (item),
310
326
  `${schemaPath}.${i}`,
311
327
  fullPath,
312
328
  schemaPath
@@ -317,7 +333,8 @@ const getArguments = (schema = webpackSchema) => {
317
333
  }
318
334
 
319
335
  addedArguments += traverse(
320
- schemaPart.items,
336
+ /** @type {Schema} */
337
+ (schemaPart.items),
321
338
  `${schemaPath}[]`,
322
339
  fullPath,
323
340
  schemaPath
@@ -337,7 +354,13 @@ const getArguments = (schema = webpackSchema) => {
337
354
  const items = maybeOf;
338
355
 
339
356
  for (let i = 0; i < items.length; i++) {
340
- addedArguments += traverse(items[i], schemaPath, fullPath, inArray);
357
+ addedArguments += traverse(
358
+ /** @type {Schema} */
359
+ (items[i]),
360
+ schemaPath,
361
+ fullPath,
362
+ inArray
363
+ );
341
364
  }
342
365
 
343
366
  return addedArguments;
@@ -350,6 +373,7 @@ const getArguments = (schema = webpackSchema) => {
350
373
 
351
374
  // Summarize flags
352
375
  for (const name of Object.keys(flags)) {
376
+ /** @type {Argument} */
353
377
  const argument = flags[name];
354
378
  argument.description = argument.configs.reduce((desc, { description }) => {
355
379
  if (!desc) return description;
@@ -357,27 +381,34 @@ const getArguments = (schema = webpackSchema) => {
357
381
  if (desc.includes(description)) return desc;
358
382
  return `${desc} ${description}`;
359
383
  }, /** @type {string | undefined} */ (undefined));
360
- argument.simpleType = argument.configs.reduce((t, argConfig) => {
361
- /** @type {"string" | "number" | "boolean"} */
362
- let type = "string";
363
- switch (argConfig.type) {
364
- case "number":
365
- type = "number";
366
- break;
367
- case "reset":
368
- case "boolean":
369
- type = "boolean";
370
- break;
371
- case "enum":
372
- if (argConfig.values.every(v => typeof v === "boolean"))
373
- type = "boolean";
374
- if (argConfig.values.every(v => typeof v === "number"))
375
- type = "number";
376
- break;
377
- }
378
- if (t === undefined) return type;
379
- return t === type ? t : "string";
380
- }, /** @type {"string" | "number" | "boolean" | undefined} */ (undefined));
384
+ argument.simpleType =
385
+ /** @type {SimpleType} */
386
+ (
387
+ argument.configs.reduce((t, argConfig) => {
388
+ /** @type {SimpleType} */
389
+ let type = "string";
390
+ switch (argConfig.type) {
391
+ case "number":
392
+ type = "number";
393
+ break;
394
+ case "reset":
395
+ case "boolean":
396
+ type = "boolean";
397
+ break;
398
+ case "enum": {
399
+ const values =
400
+ /** @type {NonNullable<ArgumentConfig["values"]>} */
401
+ (argConfig.values);
402
+
403
+ if (values.every(v => typeof v === "boolean")) type = "boolean";
404
+ if (values.every(v => typeof v === "number")) type = "number";
405
+ break;
406
+ }
407
+ }
408
+ if (t === undefined) return type;
409
+ return t === type ? t : "string";
410
+ }, /** @type {SimpleType | undefined} */ (undefined))
411
+ );
381
412
  argument.multiple = argument.configs.some(c => c.multiple);
382
413
  }
383
414
 
@@ -386,16 +417,18 @@ const getArguments = (schema = webpackSchema) => {
386
417
 
387
418
  const cliAddedItems = new WeakMap();
388
419
 
420
+ /** @typedef {string | number} Property */
421
+
389
422
  /**
390
- * @param {any} config configuration
423
+ * @param {Configuration} config configuration
391
424
  * @param {string} schemaPath path in the config
392
425
  * @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
393
- * @returns {{ problem?: LocalProblem, object?: any, property?: string | number, value?: any }} problem or object with property and value
426
+ * @returns {{ problem?: LocalProblem, object?: any, property?: Property, value?: any }} problem or object with property and value
394
427
  */
395
428
  const getObjectAndProperty = (config, schemaPath, index = 0) => {
396
429
  if (!schemaPath) return { value: config };
397
430
  const parts = schemaPath.split(".");
398
- let property = parts.pop();
431
+ const property = /** @type {string} */ (parts.pop());
399
432
  let current = config;
400
433
  let i = 0;
401
434
  for (const part of parts) {
@@ -434,22 +467,20 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
434
467
  }
435
468
  value = value[x];
436
469
  }
437
- } else {
438
- if (value === undefined) {
439
- value = current[name] = {};
440
- } else if (value === null || typeof value !== "object") {
441
- return {
442
- problem: {
443
- type: "unexpected-non-object-in-path",
444
- path: parts.slice(0, i).join(".")
445
- }
446
- };
447
- }
470
+ } else if (value === undefined) {
471
+ value = current[name] = {};
472
+ } else if (value === null || typeof value !== "object") {
473
+ return {
474
+ problem: {
475
+ type: "unexpected-non-object-in-path",
476
+ path: parts.slice(0, i).join(".")
477
+ }
478
+ };
448
479
  }
449
480
  current = value;
450
481
  i++;
451
482
  }
452
- let value = current[property];
483
+ const value = current[property];
453
484
  if (property.endsWith("[]")) {
454
485
  const name = property.slice(0, -2);
455
486
  const value = current[name];
@@ -461,36 +492,35 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
461
492
  current[name] = [value, ...Array.from({ length: index }), undefined];
462
493
  cliAddedItems.set(current[name], index + 1);
463
494
  return { object: current[name], property: index + 1, value: undefined };
464
- } else {
465
- let addedItems = cliAddedItems.get(value) || 0;
466
- while (addedItems <= index) {
467
- value.push(undefined);
468
- addedItems++;
469
- }
470
- cliAddedItems.set(value, addedItems);
471
- const x = value.length - addedItems + index;
472
- if (value[x] === undefined) {
473
- value[x] = {};
474
- } else if (value[x] === null || typeof value[x] !== "object") {
475
- return {
476
- problem: {
477
- type: "unexpected-non-object-in-path",
478
- path: schemaPath
479
- }
480
- };
481
- }
495
+ }
496
+ let addedItems = cliAddedItems.get(value) || 0;
497
+ while (addedItems <= index) {
498
+ value.push(undefined);
499
+ addedItems++;
500
+ }
501
+ cliAddedItems.set(value, addedItems);
502
+ const x = value.length - addedItems + index;
503
+ if (value[x] === undefined) {
504
+ value[x] = {};
505
+ } else if (value[x] === null || typeof value[x] !== "object") {
482
506
  return {
483
- object: value,
484
- property: x,
485
- value: value[x]
507
+ problem: {
508
+ type: "unexpected-non-object-in-path",
509
+ path: schemaPath
510
+ }
486
511
  };
487
512
  }
513
+ return {
514
+ object: value,
515
+ property: x,
516
+ value: value[x]
517
+ };
488
518
  }
489
519
  return { object: current, property, value };
490
520
  };
491
521
 
492
522
  /**
493
- * @param {any} config configuration
523
+ * @param {Configuration} config configuration
494
524
  * @param {string} schemaPath path in the config
495
525
  * @param {any} value parsed value
496
526
  * @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
@@ -503,14 +533,14 @@ const setValue = (config, schemaPath, value, index) => {
503
533
  index
504
534
  );
505
535
  if (problem) return problem;
506
- object[property] = value;
536
+ object[/** @type {Property} */ (property)] = value;
507
537
  return null;
508
538
  };
509
539
 
510
540
  /**
511
541
  * @param {ArgumentConfig} argConfig processing instructions
512
- * @param {any} config configuration
513
- * @param {any} value the value
542
+ * @param {Configuration} config configuration
543
+ * @param {Value} value the value
514
544
  * @param {number | undefined} index the index if multiple values provided
515
545
  * @returns {LocalProblem | null} a problem if any
516
546
  */
@@ -540,22 +570,26 @@ const processArgumentConfig = (argConfig, config, value, index) => {
540
570
  */
541
571
  const getExpectedValue = argConfig => {
542
572
  switch (argConfig.type) {
543
- default:
544
- return argConfig.type;
545
573
  case "boolean":
546
574
  return "true | false";
547
575
  case "RegExp":
548
576
  return "regular expression (example: /ab?c*/)";
549
577
  case "enum":
550
- return argConfig.values.map(v => `${v}`).join(" | ");
578
+ return /** @type {NonNullable<ArgumentConfig["values"]>} */ (
579
+ argConfig.values
580
+ )
581
+ .map(v => `${v}`)
582
+ .join(" | ");
551
583
  case "reset":
552
584
  return "true (will reset the previous value to an empty array)";
585
+ default:
586
+ return argConfig.type;
553
587
  }
554
588
  };
555
589
 
556
590
  /**
557
591
  * @param {ArgumentConfig} argConfig processing instructions
558
- * @param {any} value the value
592
+ * @param {Value} value the value
559
593
  * @returns {any | undefined} parsed value
560
594
  */
561
595
  const parseValueForArgumentConfig = (argConfig, value) => {
@@ -573,8 +607,8 @@ const parseValueForArgumentConfig = (argConfig, value) => {
573
607
  case "number":
574
608
  if (typeof value === "number") return value;
575
609
  if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
576
- const n = +value;
577
- if (!isNaN(n)) return n;
610
+ const n = Number(value);
611
+ if (!Number.isNaN(n)) return n;
578
612
  }
579
613
  break;
580
614
  case "boolean":
@@ -591,22 +625,28 @@ const parseValueForArgumentConfig = (argConfig, value) => {
591
625
  return new RegExp(match[1], match[2]);
592
626
  }
593
627
  break;
594
- case "enum":
595
- if (argConfig.values.includes(value)) return value;
596
- for (const item of argConfig.values) {
628
+ case "enum": {
629
+ const values =
630
+ /** @type {NonNullable<ArgumentConfig["values"]>} */
631
+ (argConfig.values);
632
+ if (values.includes(value)) return value;
633
+ for (const item of values) {
597
634
  if (`${item}` === value) return item;
598
635
  }
599
636
  break;
637
+ }
600
638
  case "reset":
601
639
  if (value === true) return [];
602
640
  break;
603
641
  }
604
642
  };
605
643
 
644
+ /** @typedef {any} Configuration */
645
+
606
646
  /**
607
- * @param {Record<string, Argument>} args object of arguments
608
- * @param {any} config configuration
609
- * @param {Record<string, string | number | boolean | RegExp | (string | number | boolean | RegExp)[]>} values object with values
647
+ * @param {Flags} args object of arguments
648
+ * @param {Configuration} config configuration
649
+ * @param {Record<string, Value[]>} values object with values
610
650
  * @returns {Problem[] | null} problems or null for success
611
651
  */
612
652
  const processArguments = (args, config, values) => {
@@ -622,6 +662,10 @@ const processArguments = (args, config, values) => {
622
662
  });
623
663
  continue;
624
664
  }
665
+ /**
666
+ * @param {Value} value value
667
+ * @param {number | undefined} i index
668
+ */
625
669
  const processValue = (value, i) => {
626
670
  const currentProblems = [];
627
671
  for (const argConfig of arg.configs) {
@@ -632,13 +676,13 @@ const processArguments = (args, config, values) => {
632
676
  currentProblems.push({
633
677
  ...problem,
634
678
  argument: key,
635
- value: value,
679
+ value,
636
680
  index: i
637
681
  });
638
682
  }
639
683
  problems.push(...currentProblems);
640
684
  };
641
- let value = values[key];
685
+ const value = values[key];
642
686
  if (Array.isArray(value)) {
643
687
  for (let i = 0; i < value.length; i++) {
644
688
  processValue(value[i], i);
@@ -651,5 +695,5 @@ const processArguments = (args, config, values) => {
651
695
  return problems;
652
696
  };
653
697
 
654
- exports.getArguments = getArguments;
655
- exports.processArguments = processArguments;
698
+ module.exports.getArguments = getArguments;
699
+ module.exports.processArguments = processArguments;
@@ -57,14 +57,14 @@ const load = (input, context) => {
57
57
  // if a query is specified, then use it, else
58
58
  // if a path to a config is specified then load it, else
59
59
  // find a nearest config
60
- const config = query
61
- ? query
62
- : configPath
60
+ const config =
61
+ query ||
62
+ (configPath
63
63
  ? browserslist.loadConfig({
64
64
  config: configPath,
65
65
  env
66
66
  })
67
- : browserslist.loadConfig({ path: context, env });
67
+ : browserslist.loadConfig({ path: context, env }));
68
68
 
69
69
  if (!config) return;
70
70
  return browserslist(config);
@@ -80,8 +80,8 @@ const resolve = browsers => {
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
- return 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];
@@ -94,19 +94,19 @@ const resolve = browsers => {
94
94
  ? parsedVersion.split("-")[0].split(".")
95
95
  : parsedVersion.split(".");
96
96
  if (typeof requiredVersion === "number") {
97
- return +parsedMajor >= requiredVersion;
97
+ return Number(parsedMajor) >= requiredVersion;
98
98
  }
99
- return requiredVersion[0] === +parsedMajor
100
- ? +parserMinor >= requiredVersion[1]
101
- : +parsedMajor > requiredVersion[0];
99
+ return requiredVersion[0] === Number(parsedMajor)
100
+ ? Number(parserMinor) >= requiredVersion[1]
101
+ : Number(parsedMajor) > requiredVersion[0];
102
102
  });
103
- };
104
- const anyNode = browsers.some(b => /^node /.test(b));
103
+ const anyNode = browsers.some(b => b.startsWith("node "));
105
104
  const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
106
105
  const browserProperty = !anyBrowser ? false : anyNode ? null : true;
107
106
  const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
108
107
  // Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
109
108
  const es6DynamicImport = rawChecker({
109
+ /* eslint-disable camelcase */
110
110
  chrome: 63,
111
111
  and_chr: 63,
112
112
  edge: 79,
@@ -124,9 +124,11 @@ const resolve = browsers => {
124
124
  and_uc: [15, 5],
125
125
  kaios: [3, 0],
126
126
  node: [12, 17]
127
+ /* eslint-enable camelcase */
127
128
  });
128
129
 
129
130
  return {
131
+ /* eslint-disable camelcase */
130
132
  const: rawChecker({
131
133
  chrome: 49,
132
134
  and_chr: 49,
@@ -331,6 +333,7 @@ const resolve = browsers => {
331
333
  kaios: 3,
332
334
  node: [7, 6]
333
335
  }),
336
+ /* eslint-enable camelcase */
334
337
  browser: browserProperty,
335
338
  electron: false,
336
339
  node: nodeProperty,
@@ -346,7 +349,7 @@ const resolve = browsers => {
346
349
  nodeBuiltins: nodeProperty,
347
350
  nodePrefixForCoreModules:
348
351
  nodeProperty &&
349
- !browsers.some(b => /^node 15/.test(b)) &&
352
+ !browsers.some(b => b.startsWith("node 15")) &&
350
353
  rawChecker({
351
354
  node: [14, 18]
352
355
  }),