webpack 5.102.0 → 5.103.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 (146) hide show
  1. package/README.md +121 -134
  2. package/lib/ChunkGraph.js +2 -2
  3. package/lib/CodeGenerationResults.js +1 -1
  4. package/lib/CompatibilityPlugin.js +25 -2
  5. package/lib/Compilation.js +30 -13
  6. package/lib/ConcatenationScope.js +0 -15
  7. package/lib/ContextModule.js +3 -1
  8. package/lib/CssModule.js +6 -1
  9. package/lib/DefinePlugin.js +12 -12
  10. package/lib/Dependency.js +8 -1
  11. package/lib/DependencyTemplate.js +1 -0
  12. package/lib/DependencyTemplates.js +1 -1
  13. package/lib/DotenvPlugin.js +457 -0
  14. package/lib/EnvironmentPlugin.js +19 -16
  15. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  16. package/lib/ExportsInfo.js +6 -2
  17. package/lib/ExternalModule.js +20 -28
  18. package/lib/ExternalModuleFactoryPlugin.js +10 -8
  19. package/lib/ExternalsPlugin.js +2 -1
  20. package/lib/FileSystemInfo.js +9 -12
  21. package/lib/ManifestPlugin.js +235 -0
  22. package/lib/Module.js +3 -0
  23. package/lib/ModuleFilenameHelpers.js +1 -1
  24. package/lib/ModuleGraph.js +2 -1
  25. package/lib/ModuleSourceTypesConstants.js +0 -6
  26. package/lib/MultiCompiler.js +1 -1
  27. package/lib/NodeStuffPlugin.js +419 -121
  28. package/lib/NormalModule.js +18 -17
  29. package/lib/NormalModuleFactory.js +75 -4
  30. package/lib/RuntimeGlobals.js +22 -4
  31. package/lib/RuntimePlugin.js +27 -6
  32. package/lib/RuntimeTemplate.js +125 -57
  33. package/lib/SourceMapDevToolPlugin.js +26 -8
  34. package/lib/WebpackOptionsApply.js +33 -9
  35. package/lib/asset/AssetBytesGenerator.js +2 -1
  36. package/lib/asset/AssetGenerator.js +3 -5
  37. package/lib/asset/AssetSourceGenerator.js +1 -1
  38. package/lib/cache/getLazyHashedEtag.js +1 -1
  39. package/lib/config/browserslistTargetHandler.js +82 -76
  40. package/lib/config/defaults.js +105 -20
  41. package/lib/config/normalization.js +2 -1
  42. package/lib/config/target.js +7 -1
  43. package/lib/css/CssGenerator.js +283 -57
  44. package/lib/css/CssLoadingRuntimeModule.js +2 -0
  45. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  46. package/lib/css/CssModulesPlugin.js +86 -40
  47. package/lib/css/CssParser.js +1174 -667
  48. package/lib/css/walkCssTokens.js +98 -1
  49. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  50. package/lib/dependencies/CommonJsPlugin.js +12 -0
  51. package/lib/dependencies/ContextElementDependency.js +2 -2
  52. package/lib/dependencies/CssIcssExportDependency.js +247 -8
  53. package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
  54. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
  55. package/lib/dependencies/CssIcssImportDependency.js +60 -54
  56. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
  57. package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
  58. package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
  59. package/lib/dependencies/CssImportDependency.js +15 -5
  60. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  61. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
  62. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  63. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  64. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
  67. package/lib/dependencies/HarmonyImportDependency.js +27 -28
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  71. package/lib/dependencies/ImportContextDependency.js +13 -0
  72. package/lib/dependencies/ImportDependency.js +10 -4
  73. package/lib/dependencies/ImportEagerDependency.js +6 -3
  74. package/lib/dependencies/ImportMetaPlugin.js +98 -10
  75. package/lib/dependencies/ImportParserPlugin.js +19 -21
  76. package/lib/dependencies/ImportPhase.js +121 -0
  77. package/lib/dependencies/ImportWeakDependency.js +6 -3
  78. package/lib/dependencies/ModuleDependency.js +5 -1
  79. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  80. package/lib/dependencies/WorkerPlugin.js +1 -3
  81. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  82. package/lib/hmr/LazyCompilationPlugin.js +1 -0
  83. package/lib/ids/HashedModuleIdsPlugin.js +5 -7
  84. package/lib/ids/IdHelpers.js +5 -2
  85. package/lib/index.js +6 -0
  86. package/lib/javascript/ChunkHelpers.js +16 -5
  87. package/lib/javascript/JavascriptGenerator.js +101 -101
  88. package/lib/javascript/JavascriptModulesPlugin.js +25 -16
  89. package/lib/javascript/JavascriptParser.js +143 -39
  90. package/lib/json/JsonParser.js +7 -1
  91. package/lib/library/ModuleLibraryPlugin.js +0 -10
  92. package/lib/library/SystemLibraryPlugin.js +19 -5
  93. package/lib/library/UmdLibraryPlugin.js +1 -1
  94. package/lib/node/NodeTargetPlugin.js +9 -1
  95. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  96. package/lib/optimize/ConcatenatedModule.js +161 -135
  97. package/lib/optimize/RealContentHashPlugin.js +5 -3
  98. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  99. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  100. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  101. package/lib/serialization/FileMiddleware.js +1 -1
  102. package/lib/serialization/ObjectMiddleware.js +1 -1
  103. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  104. package/lib/util/Hash.js +35 -5
  105. package/lib/util/comparators.js +4 -3
  106. package/lib/util/create-schema-validation.js +1 -1
  107. package/lib/util/createHash.js +85 -15
  108. package/lib/util/hash/BatchedHash.js +47 -8
  109. package/lib/util/hash/wasm-hash.js +53 -13
  110. package/lib/util/internalSerializables.js +4 -4
  111. package/lib/util/jsonParseEvenBetterErrors.js +10 -0
  112. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  113. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
  114. package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
  115. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
  116. package/lib/wasm-sync/WebAssemblyParser.js +0 -9
  117. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  118. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  119. package/lib/webpack.js +85 -82
  120. package/module.d.ts +5 -0
  121. package/package.json +28 -26
  122. package/schemas/WebpackOptions.check.js +1 -1
  123. package/schemas/WebpackOptions.json +110 -15
  124. package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
  125. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  126. package/schemas/plugins/ManifestPlugin.json +98 -0
  127. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  128. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  129. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  130. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  131. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  132. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  133. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  134. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  135. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  136. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  137. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  138. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  139. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  140. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  141. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  142. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  143. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  144. package/types.d.ts +788 -127
  145. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
  146. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
@@ -134,6 +134,7 @@ const { isSourceEqual } = require("./util/source");
134
134
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
135
135
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
136
136
  /** @typedef {import("./util/Hash")} Hash */
137
+
137
138
  /**
138
139
  * @template T
139
140
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
@@ -296,6 +297,7 @@ const { isSourceEqual } = require("./util/source");
296
297
  * @property {boolean=} development true, when asset is only used for development and doesn't count towards user-facing assets
297
298
  * @property {boolean=} hotModuleReplacement true, when asset ships data for updating an existing application (HMR)
298
299
  * @property {boolean=} javascriptModule true, when asset is javascript and an ESM
300
+ * @property {boolean=} manifest true, when file is a manifest
299
301
  * @property {Record<string, null | string | string[]>=} related object of pointers to other assets, keyed by type of relation (only points from parent to child)
300
302
  */
301
303
 
@@ -1635,6 +1637,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1635
1637
  _processModuleDependencies(module, callback) {
1636
1638
  /** @type {{ factory: ModuleFactory, dependencies: Dependency[], context: string | undefined, originModule: Module | null }[]} */
1637
1639
  const sortedDependencies = [];
1640
+ /** @type {boolean} */
1641
+ const hasLowPriorityDependencies = module.dependencies.some(
1642
+ Dependency.isLowPriorityDependency
1643
+ );
1638
1644
 
1639
1645
  /** @type {DependenciesBlock} */
1640
1646
  let currentBlock;
@@ -1882,12 +1888,29 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1882
1888
  if (list === undefined) {
1883
1889
  /** @type {FactoryCacheValue} */
1884
1890
  (factoryCacheValue).set(cacheKey, (list = []));
1885
- sortedDependencies.push({
1891
+ const newItem = {
1886
1892
  factory: factoryCacheKey2,
1887
1893
  dependencies: list,
1888
1894
  context: dep.getContext(),
1889
1895
  originModule: module
1890
- });
1896
+ };
1897
+ if (hasLowPriorityDependencies) {
1898
+ let insertIndex = sortedDependencies.length;
1899
+ while (insertIndex > 0) {
1900
+ const item = sortedDependencies[insertIndex - 1];
1901
+ const isAllLowPriorityDependencies = item.dependencies.every(
1902
+ Dependency.isLowPriorityDependency
1903
+ );
1904
+ if (isAllLowPriorityDependencies) {
1905
+ insertIndex--;
1906
+ } else {
1907
+ break;
1908
+ }
1909
+ }
1910
+ sortedDependencies.splice(insertIndex, 0, newItem);
1911
+ } else {
1912
+ sortedDependencies.push(newItem);
1913
+ }
1891
1914
  }
1892
1915
  list.push(dep);
1893
1916
  listCacheKey1 = category;
@@ -4378,7 +4401,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4378
4401
  runtime,
4379
4402
  runtimeTemplate
4380
4403
  });
4381
- moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
4404
+ moduleHashDigest = moduleHash.digest(hashDigest);
4382
4405
  } catch (err) {
4383
4406
  errors.push(new ModuleHashingError(module, /** @type {Error} */ (err)));
4384
4407
  moduleHashDigest = "XXXXXX";
@@ -4601,9 +4624,7 @@ This prevents using hashes of each other and should be avoided.`);
4601
4624
  moduleGraph: this.moduleGraph,
4602
4625
  runtimeTemplate: this.runtimeTemplate
4603
4626
  });
4604
- const chunkHashDigest = /** @type {string} */ (
4605
- chunkHash.digest(hashDigest)
4606
- );
4627
+ const chunkHashDigest = chunkHash.digest(hashDigest);
4607
4628
  hash.update(chunkHashDigest);
4608
4629
  chunk.hash = chunkHashDigest;
4609
4630
  chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
@@ -4637,7 +4658,7 @@ This prevents using hashes of each other and should be avoided.`);
4637
4658
  this.logger.timeAggregateEnd("hashing: hash chunks");
4638
4659
  this.logger.time("hashing: hash digest");
4639
4660
  this.hooks.fullHash.call(hash);
4640
- this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4661
+ this.fullHash = hash.digest(hashDigest);
4641
4662
  this.hash = this.fullHash.slice(0, hashDigestLength);
4642
4663
  this.logger.timeEnd("hashing: hash digest");
4643
4664
 
@@ -4652,9 +4673,7 @@ This prevents using hashes of each other and should be avoided.`);
4652
4673
  runtime: chunk.runtime,
4653
4674
  runtimeTemplate
4654
4675
  });
4655
- const moduleHashDigest = /** @type {string} */ (
4656
- moduleHash.digest(hashDigest)
4657
- );
4676
+ const moduleHashDigest = moduleHash.digest(hashDigest);
4658
4677
  const oldHash = chunkGraph.getModuleHash(module, chunk.runtime);
4659
4678
  chunkGraph.setModuleHashes(
4660
4679
  module,
@@ -4671,9 +4690,7 @@ This prevents using hashes of each other and should be avoided.`);
4671
4690
  const chunkHash = createHash(hashFunction);
4672
4691
  chunkHash.update(chunk.hash);
4673
4692
  chunkHash.update(this.hash);
4674
- const chunkHashDigest =
4675
- /** @type {string} */
4676
- (chunkHash.digest(hashDigest));
4693
+ const chunkHashDigest = chunkHash.digest(hashDigest);
4677
4694
  chunk.hash = chunkHashDigest;
4678
4695
  chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4679
4696
  this.hooks.contentHash.call(chunk);
@@ -112,18 +112,6 @@ class ConcatenationScope {
112
112
  this._currentModule.namespaceExportSymbol = symbol;
113
113
  }
114
114
 
115
- /**
116
- * @param {string} symbol identifier of the export in source code
117
- * @returns {boolean} registered success
118
- */
119
- registerUsedName(symbol) {
120
- if (this.usedNames.has(symbol)) {
121
- return false;
122
- }
123
- this.usedNames.add(symbol);
124
- return true;
125
- }
126
-
127
115
  /**
128
116
  * @param {Module} module the referenced module
129
117
  * @param {Partial<ModuleReferenceOptions>} options options
@@ -189,7 +177,4 @@ class ConcatenationScope {
189
177
  ConcatenationScope.DEFAULT_EXPORT = DEFAULT_EXPORT;
190
178
  ConcatenationScope.NAMESPACE_OBJECT_EXPORT = NAMESPACE_OBJECT_EXPORT;
191
179
 
192
- /** @type {WeakMap<Chunk, Set<string>>} */
193
- ConcatenationScope.chunkUsedNames = new WeakMap();
194
-
195
180
  module.exports = ConcatenationScope;
@@ -254,10 +254,12 @@ class ContextModule extends Module {
254
254
  } else if (this.options.namespaceObject) {
255
255
  identifier += "|namespace object";
256
256
  }
257
+ if (this.options.attributes) {
258
+ identifier += `|importAttributes: ${JSON.stringify(this.options.attributes)}`;
259
+ }
257
260
  if (this.layer) {
258
261
  identifier += `|layer: ${this.layer}`;
259
262
  }
260
-
261
263
  return identifier;
262
264
  }
263
265
 
package/lib/CssModule.js CHANGED
@@ -30,9 +30,13 @@ class CssModule extends NormalModule {
30
30
  super(options);
31
31
 
32
32
  // Avoid override `layer` for `Module` class, because it is a feature to run module in specific layer
33
+ /** @type {CSSModuleCreateData['cssLayer']} */
33
34
  this.cssLayer = options.cssLayer;
35
+ /** @type {CSSModuleCreateData['supports']} */
34
36
  this.supports = options.supports;
37
+ /** @type {CSSModuleCreateData['media']} */
35
38
  this.media = options.media;
39
+ /** @type {CSSModuleCreateData['inheritance']} */
36
40
  this.inheritance = options.inheritance;
37
41
  }
38
42
 
@@ -150,7 +154,8 @@ class CssModule extends NormalModule {
150
154
  cssLayer: /** @type {EXPECTED_ANY} */ (null),
151
155
  supports: /** @type {EXPECTED_ANY} */ (null),
152
156
  media: /** @type {EXPECTED_ANY} */ (null),
153
- inheritance: /** @type {EXPECTED_ANY} */ (null)
157
+ inheritance: /** @type {EXPECTED_ANY} */ (null),
158
+ extractSourceMap: /** @type {EXPECTED_ANY} */ (null)
154
159
  });
155
160
  obj.deserialize(context);
156
161
  return obj;
@@ -354,20 +354,20 @@ class DefinePlugin {
354
354
  * @returns {void}
355
355
  */
356
356
  apply(compiler) {
357
- const definitions = this.definitions;
358
-
359
- /**
360
- * @type {Map<string, Set<string>>}
361
- */
362
- const finalByNestedKey = new Map();
363
- /**
364
- * @type {Map<string, Set<string>>}
365
- */
366
- const nestedByFinalKey = new Map();
367
-
368
357
  compiler.hooks.compilation.tap(
369
358
  PLUGIN_NAME,
370
359
  (compilation, { normalModuleFactory }) => {
360
+ const definitions = this.definitions;
361
+
362
+ /**
363
+ * @type {Map<string, Set<string>>}
364
+ */
365
+ const finalByNestedKey = new Map();
366
+ /**
367
+ * @type {Map<string, Set<string>>}
368
+ */
369
+ const nestedByFinalKey = new Map();
370
+
371
371
  const logger = compilation.getLogger("webpack.DefinePlugin");
372
372
  compilation.dependencyTemplates.set(
373
373
  ConstDependency,
@@ -830,7 +830,7 @@ class DefinePlugin {
830
830
 
831
831
  compilation.valueCacheVersions.set(
832
832
  VALUE_DEP_MAIN,
833
- /** @type {string} */ (mainHash.digest("hex").slice(0, 8))
833
+ mainHash.digest("hex").slice(0, 8)
834
834
  );
835
835
  }
836
836
  );
package/lib/Dependency.js CHANGED
@@ -19,7 +19,7 @@ const memoize = require("./util/memoize");
19
19
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
20
  /** @typedef {import("./util/Hash")} Hash */
21
21
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
22
-
22
+ /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
23
23
  /**
24
24
  * @typedef {object} UpdateHashContext
25
25
  * @property {ChunkGraph} chunkGraph
@@ -360,6 +360,13 @@ Object.defineProperty(Dependency.prototype, "module", {
360
360
  }
361
361
  });
362
362
 
363
+ /**
364
+ * @param {Dependency} dependency dep
365
+ * @returns {boolean} true if the dependency is a low priority dependency
366
+ */
367
+ Dependency.isLowPriorityDependency = (dependency) =>
368
+ /** @type {ModuleDependency} */ (dependency).sourceOrder === Infinity;
369
+
363
370
  // TODO remove in webpack 6
364
371
  Object.defineProperty(Dependency.prototype, "disconnect", {
365
372
  /**
@@ -41,6 +41,7 @@
41
41
  /**
42
42
  * @typedef {object} CssDependencyTemplateContextExtras
43
43
  * @property {CssData} cssData the css exports data
44
+ * @property {string} type the css exports data
44
45
  */
45
46
 
46
47
  /**
@@ -48,7 +48,7 @@ class DependencyTemplates {
48
48
  updateHash(part) {
49
49
  const hash = createHash(this._hashFunction);
50
50
  hash.update(`${this._hash}${part}`);
51
- this._hash = /** @type {string} */ (hash.digest("hex"));
51
+ this._hash = hash.digest("hex");
52
52
  }
53
53
 
54
54
  getHash() {