webpack 5.103.0 → 5.104.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 (176) hide show
  1. package/hot/dev-server.js +18 -3
  2. package/hot/emitter-event-target.js +7 -0
  3. package/hot/lazy-compilation-node.js +45 -29
  4. package/hot/lazy-compilation-universal.js +18 -0
  5. package/hot/lazy-compilation-web.js +15 -5
  6. package/hot/load-http.js +7 -0
  7. package/hot/only-dev-server.js +19 -4
  8. package/lib/APIPlugin.js +6 -0
  9. package/lib/Chunk.js +1 -1
  10. package/lib/ChunkGraph.js +9 -7
  11. package/lib/ChunkGroup.js +8 -5
  12. package/lib/CleanPlugin.js +6 -3
  13. package/lib/CodeGenerationResults.js +2 -1
  14. package/lib/CompatibilityPlugin.js +3 -0
  15. package/lib/Compilation.js +33 -19
  16. package/lib/Compiler.js +3 -3
  17. package/lib/ContextModule.js +6 -3
  18. package/lib/ContextModuleFactory.js +6 -4
  19. package/lib/DefinePlugin.js +34 -3
  20. package/lib/DelegatedModule.js +7 -4
  21. package/lib/DllModule.js +6 -3
  22. package/lib/DotenvPlugin.js +11 -6
  23. package/lib/ExportsInfo.js +5 -5
  24. package/lib/ExternalModule.js +8 -7
  25. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  26. package/lib/FileSystemInfo.js +1 -1
  27. package/lib/Generator.js +10 -7
  28. package/lib/HookWebpackError.js +33 -4
  29. package/lib/HotModuleReplacementPlugin.js +22 -0
  30. package/lib/ManifestPlugin.js +1 -1
  31. package/lib/Module.js +24 -15
  32. package/lib/ModuleBuildError.js +1 -1
  33. package/lib/ModuleError.js +1 -1
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +27 -12
  36. package/lib/ModuleGraphConnection.js +2 -2
  37. package/lib/ModuleSourceTypeConstants.js +189 -0
  38. package/lib/ModuleTypeConstants.js +1 -4
  39. package/lib/ModuleWarning.js +1 -1
  40. package/lib/NodeStuffPlugin.js +52 -42
  41. package/lib/NormalModule.js +6 -4
  42. package/lib/NormalModuleFactory.js +7 -10
  43. package/lib/Parser.js +1 -1
  44. package/lib/RawModule.js +7 -4
  45. package/lib/RuntimeModule.js +1 -1
  46. package/lib/RuntimeTemplate.js +5 -1
  47. package/lib/SourceMapDevToolPlugin.js +6 -1
  48. package/lib/Template.js +17 -6
  49. package/lib/TemplatedPathPlugin.js +5 -6
  50. package/lib/WebpackError.js +0 -1
  51. package/lib/WebpackOptionsApply.js +37 -9
  52. package/lib/asset/AssetBytesGenerator.js +15 -11
  53. package/lib/asset/AssetGenerator.js +30 -24
  54. package/lib/asset/AssetSourceGenerator.js +15 -11
  55. package/lib/asset/RawDataUrlModule.js +6 -3
  56. package/lib/buildChunkGraph.js +4 -2
  57. package/lib/cache/PackFileCacheStrategy.js +6 -5
  58. package/lib/cli.js +2 -43
  59. package/lib/config/browserslistTargetHandler.js +19 -0
  60. package/lib/config/defaults.js +128 -43
  61. package/lib/config/normalization.js +2 -2
  62. package/lib/config/target.js +5 -0
  63. package/lib/container/ContainerEntryModule.js +6 -3
  64. package/lib/container/FallbackModule.js +6 -3
  65. package/lib/container/RemoteModule.js +1 -3
  66. package/lib/css/CssGenerator.js +26 -24
  67. package/lib/css/CssLoadingRuntimeModule.js +12 -4
  68. package/lib/css/CssModulesPlugin.js +29 -74
  69. package/lib/css/CssParser.js +828 -341
  70. package/lib/css/walkCssTokens.js +33 -13
  71. package/lib/dependencies/CachedConstDependency.js +24 -10
  72. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  73. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  74. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  75. package/lib/dependencies/CssIcssExportDependency.js +242 -104
  76. package/lib/dependencies/CssIcssImportDependency.js +61 -4
  77. package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
  78. package/lib/dependencies/CssImportDependency.js +2 -1
  79. package/lib/dependencies/CssUrlDependency.js +3 -2
  80. package/lib/dependencies/DynamicExports.js +7 -7
  81. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  82. package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
  83. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
  84. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
  85. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1 -1
  86. package/lib/dependencies/HarmonyExports.js +4 -4
  87. package/lib/dependencies/HarmonyImportDependency.js +8 -3
  88. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  89. package/lib/dependencies/ImportMetaPlugin.js +57 -0
  90. package/lib/dependencies/ImportParserPlugin.js +2 -2
  91. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  92. package/lib/dependencies/WorkerPlugin.js +2 -2
  93. package/lib/dependencies/getFunctionExpression.js +1 -1
  94. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  95. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  96. package/lib/hmr/LazyCompilationPlugin.js +4 -3
  97. package/lib/ids/IdHelpers.js +16 -7
  98. package/lib/javascript/ChunkHelpers.js +1 -1
  99. package/lib/javascript/JavascriptGenerator.js +4 -3
  100. package/lib/javascript/JavascriptModulesPlugin.js +57 -24
  101. package/lib/javascript/JavascriptParser.js +19 -6
  102. package/lib/json/JsonGenerator.js +5 -4
  103. package/lib/json/JsonParser.js +2 -1
  104. package/lib/library/AbstractLibraryPlugin.js +1 -1
  105. package/lib/library/AmdLibraryPlugin.js +4 -1
  106. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  107. package/lib/library/ModuleLibraryPlugin.js +41 -13
  108. package/lib/library/SystemLibraryPlugin.js +4 -1
  109. package/lib/library/UmdLibraryPlugin.js +1 -1
  110. package/lib/logging/Logger.js +5 -4
  111. package/lib/logging/createConsoleLogger.js +2 -2
  112. package/lib/optimize/ConcatenatedModule.js +47 -32
  113. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  114. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  115. package/lib/optimize/SplitChunksPlugin.js +60 -46
  116. package/lib/rules/RuleSetCompiler.js +1 -1
  117. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  118. package/lib/schemes/HttpUriPlugin.js +78 -7
  119. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  120. package/lib/serialization/ObjectMiddleware.js +0 -2
  121. package/lib/serialization/SingleItemMiddleware.js +1 -1
  122. package/lib/sharing/ConsumeSharedModule.js +1 -1
  123. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  124. package/lib/sharing/ProvideSharedModule.js +1 -1
  125. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  126. package/lib/sharing/utils.js +1 -1
  127. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  128. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  129. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  130. package/lib/util/StringXor.js +1 -1
  131. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  132. package/lib/util/binarySearchBounds.js +2 -2
  133. package/lib/util/comparators.js +53 -76
  134. package/lib/util/compileBooleanMatcher.js +78 -6
  135. package/lib/util/createHash.js +20 -199
  136. package/lib/util/deprecation.js +1 -1
  137. package/lib/util/deterministicGrouping.js +6 -3
  138. package/lib/util/fs.js +75 -75
  139. package/lib/util/hash/BatchedHash.js +10 -9
  140. package/lib/util/hash/BulkUpdateHash.js +138 -0
  141. package/lib/util/hash/DebugHash.js +75 -0
  142. package/lib/util/hash/hash-digest.js +216 -0
  143. package/lib/util/identifier.js +82 -17
  144. package/lib/util/internalSerializables.js +2 -6
  145. package/lib/util/runtime.js +3 -3
  146. package/lib/util/source.js +2 -2
  147. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  148. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
  149. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  150. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
  151. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  152. package/lib/webpack.js +1 -1
  153. package/package.json +29 -25
  154. package/schemas/WebpackOptions.check.js +1 -1
  155. package/schemas/WebpackOptions.json +59 -82
  156. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  157. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  158. package/types.d.ts +225 -157
  159. package/lib/ModuleSourceTypesConstants.js +0 -117
  160. package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
  161. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
  162. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
  163. package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
  164. package/lib/util/jsonParseEvenBetterErrors.js +0 -10
  165. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  166. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  167. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  168. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  169. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  170. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  171. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  173. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  174. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  175. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  176. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
package/lib/Template.js CHANGED
@@ -280,7 +280,7 @@ class Template {
280
280
  /**
281
281
  * @param {ChunkRenderContext} renderContext render context
282
282
  * @param {Module[]} modules modules to render (should be ordered by identifier)
283
- * @param {(module: Module) => Source | null} renderModule function to render a module
283
+ * @param {(module: Module, renderInArray?: boolean) => Source | null} renderModule function to render a module
284
284
  * @param {string=} prefix applying prefix strings
285
285
  * @returns {Source | null} rendered chunk modules in a Source object or null if no modules
286
286
  */
@@ -290,12 +290,20 @@ class Template {
290
290
  if (modules.length === 0) {
291
291
  return null;
292
292
  }
293
+ /** @type {{ id: ModuleId, module: Module }[]} */
294
+ const modulesWithId = modules.map((m) => ({
295
+ id: /** @type {ModuleId} */ (chunkGraph.getModuleId(m)),
296
+ module: m
297
+ }));
298
+ const bounds = Template.getModulesArrayBounds(modulesWithId);
299
+ const renderInObject = bounds === false;
300
+
293
301
  /** @type {{ id: ModuleId, source: Source | "false" }[]} */
294
- const allModules = modules.map((module) => ({
295
- id: /** @type {ModuleId} */ (chunkGraph.getModuleId(module)),
296
- source: renderModule(module) || "false"
302
+ const allModules = modulesWithId.map(({ id, module }) => ({
303
+ id,
304
+ source: renderModule(module, renderInObject) || "false"
297
305
  }));
298
- const bounds = Template.getModulesArrayBounds(allModules);
306
+
299
307
  if (bounds) {
300
308
  // Render a spare array
301
309
  const minId = bounds[0];
@@ -332,7 +340,9 @@ class Template {
332
340
  if (i !== 0) {
333
341
  source.add(",\n");
334
342
  }
335
- source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
343
+ source.add(
344
+ `\n/***/ ${JSON.stringify(module.id)}${renderContext.runtimeTemplate.supportsMethodShorthand() && module.source !== "false" ? "" : ":"}\n`
345
+ );
336
346
  source.add(module.source);
337
347
  }
338
348
  source.add(`\n\n${prefix}}`);
@@ -363,6 +373,7 @@ class Template {
363
373
  moduleGraph: renderContext.moduleGraph,
364
374
  runtimeTemplate: renderContext.runtimeTemplate,
365
375
  runtime: renderContext.chunk.runtime,
376
+ runtimes: [renderContext.chunk.runtime],
366
377
  codeGenerationResults
367
378
  });
368
379
  if (!codeGenResult) continue;
@@ -20,10 +20,7 @@ const { parseResource } = require("./util/identifier");
20
20
 
21
21
  const REGEXP = /\[\\*([\w:]+)\\*\]/gi;
22
22
 
23
- /**
24
- * @param {string | number} id id
25
- * @returns {string | number} result
26
- */
23
+ /** @type {PathData["prepareId"]} */
27
24
  const prepareId = (id) => {
28
25
  if (typeof id !== "string") return id;
29
26
 
@@ -303,7 +300,7 @@ const replacePathVariables = (path, data, assetInfo) => {
303
300
  const module = data.module;
304
301
 
305
302
  const idReplacer = replacer(() =>
306
- prepareId(
303
+ (data.prepareId || prepareId)(
307
304
  module instanceof Module
308
305
  ? /** @type {ModuleId} */
309
306
  (/** @type {ChunkGraph} */ (chunkGraph).getModuleId(module))
@@ -353,7 +350,9 @@ const replacePathVariables = (path, data, assetInfo) => {
353
350
  if (typeof data.runtime === "string") {
354
351
  replacements.set(
355
352
  "runtime",
356
- replacer(() => prepareId(/** @type {string} */ (data.runtime)))
353
+ replacer(() =>
354
+ (data.prepareId || prepareId)(/** @type {string} */ (data.runtime))
355
+ )
357
356
  );
358
357
  } else {
359
358
  replacements.set("runtime", replacer("_"));
@@ -21,7 +21,6 @@ class WebpackError extends Error {
21
21
  * @param {{ cause?: unknown }} options error options
22
22
  */
23
23
  constructor(message, options = {}) {
24
- // @ts-expect-error ES2018 doesn't `Error.cause`, but it can be used by developers
25
24
  super(message, options);
26
25
 
27
26
  /** @type {string=} */
@@ -111,11 +111,11 @@ class WebpackOptionsApply extends OptionsApply {
111
111
  const NodeTargetPlugin = require("./node/NodeTargetPlugin");
112
112
 
113
113
  // Some older versions of Node.js don't support all built-in modules via import, only via `require`,
114
- // but шt seems like there shouldn't be a warning here since these versions are rarely used in real applications
114
+ // but it seems like there shouldn't be a warning here since these versions are rarely used in real applications
115
115
  new NodeTargetPlugin(
116
116
  options.output.module &&
117
- compiler.platform.node === null &&
118
- compiler.platform.web === null
117
+ compiler.platform.node === null &&
118
+ compiler.platform.web === null
119
119
  ? "module-import"
120
120
  : "node-commonjs"
121
121
  ).apply(compiler);
@@ -408,6 +408,39 @@ class WebpackOptionsApply extends OptionsApply {
408
408
  typeof options.experiments.lazyCompilation === "object"
409
409
  ? options.experiments.lazyCompilation
410
410
  : {};
411
+ const isUniversalTarget =
412
+ options.output.module &&
413
+ compiler.platform.node === null &&
414
+ compiler.platform.web === null;
415
+
416
+ if (isUniversalTarget) {
417
+ const emitter = require.resolve("../hot/emitter-event-target.js");
418
+
419
+ const NormalModuleReplacementPlugin = require("./NormalModuleReplacementPlugin");
420
+
421
+ // Override emitter that using `EventEmitter` to `EventTarget`
422
+ // TODO webpack6 - migrate to `EventTarget` by default
423
+ new NormalModuleReplacementPlugin(/emitter(\.js)?$/, (result) => {
424
+ if (
425
+ /webpack[/\\]hot|webpack-dev-server[/\\]client|webpack-hot-middleware[/\\]client/.test(
426
+ result.context
427
+ )
428
+ ) {
429
+ result.request = emitter;
430
+ }
431
+
432
+ return result;
433
+ }).apply(compiler);
434
+ }
435
+
436
+ const backend = require.resolve(
437
+ isUniversalTarget
438
+ ? "../hot/lazy-compilation-universal.js"
439
+ : `../hot/lazy-compilation-${
440
+ options.externalsPresets.node ? "node" : "web"
441
+ }.js`
442
+ );
443
+
411
444
  new LazyCompilationPlugin({
412
445
  backend:
413
446
  typeof lazyOptions.backend === "function"
@@ -415,12 +448,7 @@ class WebpackOptionsApply extends OptionsApply {
415
448
  : require("./hmr/lazyCompilationBackend")({
416
449
  ...lazyOptions.backend,
417
450
  client:
418
- (lazyOptions.backend && lazyOptions.backend.client) ||
419
- require.resolve(
420
- `../hot/lazy-compilation-${
421
- options.externalsPresets.node ? "node" : "web"
422
- }.js`
423
- )
451
+ (lazyOptions.backend && lazyOptions.backend.client) || backend
424
452
  }),
425
453
  entries: !lazyOptions || lazyOptions.entries !== false,
426
454
  imports: !lazyOptions || lazyOptions.imports !== false,
@@ -9,16 +9,20 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const Generator = require("../Generator");
11
11
  const {
12
+ CSS_TYPE,
13
+ CSS_URL_TYPE,
12
14
  CSS_URL_TYPES,
13
- JS_AND_CSS_URL_TYPES,
14
- JS_TYPES,
15
+ JAVASCRIPT_AND_CSS_URL_TYPES,
16
+ JAVASCRIPT_TYPE,
17
+ JAVASCRIPT_TYPES,
15
18
  NO_TYPES
16
- } = require("../ModuleSourceTypesConstants");
19
+ } = require("../ModuleSourceTypeConstants");
17
20
  const RuntimeGlobals = require("../RuntimeGlobals");
18
21
 
19
22
  /** @typedef {import("webpack-sources").Source} Source */
20
23
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
21
24
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
25
+ /** @typedef {import("../Module").SourceType} SourceType */
22
26
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
23
27
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
24
28
  /** @typedef {import("../NormalModule")} NormalModule */
@@ -46,7 +50,7 @@ class AssetSourceGenerator extends Generator {
46
50
  const data = getData ? getData() : undefined;
47
51
 
48
52
  switch (type) {
49
- case "javascript": {
53
+ case JAVASCRIPT_TYPE: {
50
54
  if (!originalSource) {
51
55
  return new RawSource("");
52
56
  }
@@ -72,7 +76,7 @@ class AssetSourceGenerator extends Generator {
72
76
  }
73
77
  return new RawSource(sourceContent);
74
78
  }
75
- case "css-url": {
79
+ case CSS_URL_TYPE: {
76
80
  if (!originalSource) {
77
81
  return null;
78
82
  }
@@ -99,7 +103,7 @@ class AssetSourceGenerator extends Generator {
99
103
  */
100
104
  generateError(error, module, generateContext) {
101
105
  switch (generateContext.type) {
102
- case "javascript": {
106
+ case JAVASCRIPT_TYPE: {
103
107
  return new RawSource(
104
108
  `throw new Error(${JSON.stringify(error.message)});`
105
109
  );
@@ -136,12 +140,12 @@ class AssetSourceGenerator extends Generator {
136
140
  }
137
141
 
138
142
  if (sourceTypes.size > 0) {
139
- if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
140
- return JS_AND_CSS_URL_TYPES;
141
- } else if (sourceTypes.has("css")) {
143
+ if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
144
+ return JAVASCRIPT_AND_CSS_URL_TYPES;
145
+ } else if (sourceTypes.has(CSS_TYPE)) {
142
146
  return CSS_URL_TYPES;
143
147
  }
144
- return JS_TYPES;
148
+ return JAVASCRIPT_TYPES;
145
149
  }
146
150
 
147
151
  return NO_TYPES;
@@ -149,7 +153,7 @@ class AssetSourceGenerator extends Generator {
149
153
 
150
154
  /**
151
155
  * @param {NormalModule} module the module
152
- * @param {string=} type source type
156
+ * @param {SourceType=} type source type
153
157
  * @returns {number} estimate size of the module
154
158
  */
155
159
  getSize(module, type) {
@@ -11,14 +11,17 @@ const ConcatenationScope = require("../ConcatenationScope");
11
11
  const Generator = require("../Generator");
12
12
  const {
13
13
  ASSET_AND_CSS_URL_TYPES,
14
- ASSET_AND_JS_AND_CSS_URL_TYPES,
15
- ASSET_AND_JS_TYPES,
14
+ ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES,
15
+ ASSET_AND_JAVASCRIPT_TYPES,
16
16
  ASSET_TYPES,
17
+ CSS_TYPE,
18
+ CSS_URL_TYPE,
17
19
  CSS_URL_TYPES,
18
- JS_AND_CSS_URL_TYPES,
19
- JS_TYPES,
20
+ JAVASCRIPT_AND_CSS_URL_TYPES,
21
+ JAVASCRIPT_TYPE,
22
+ JAVASCRIPT_TYPES,
20
23
  NO_TYPES
21
- } = require("../ModuleSourceTypesConstants");
24
+ } = require("../ModuleSourceTypeConstants");
22
25
  const { ASSET_MODULE_TYPE } = require("../ModuleTypeConstants");
23
26
  const RuntimeGlobals = require("../RuntimeGlobals");
24
27
  const CssUrlDependency = require("../dependencies/CssUrlDependency");
@@ -43,6 +46,7 @@ const getMimeTypes = memoize(() => require("mime-types"));
43
46
  /** @typedef {import("../Module").NameForCondition} NameForCondition */
44
47
  /** @typedef {import("../Module").BuildInfo} BuildInfo */
45
48
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
49
+ /** @typedef {import("../Module").SourceType} SourceType */
46
50
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
47
51
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
48
52
  /** @typedef {import("../NormalModule")} NormalModule */
@@ -331,7 +335,7 @@ class AssetGenerator extends Generator {
331
335
 
332
336
  let assetPath;
333
337
 
334
- if (generatorOptions.publicPath !== undefined && type === "javascript") {
338
+ if (generatorOptions.publicPath !== undefined && type === JAVASCRIPT_TYPE) {
335
339
  const { path, info } = runtimeTemplate.compilation.getAssetPathWithInfo(
336
340
  generatorOptions.publicPath,
337
341
  {
@@ -346,7 +350,7 @@ class AssetGenerator extends Generator {
346
350
  assetPath = JSON.stringify(path + filename);
347
351
  } else if (
348
352
  generatorOptions.publicPath !== undefined &&
349
- type === "css-url"
353
+ type === CSS_URL_TYPE
350
354
  ) {
351
355
  const { path, info } = runtimeTemplate.compilation.getAssetPathWithInfo(
352
356
  generatorOptions.publicPath,
@@ -360,14 +364,14 @@ class AssetGenerator extends Generator {
360
364
  );
361
365
  assetInfo = mergeAssetInfo(assetInfo, info);
362
366
  assetPath = path + filename;
363
- } else if (type === "javascript") {
367
+ } else if (type === JAVASCRIPT_TYPE) {
364
368
  // add __webpack_require__.p
365
369
  runtimeRequirements.add(RuntimeGlobals.publicPath);
366
370
  assetPath = runtimeTemplate.concatenation(
367
371
  { expr: RuntimeGlobals.publicPath },
368
372
  filename
369
373
  );
370
- } else if (type === "css-url") {
374
+ } else if (type === CSS_URL_TYPE) {
371
375
  const compilation = runtimeTemplate.compilation;
372
376
  const path =
373
377
  compilation.outputOptions.publicPath === "auto"
@@ -518,7 +522,7 @@ class AssetGenerator extends Generator {
518
522
 
519
523
  let content;
520
524
 
521
- const needContent = type === "javascript" || type === "css-url";
525
+ const needContent = type === JAVASCRIPT_TYPE || type === CSS_URL_TYPE;
522
526
 
523
527
  const data = getData ? getData() : undefined;
524
528
 
@@ -529,7 +533,9 @@ class AssetGenerator extends Generator {
529
533
  ) {
530
534
  const encodedSource = this.generateDataUri(module);
531
535
  content =
532
- type === "javascript" ? JSON.stringify(encodedSource) : encodedSource;
536
+ type === JAVASCRIPT_TYPE
537
+ ? JSON.stringify(encodedSource)
538
+ : encodedSource;
533
539
 
534
540
  if (data) {
535
541
  data.set("url", { [type]: content, ...data.get("url") });
@@ -570,7 +576,7 @@ class AssetGenerator extends Generator {
570
576
  contentHash
571
577
  );
572
578
 
573
- if (data && (type === "javascript" || type === "css-url")) {
579
+ if (data && (type === JAVASCRIPT_TYPE || type === CSS_URL_TYPE)) {
574
580
  data.set("url", { [type]: assetPath, ...data.get("url") });
575
581
  }
576
582
 
@@ -598,7 +604,7 @@ class AssetGenerator extends Generator {
598
604
  content = assetPath;
599
605
  }
600
606
 
601
- if (type === "javascript") {
607
+ if (type === JAVASCRIPT_TYPE) {
602
608
  if (concatenationScope) {
603
609
  concatenationScope.registerNamespaceExport(
604
610
  ConcatenationScope.NAMESPACE_OBJECT_EXPORT
@@ -614,7 +620,7 @@ class AssetGenerator extends Generator {
614
620
  runtimeRequirements.add(RuntimeGlobals.module);
615
621
 
616
622
  return new RawSource(`${module.moduleArgument}.exports = ${content};`);
617
- } else if (type === "css-url") {
623
+ } else if (type === CSS_URL_TYPE) {
618
624
  return null;
619
625
  }
620
626
 
@@ -632,7 +638,7 @@ class AssetGenerator extends Generator {
632
638
  case "asset": {
633
639
  return new RawSource(error.message);
634
640
  }
635
- case "javascript": {
641
+ case JAVASCRIPT_TYPE: {
636
642
  return new RawSource(
637
643
  `throw new Error(${JSON.stringify(error.message)});`
638
644
  );
@@ -661,24 +667,24 @@ class AssetGenerator extends Generator {
661
667
 
662
668
  if ((module.buildInfo && module.buildInfo.dataUrl) || this.emit === false) {
663
669
  if (sourceTypes.size > 0) {
664
- if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
665
- return JS_AND_CSS_URL_TYPES;
666
- } else if (sourceTypes.has("css")) {
670
+ if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
671
+ return JAVASCRIPT_AND_CSS_URL_TYPES;
672
+ } else if (sourceTypes.has(CSS_TYPE)) {
667
673
  return CSS_URL_TYPES;
668
674
  }
669
- return JS_TYPES;
675
+ return JAVASCRIPT_TYPES;
670
676
  }
671
677
 
672
678
  return NO_TYPES;
673
679
  }
674
680
 
675
681
  if (sourceTypes.size > 0) {
676
- if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
677
- return ASSET_AND_JS_AND_CSS_URL_TYPES;
678
- } else if (sourceTypes.has("css")) {
682
+ if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
683
+ return ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES;
684
+ } else if (sourceTypes.has(CSS_TYPE)) {
679
685
  return ASSET_AND_CSS_URL_TYPES;
680
686
  }
681
- return ASSET_AND_JS_TYPES;
687
+ return ASSET_AND_JAVASCRIPT_TYPES;
682
688
  }
683
689
 
684
690
  return ASSET_TYPES;
@@ -686,7 +692,7 @@ class AssetGenerator extends Generator {
686
692
 
687
693
  /**
688
694
  * @param {NormalModule} module the module
689
- * @param {string=} type source type
695
+ * @param {SourceType=} type source type
690
696
  * @returns {number} estimate size of the module
691
697
  */
692
698
  getSize(module, type) {
@@ -9,16 +9,20 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const Generator = require("../Generator");
11
11
  const {
12
+ CSS_TYPE,
13
+ CSS_URL_TYPE,
12
14
  CSS_URL_TYPES,
13
- JS_AND_CSS_URL_TYPES,
14
- JS_TYPES,
15
+ JAVASCRIPT_AND_CSS_URL_TYPES,
16
+ JAVASCRIPT_TYPE,
17
+ JAVASCRIPT_TYPES,
15
18
  NO_TYPES
16
- } = require("../ModuleSourceTypesConstants");
19
+ } = require("../ModuleSourceTypeConstants");
17
20
  const RuntimeGlobals = require("../RuntimeGlobals");
18
21
 
19
22
  /** @typedef {import("webpack-sources").Source} Source */
20
23
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
21
24
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
25
+ /** @typedef {import("../Module").SourceType} SourceType */
22
26
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
23
27
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
24
28
  /** @typedef {import("../NormalModule")} NormalModule */
@@ -46,7 +50,7 @@ class AssetSourceGenerator extends Generator {
46
50
  const data = getData ? getData() : undefined;
47
51
 
48
52
  switch (type) {
49
- case "javascript": {
53
+ case JAVASCRIPT_TYPE: {
50
54
  if (!originalSource) {
51
55
  return new RawSource("");
52
56
  }
@@ -71,7 +75,7 @@ class AssetSourceGenerator extends Generator {
71
75
  }
72
76
  return new RawSource(sourceContent);
73
77
  }
74
- case "css-url": {
78
+ case CSS_URL_TYPE: {
75
79
  if (!originalSource) {
76
80
  return null;
77
81
  }
@@ -98,7 +102,7 @@ class AssetSourceGenerator extends Generator {
98
102
  */
99
103
  generateError(error, module, generateContext) {
100
104
  switch (generateContext.type) {
101
- case "javascript": {
105
+ case JAVASCRIPT_TYPE: {
102
106
  return new RawSource(
103
107
  `throw new Error(${JSON.stringify(error.message)});`
104
108
  );
@@ -135,12 +139,12 @@ class AssetSourceGenerator extends Generator {
135
139
  }
136
140
 
137
141
  if (sourceTypes.size > 0) {
138
- if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
139
- return JS_AND_CSS_URL_TYPES;
140
- } else if (sourceTypes.has("css")) {
142
+ if (sourceTypes.has(JAVASCRIPT_TYPE) && sourceTypes.has(CSS_TYPE)) {
143
+ return JAVASCRIPT_AND_CSS_URL_TYPES;
144
+ } else if (sourceTypes.has(CSS_TYPE)) {
141
145
  return CSS_URL_TYPES;
142
146
  }
143
- return JS_TYPES;
147
+ return JAVASCRIPT_TYPES;
144
148
  }
145
149
 
146
150
  return NO_TYPES;
@@ -148,7 +152,7 @@ class AssetSourceGenerator extends Generator {
148
152
 
149
153
  /**
150
154
  * @param {NormalModule} module the module
151
- * @param {string=} type source type
155
+ * @param {SourceType=} type source type
152
156
  * @returns {number} estimate size of the module
153
157
  */
154
158
  getSize(module, type) {
@@ -7,7 +7,10 @@
7
7
 
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Module = require("../Module");
10
- const { JS_TYPES } = require("../ModuleSourceTypesConstants");
10
+ const {
11
+ JAVASCRIPT_TYPE,
12
+ JAVASCRIPT_TYPES
13
+ } = require("../ModuleSourceTypeConstants");
11
14
  const { ASSET_MODULE_TYPE_RAW_DATA_URL } = require("../ModuleTypeConstants");
12
15
  const RuntimeGlobals = require("../RuntimeGlobals");
13
16
  const makeSerializable = require("../util/makeSerializable");
@@ -47,7 +50,7 @@ class RawDataUrlModule extends Module {
47
50
  * @returns {SourceTypes} types available (do not mutate)
48
51
  */
49
52
  getSourceTypes() {
50
- return JS_TYPES;
53
+ return JAVASCRIPT_TYPES;
51
54
  }
52
55
 
53
56
  /**
@@ -113,7 +116,7 @@ class RawDataUrlModule extends Module {
113
116
  }
114
117
  const sources = new Map();
115
118
  sources.set(
116
- "javascript",
119
+ JAVASCRIPT_TYPE,
117
120
  new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
118
121
  );
119
122
  const data = new Map();
@@ -352,10 +352,12 @@ const visitModules = (
352
352
  /** @type {Map<ChunkGroupInfo, Set<DependenciesBlock>>} */
353
353
  const blocksByChunkGroups = new Map();
354
354
 
355
- /** @type {Map<string, ChunkGroupInfo>} */
355
+ /** @typedef {Map<string, ChunkGroupInfo>} NamedChunkGroup */
356
+
357
+ /** @type {NamedChunkGroup} */
356
358
  const namedChunkGroups = new Map();
357
359
 
358
- /** @type {Map<string, ChunkGroupInfo>} */
360
+ /** @type {NamedChunkGroup} */
359
361
  const namedAsyncEntrypoints = new Map();
360
362
 
361
363
  /** @type {Set<ChunkGroupInfo>} */
@@ -18,6 +18,7 @@ const {
18
18
  } = require("../util/serialization");
19
19
 
20
20
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
21
+ /** @typedef {import("../Compilation").FileSystemDependencies} FileSystemDependencies */
21
22
  /** @typedef {import("../Cache").Data} Data */
22
23
  /** @typedef {import("../Cache").Etag} Etag */
23
24
  /** @typedef {import("../Compiler")} Compiler */
@@ -51,7 +52,7 @@ class PackContainer {
51
52
  resolveResults,
52
53
  resolveBuildDependenciesSnapshot
53
54
  ) {
54
- /** @type {Pack | (() => Pack) } */
55
+ /** @type {Pack | (() => Pack)} */
55
56
  this.data = data;
56
57
  /** @type {string} */
57
58
  this.version = version;
@@ -395,7 +396,7 @@ class Pack {
395
396
  return;
396
397
  }
397
398
 
398
- /** @type {PackContent[] } */
399
+ /** @type {PackContent[]} */
399
400
  const mergedContent = [];
400
401
 
401
402
  // 3. Remove old content entries
@@ -1109,7 +1110,7 @@ class PackFileCacheStrategy {
1109
1110
  compression,
1110
1111
  readonly
1111
1112
  }) {
1112
- /** @type {import("../serialization/Serializer")<PackContainer, null, {}>} */
1113
+ /** @type {import("../serialization/Serializer")<PackContainer, null, EXPECTED_OBJECT>} */
1113
1114
  this.fileSerializer = createFileSerializer(
1114
1115
  fs,
1115
1116
  /** @type {string | Hash} */
@@ -1140,7 +1141,7 @@ class PackFileCacheStrategy {
1140
1141
  this.snapshot = snapshot;
1141
1142
  /** @type {BuildDependencies} */
1142
1143
  this.buildDependencies = new Set();
1143
- /** @type {LazySet<string>} */
1144
+ /** @type {FileSystemDependencies} */
1144
1145
  this.newBuildDependencies = new LazySet();
1145
1146
  /** @type {Snapshot | undefined} */
1146
1147
  this.resolveBuildDependenciesSnapshot = undefined;
@@ -1364,7 +1365,7 @@ class PackFileCacheStrategy {
1364
1365
  }
1365
1366
 
1366
1367
  /**
1367
- * @param {LazySet<string> | Iterable<string>} dependencies dependencies to store
1368
+ * @param {FileSystemDependencies | Iterable<string>} dependencies dependencies to store
1368
1369
  */
1369
1370
  storeBuildDependencies(dependencies) {
1370
1371
  if (this.readonly) return;
package/lib/cli.js CHANGED
@@ -795,49 +795,8 @@ const init = (open, close, replace) =>
795
795
  filterEmpty(`\u001B[${open}m`, `\u001B[${close}m`, replace);
796
796
 
797
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 */
798
+ * @typedef {{ reset: PrintFunction, bold: PrintFunction, dim: PrintFunction, italic: PrintFunction, underline: PrintFunction, inverse: PrintFunction, hidden: PrintFunction, strikethrough: PrintFunction, black: PrintFunction, red: PrintFunction, green: PrintFunction, yellow: PrintFunction, blue: PrintFunction, magenta: PrintFunction, cyan: PrintFunction, white: PrintFunction, gray: PrintFunction, bgBlack: PrintFunction, bgRed: PrintFunction, bgGreen: PrintFunction, bgYellow: PrintFunction, bgBlue: PrintFunction, bgMagenta: PrintFunction, bgCyan: PrintFunction, bgWhite: PrintFunction, blackBright: PrintFunction, redBright: PrintFunction, greenBright: PrintFunction, yellowBright: PrintFunction, blueBright: PrintFunction, magentaBright: PrintFunction, cyanBright: PrintFunction, whiteBright: PrintFunction, bgBlackBright: PrintFunction, bgRedBright: PrintFunction, bgGreenBright: PrintFunction, bgYellowBright: PrintFunction, bgBlueBright: PrintFunction, bgMagentaBright: PrintFunction, bgCyanBright: PrintFunction, bgWhiteBright: PrintFunction }} Colors
799
+ */
841
800
 
842
801
  /**
843
802
  * @typedef {object} ColorsOptions
@@ -118,6 +118,25 @@ const resolve = (browsers) => {
118
118
  kaios: [2, 5],
119
119
  node: [6, 0]
120
120
  }),
121
+ methodShorthand: rawChecker({
122
+ chrome: 47,
123
+ and_chr: 47,
124
+ edge: 12,
125
+ firefox: 34,
126
+ and_ff: 34,
127
+ // ie: Not supported,
128
+ opera: 34,
129
+ op_mob: 34,
130
+ safari: 9,
131
+ ios_saf: 9,
132
+ samsung: 5,
133
+ android: 47,
134
+ // baidu: Not tracked,
135
+ and_qq: [14, 9],
136
+ and_uc: [15, 5],
137
+ kaios: [2, 5],
138
+ node: [4, 9]
139
+ }),
121
140
  arrowFunction: rawChecker({
122
141
  chrome: 45,
123
142
  and_chr: 45,