webpack 5.111.0 → 5.111.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/lib/APIPlugin.js +3 -4
  2. package/lib/CompatibilityPlugin.js +3 -4
  3. package/lib/Compilation.js +16 -35
  4. package/lib/Compiler.js +4 -5
  5. package/lib/ConstPlugin.js +16 -132
  6. package/lib/DependencyTemplate.js +2 -1
  7. package/lib/DotenvPlugin.js +24 -28
  8. package/lib/ErrorHelpers.js +113 -0
  9. package/lib/ExportsInfo.js +20 -16
  10. package/lib/ExternalModule.js +6 -8
  11. package/lib/FlagDependencyExportsPlugin.js +8 -13
  12. package/lib/FlagDependencyUsagePlugin.js +9 -13
  13. package/lib/Generator.js +24 -2
  14. package/lib/HotModuleReplacementPlugin.js +2 -0
  15. package/lib/IgnorePlugin.js +1 -1
  16. package/lib/LoaderOptionsPlugin.js +1 -1
  17. package/lib/Module.js +3 -3
  18. package/lib/ModuleGraph.js +6 -9
  19. package/lib/MultiCompiler.js +6 -16
  20. package/lib/NormalModule.js +96 -44
  21. package/lib/RuntimeTemplate.js +33 -43
  22. package/lib/SourceMapDevToolPlugin.js +53 -103
  23. package/lib/TemplatedPathPlugin.js +16 -59
  24. package/lib/asset/AssetBytesGenerator.js +7 -1
  25. package/lib/asset/AssetGenerator.js +25 -16
  26. package/lib/asset/AssetSourceGenerator.js +7 -1
  27. package/lib/buildChunkGraph.js +11 -15
  28. package/lib/cache/MemoryCachePlugin.js +4 -4
  29. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  30. package/lib/cache/PackFileCacheStrategy.js +3 -18
  31. package/lib/cache/getLazyHashedEtag.js +3 -5
  32. package/lib/config/browserslistTargetHandler.js +2 -8
  33. package/lib/config/defaults.js +52 -78
  34. package/lib/config/getClaimedAssetTypes.js +10 -11
  35. package/lib/config/target.js +3 -4
  36. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  37. package/lib/{ContextModule.js → context/ContextModule.js} +37 -34
  38. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  39. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  40. package/lib/css/CssGenerator.js +19 -11
  41. package/lib/css/CssParser.js +18 -20
  42. package/lib/css/cssMinify.js +32 -29
  43. package/lib/css/data.js +797 -288
  44. package/lib/css/syntax.js +2250 -934
  45. package/lib/debug/ProfilingPlugin.js +3 -4
  46. package/lib/dependencies/CommonJsExportRequireDependency.js +10 -11
  47. package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -5
  48. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  49. package/lib/dependencies/ContextDependency.js +1 -1
  50. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  51. package/lib/dependencies/ContextElementDependency.js +1 -1
  52. package/lib/dependencies/CssIcssExportDependency.js +6 -8
  53. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  54. package/lib/dependencies/CssUrlDependency.js +3 -5
  55. package/lib/dependencies/HarmonyCompatibilityDependency.js +11 -20
  56. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  57. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -4
  58. package/lib/dependencies/HarmonyExportExpressionDependency.js +3 -4
  59. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +3 -4
  60. package/lib/dependencies/HarmonyExportInitFragment.js +26 -19
  61. package/lib/dependencies/HarmonyExportSpecifierDependency.js +7 -28
  62. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +103 -16
  63. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  64. package/lib/dependencies/HarmonyImportSpecifierDependency.js +16 -2
  65. package/lib/dependencies/HtmlEntryDependency.js +74 -102
  66. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  67. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  68. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  69. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  70. package/lib/dependencies/ImportMetaPlugin.js +8 -10
  71. package/lib/dependencies/ImportParserPlugin.js +1 -1
  72. package/lib/dependencies/LoaderPlugin.js +26 -1
  73. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/URLContextDependency.js +1 -1
  75. package/lib/dependencies/URLDependency.js +6 -5
  76. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  77. package/lib/dependencies/WorkerDependency.js +6 -5
  78. package/lib/dependencies/WorkletDependency.js +6 -9
  79. package/lib/errors/HookWebpackError.js +3 -2
  80. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  81. package/lib/html/HtmlGenerator.js +61 -82
  82. package/lib/html/HtmlModulesPlugin.js +88 -139
  83. package/lib/html/HtmlParser.js +97 -141
  84. package/lib/html/data.js +21 -0
  85. package/lib/html/htmlMinify.js +10 -11
  86. package/lib/html/syntax.js +883 -993
  87. package/lib/index.js +46 -3
  88. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  89. package/lib/javascript/JavascriptGenerator.js +8 -1
  90. package/lib/javascript/JavascriptModulesPlugin.js +21 -48
  91. package/lib/javascript/JavascriptParser.js +721 -178
  92. package/lib/javascript/parser.js +6 -0
  93. package/lib/javascript/syntax.js +420 -92
  94. package/lib/json/JsonGenerator.js +7 -1
  95. package/lib/library/ModuleLibraryPlugin.js +64 -136
  96. package/lib/loaders/LoaderRunner.js +137 -9
  97. package/lib/node/NodeWatchFileSystem.js +3 -9
  98. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  99. package/lib/optimize/ConcatenatedModule.js +81 -100
  100. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  101. package/lib/optimize/InnerGraphPlugin.js +7 -13
  102. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  103. package/lib/optimize/MangleExportsPlugin.js +3 -4
  104. package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
  105. package/lib/optimize/SideEffectsFlagPlugin.js +7 -19
  106. package/lib/optimize/SplitChunksPlugin.js +2 -4
  107. package/lib/performance/BroadContextsPlugin.js +1 -1
  108. package/lib/performance/CacheEffectivenessPlugin.js +3 -4
  109. package/lib/performance/SizeLimitsPlugin.js +2 -4
  110. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +6 -8
  111. package/lib/prefetch/ResourceHintPlugin.js +17 -21
  112. package/lib/prefetch/StartupAssetHintRuntimeModule.js +7 -10
  113. package/lib/runtime/AsyncModuleRuntimeModule.js +3 -5
  114. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  115. package/lib/runtime/GlobalRuntimeModule.js +2 -4
  116. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +55 -85
  117. package/lib/schemes/DataUriPlugin.js +3 -6
  118. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  119. package/lib/serialization/BinaryMiddleware.js +9 -9
  120. package/lib/serialization/FileMiddleware.js +16 -16
  121. package/lib/serialization/ObjectMiddleware.js +30 -33
  122. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -4
  123. package/lib/typescript/TypeScriptPlugin.js +2 -3
  124. package/lib/url/URLParserPlugin.js +6 -8
  125. package/lib/util/LocConverter.js +4 -7
  126. package/lib/util/SourceProcessor.js +15 -22
  127. package/lib/util/chainedImports.js +3 -4
  128. package/lib/util/concatenate.js +4 -4
  129. package/lib/util/createHooksRegistry.js +1 -2
  130. package/lib/util/dataURL.js +2 -3
  131. package/lib/util/deterministicGrouping.js +8 -13
  132. package/lib/util/findGraphRoots.js +6 -13
  133. package/lib/util/globUtils.js +1 -1
  134. package/lib/util/hash/wasm-hash.js +3 -4
  135. package/lib/util/internalSerializables.js +1 -1
  136. package/lib/util/semver.js +5 -3
  137. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  138. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  139. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -4
  140. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  141. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  142. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  143. package/package.json +30 -23
  144. package/types.d.ts +299 -280
package/lib/index.js CHANGED
@@ -38,7 +38,7 @@ const memoize = require("./util/memoize");
38
38
  /** @typedef {import("./asset/AssetModule").AssetModuleBuildInfo} AssetModuleBuildInfo */
39
39
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
40
40
  /** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
41
- /** @typedef {import("./ContextModule").ContextModuleBuildInfo} ContextModuleBuildInfo */
41
+ /** @typedef {import("./context/ContextModule").ContextModuleBuildInfo} ContextModuleBuildInfo */
42
42
  /** @typedef {import("./css/CssModule").CssModuleBuildInfo} CssModuleBuildInfo */
43
43
  /** @typedef {import("./css/CssModule").CssModuleBuildMeta} CssModuleBuildMeta */
44
44
  /** @typedef {import("./ExternalModule").ExternalModuleBuildInfo} ExternalModuleBuildInfo */
@@ -237,10 +237,10 @@ module.exports = mergeExports(fn, {
237
237
  return require("./ConcatenationScope");
238
238
  },
239
239
  get ContextExclusionPlugin() {
240
- return require("./ContextExclusionPlugin");
240
+ return require("./context/ContextExclusionPlugin");
241
241
  },
242
242
  get ContextReplacementPlugin() {
243
- return require("./ContextReplacementPlugin");
243
+ return require("./context/ContextReplacementPlugin");
244
244
  },
245
245
  get CopyPlugin() {
246
246
  return require("./CopyPlugin");
@@ -743,3 +743,46 @@ module.exports = mergeExports(fn, {
743
743
  }
744
744
  }
745
745
  });
746
+
747
+ /**
748
+ * The loader-authoring types, re-exported here because this file is what
749
+ * `generate-types.js` reads webpack's public type surface from
750
+ * @template [OptionsType={}]
751
+ * @template [ContextAdditions={}]
752
+ * @typedef {import("./loaders/LoaderRunner").LoaderModule<OptionsType, ContextAdditions>} LoaderModule
753
+ */
754
+
755
+ /**
756
+ * @template [OptionsType={}]
757
+ * @template [ContextAdditions={}]
758
+ * @typedef {import("./loaders/LoaderRunner").RawLoaderDefinition<OptionsType, ContextAdditions>} RawLoaderDefinition
759
+ */
760
+
761
+ /**
762
+ * @template [OptionsType={}]
763
+ * @template [ContextAdditions={}]
764
+ * @typedef {import("./loaders/LoaderRunner").LoaderDefinition<OptionsType, ContextAdditions>} LoaderDefinition
765
+ */
766
+
767
+ /**
768
+ * @template [OptionsType={}]
769
+ * @template [ContextAdditions={}]
770
+ * @typedef {import("./loaders/LoaderRunner").LoaderDefinitionFunction<OptionsType, ContextAdditions>} LoaderDefinitionFunction
771
+ */
772
+
773
+ /**
774
+ * @template [OptionsType={}]
775
+ * @template [ContextAdditions={}]
776
+ * @typedef {import("./loaders/LoaderRunner").PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>} PitchLoaderDefinitionFunction
777
+ */
778
+
779
+ /**
780
+ * @template [OptionsType={}]
781
+ * @template [ContextAdditions={}]
782
+ * @typedef {import("./loaders/LoaderRunner").RawLoaderDefinitionFunction<OptionsType, ContextAdditions>} RawLoaderDefinitionFunction
783
+ */
784
+
785
+ /**
786
+ * @template OptionsType
787
+ * @typedef {import("./NormalModule").LoaderContext<OptionsType>} LoaderContext
788
+ */
@@ -55,10 +55,11 @@ function createChunkHashHandler(name) {
55
55
  hash.update(name);
56
56
  hash.update("1");
57
57
  if (runtimeChunk && runtimeChunk.hash) {
58
- // https://github.com/webpack/webpack/issues/19439
59
- // Any change to runtimeChunk should trigger a hash update,
60
- // we shouldn't depend on or inspect its internal implementation.
58
+ // WHY: any change to the runtime chunk must move this hash, and its
59
+ // internal implementation is not ours to depend on or inspect — the import
60
+ // names its hashed filename:
61
61
  // import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js";
62
+ // https://github.com/webpack/webpack/issues/19439
62
63
  hash.update(runtimeChunk.hash);
63
64
  }
64
65
  updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
@@ -256,6 +256,7 @@ class JavascriptGenerator extends Generator {
256
256
  /** @type {NonNullable<GenerateContext["codeGenerationResults"]>} */
257
257
  (generateContext.codeGenerationResults),
258
258
  initFragments,
259
+ getData: generateContext.getData,
259
260
  get chunkInitFragments() {
260
261
  if (!chunkInitFragments) {
261
262
  const data =
@@ -332,7 +333,13 @@ class JavascriptGenerator extends Generator {
332
333
  * @returns {Source | null} generated code
333
334
  */
334
335
  generateError(error, module, generateContext) {
335
- return new RawSource(Generator.throwBuildErrorCode(error));
336
+ return new RawSource(
337
+ Generator.throwBuildErrorCode(
338
+ error,
339
+ undefined,
340
+ generateContext.runtimeTemplate.requestShortener
341
+ )
342
+ );
336
343
  }
337
344
  }
338
345
 
@@ -78,7 +78,6 @@ const { releaseParserCaches } = require("./syntax");
78
78
  /** @import DependencyTemplates from "../DependencyTemplates" */
79
79
  /** @import Entrypoint from "../Entrypoint" */
80
80
  /** @import Module, { BuildInfo, CodeGenerationResultData } from "../Module" */
81
- /** @import { RuntimeSpec } from "../util/runtime" */
82
81
  /** @import ModuleGraph from "../ModuleGraph" */
83
82
  /** @import RuntimeTemplate from "../RuntimeTemplate" */
84
83
  /** @import WebpackError from "../errors/WebpackError" */
@@ -332,18 +331,6 @@ const createCompilationHooks = () => ({
332
331
  * @since 5.22.0
333
332
  */
334
333
  inlineInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
335
- /**
336
- * Offers a module's rendered export-definition call to a consumer that can place
337
- * it better — a library whose entry exports the same bindings natively takes it
338
- * over and emits it only where the module is wrapped. Return true to take it.
339
- * @type {SyncBailHook<[Module, RuntimeSpec, string, boolean], boolean | void>}
340
- */
341
- onDemandExportsGeneration: new SyncBailHook([
342
- "module",
343
- "runtime",
344
- "source",
345
- "placeAtEnd"
346
- ]),
347
334
  /**
348
335
  * @type {SyncBailHook<[Module, RenderContext], string | void>}
349
336
  * @since 5.22.0
@@ -1597,17 +1584,14 @@ class JavascriptModulesPlugin {
1597
1584
  }
1598
1585
 
1599
1586
  if (runtimeRequirements.has(RuntimeGlobals.makeDeferredNamespaceObject)) {
1600
- // in order to optimize of DeferredNamespaceObject, we remove all proxy handlers after the module initialize
1601
- // (see MakeDeferredNamespaceObjectRuntimeModule)
1602
- // This requires all deferred imports to a module can get the module export object before the module
1603
- // is evaluated.
1587
+ // The deferred namespace drops its proxy handlers once the module has
1588
+ // initialized, which needs every deferred import of it to reach the exports
1589
+ // object before evaluation.
1604
1590
  buf.push("// The deferred module cache");
1605
1591
  buf.push(`${bootstrapCst} __webpack_module_deferred_exports__ = {};`);
1606
- // Per the TC39 import-defer spec, every defer-import call site for
1607
- // the same module must yield the same Deferred Module Namespace
1608
- // Exotic Object (and a distinct one from any eager namespace).
1609
- // Cache the deferred namespace proxy here so calls from different
1610
- // files share identity.
1592
+ // Every defer-import site for one module must yield the same Deferred
1593
+ // Module Namespace, distinct from any eager one, so the proxy is cached
1594
+ // here for call sites in different files to share.
1611
1595
  buf.push("// The deferred namespace cache");
1612
1596
  buf.push(
1613
1597
  `${bootstrapCst} __webpack_module_deferred_namespace_cache__ = {};`
@@ -1797,13 +1781,9 @@ class JavascriptModulesPlugin {
1797
1781
  result.allowInlineStartup = false;
1798
1782
  }
1799
1783
 
1800
- // `__webpack_exports__` may be reassigned later — by the
1801
- // `onChunksLoaded` wrapper below, by an inlined entry
1802
- // module that uses top-level `await` (the emitted
1803
- // bridge reassigns `__webpack_exports__` to the awaited
1804
- // value), or by other downstream codegen. Always declare
1805
- // with `let` (or `var` if `let` is unsupported) so
1806
- // reassignment is allowed.
1784
+ // `__webpack_exports__` may be reassigned later, by the
1785
+ // `onChunksLoaded` wrapper, a top-level `await` bridge or other
1786
+ // codegen, so it is never declared as a constant.
1807
1787
  const exportsDecl = runtimeTemplate.renderLet();
1808
1788
  if (chunks.length > 0) {
1809
1789
  const awaitEntry =
@@ -2012,11 +1992,9 @@ class JavascriptModulesPlugin {
2012
1992
  const needModuleDefer = runtimeRequirements.has(
2013
1993
  RuntimeGlobals.makeDeferredNamespaceObject
2014
1994
  );
2015
- // Both deferred-namespace runtimes re-invoke `__webpack_require__` on
2016
- // access, so a module's evaluation error must be retained and re-thrown
2017
- // (a Cyclic Module Record's [[EvaluationError]]); the optimized variant
2018
- // does not use `__webpack_module_deferred_exports__`, so it is tracked
2019
- // separately from `needModuleDefer`.
1995
+ // Both deferred-namespace runtimes re-invoke `__webpack_require__` on access,
1996
+ // so an evaluation error must be retained and re-thrown. The optimized one
1997
+ // skips the deferred exports object, hence the separate flag.
2020
1998
  const needModuleDeferAny =
2021
1999
  needModuleDefer ||
2022
2000
  runtimeRequirements.has(
@@ -2144,10 +2122,9 @@ class JavascriptModulesPlugin {
2144
2122
  allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict);
2145
2123
  const isMultipleEntries = inlinedModules.size > 1;
2146
2124
  const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
2147
- // This step is before the IIFE reason calculation; it only runs for the
2148
- // cases whose IIFE reason it can remove: multiple inlined entry modules, or a
2149
- // single inlined entry alongside other chunk modules. The remaining reason
2150
- // ('it uses a non-standard name for the exports') is not handled here.
2125
+ // Runs before the IIFE reason is calculated, and only for the cases whose
2126
+ // reason it can remove: several inlined entries, or one beside other chunk
2127
+ // modules. A non-standard exports name is not handled here.
2151
2128
  if (innerStrict || (!isMultipleEntries && !singleEntryWithModules)) {
2152
2129
  return false;
2153
2130
  }
@@ -2206,11 +2183,9 @@ class JavascriptModulesPlugin {
2206
2183
  }
2207
2184
  }
2208
2185
 
2209
- // Fast path: codegen reports each inlined entry's rendered top-level
2210
- // declarations and free names (post-concatenation), so when no declaration
2211
- // collides with a free name of any other module, another entry's
2212
- // declarations, or a reserved name, no renaming is needed and the entries
2213
- // don't have to be parsed at all.
2186
+ // Codegen reports each inlined entry's rendered top-level declarations and
2187
+ // free names, so where nothing collides there is no renaming to do and the
2188
+ // entries need not be parsed at all.
2214
2189
  fastPath: {
2215
2190
  const { codeGenerationResults, chunk } = renderContext;
2216
2191
  /** @type {Set<string>} */
@@ -2295,11 +2270,9 @@ class JavascriptModulesPlugin {
2295
2270
  }
2296
2271
  }
2297
2272
 
2298
- // Multiple inlined entry modules share the chunk's startup scope. Rename any
2299
- // top-level declaration that would collide with another inlined module's
2300
- // declaration, with any inlined or non-inlined module's free (global)
2301
- // reference, or with a reserved name, so the modules can be emitted without a
2302
- // per-entry IIFE.
2273
+ // Several inlined entries share the chunk's startup scope, so any top-level
2274
+ // declaration colliding with another's declaration, any module's free
2275
+ // reference or a reserved name is renamed, sparing them a per-entry IIFE.
2303
2276
  if (isMultipleEntries) {
2304
2277
  /** @type {Set<string>} */
2305
2278
  const allUsedNames = new Set(nonInlinedModuleThroughIdentifiers);