webpack 5.103.0 → 5.104.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 (177) 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/SizeFormatHelpers.js +1 -1
  48. package/lib/SourceMapDevToolPlugin.js +6 -1
  49. package/lib/Template.js +17 -6
  50. package/lib/TemplatedPathPlugin.js +5 -6
  51. package/lib/WebpackError.js +0 -1
  52. package/lib/WebpackOptionsApply.js +37 -9
  53. package/lib/asset/AssetBytesGenerator.js +15 -11
  54. package/lib/asset/AssetGenerator.js +30 -24
  55. package/lib/asset/AssetSourceGenerator.js +15 -11
  56. package/lib/asset/RawDataUrlModule.js +6 -3
  57. package/lib/buildChunkGraph.js +4 -2
  58. package/lib/cache/PackFileCacheStrategy.js +6 -5
  59. package/lib/cli.js +2 -43
  60. package/lib/config/browserslistTargetHandler.js +19 -0
  61. package/lib/config/defaults.js +128 -43
  62. package/lib/config/normalization.js +2 -2
  63. package/lib/config/target.js +5 -0
  64. package/lib/container/ContainerEntryModule.js +6 -3
  65. package/lib/container/FallbackModule.js +6 -3
  66. package/lib/container/RemoteModule.js +1 -3
  67. package/lib/css/CssGenerator.js +26 -24
  68. package/lib/css/CssLoadingRuntimeModule.js +12 -4
  69. package/lib/css/CssModulesPlugin.js +29 -74
  70. package/lib/css/CssParser.js +828 -341
  71. package/lib/css/walkCssTokens.js +33 -13
  72. package/lib/dependencies/CachedConstDependency.js +24 -10
  73. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  74. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  75. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  76. package/lib/dependencies/CssIcssExportDependency.js +242 -104
  77. package/lib/dependencies/CssIcssImportDependency.js +61 -4
  78. package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
  79. package/lib/dependencies/CssImportDependency.js +2 -1
  80. package/lib/dependencies/CssUrlDependency.js +3 -2
  81. package/lib/dependencies/DynamicExports.js +7 -7
  82. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  83. package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
  84. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
  85. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
  86. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -4
  87. package/lib/dependencies/HarmonyExports.js +4 -4
  88. package/lib/dependencies/HarmonyImportDependency.js +8 -3
  89. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  90. package/lib/dependencies/ImportMetaPlugin.js +57 -0
  91. package/lib/dependencies/ImportParserPlugin.js +2 -2
  92. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  93. package/lib/dependencies/WorkerPlugin.js +2 -2
  94. package/lib/dependencies/getFunctionExpression.js +1 -1
  95. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  96. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  97. package/lib/hmr/LazyCompilationPlugin.js +4 -3
  98. package/lib/ids/IdHelpers.js +16 -7
  99. package/lib/javascript/ChunkHelpers.js +1 -1
  100. package/lib/javascript/JavascriptGenerator.js +4 -3
  101. package/lib/javascript/JavascriptModulesPlugin.js +57 -24
  102. package/lib/javascript/JavascriptParser.js +19 -6
  103. package/lib/json/JsonGenerator.js +5 -4
  104. package/lib/json/JsonParser.js +2 -1
  105. package/lib/library/AbstractLibraryPlugin.js +1 -1
  106. package/lib/library/AmdLibraryPlugin.js +4 -1
  107. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  108. package/lib/library/ModuleLibraryPlugin.js +41 -13
  109. package/lib/library/SystemLibraryPlugin.js +4 -1
  110. package/lib/library/UmdLibraryPlugin.js +1 -1
  111. package/lib/logging/Logger.js +5 -4
  112. package/lib/logging/createConsoleLogger.js +2 -2
  113. package/lib/optimize/ConcatenatedModule.js +47 -32
  114. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  115. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  116. package/lib/optimize/SplitChunksPlugin.js +60 -46
  117. package/lib/rules/RuleSetCompiler.js +1 -1
  118. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  119. package/lib/schemes/HttpUriPlugin.js +97 -10
  120. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  121. package/lib/serialization/ObjectMiddleware.js +0 -2
  122. package/lib/serialization/SingleItemMiddleware.js +1 -1
  123. package/lib/sharing/ConsumeSharedModule.js +1 -1
  124. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  125. package/lib/sharing/ProvideSharedModule.js +1 -1
  126. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  127. package/lib/sharing/utils.js +1 -1
  128. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  129. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  130. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  131. package/lib/util/StringXor.js +1 -1
  132. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  133. package/lib/util/binarySearchBounds.js +2 -2
  134. package/lib/util/comparators.js +53 -76
  135. package/lib/util/compileBooleanMatcher.js +78 -6
  136. package/lib/util/createHash.js +20 -199
  137. package/lib/util/deprecation.js +1 -1
  138. package/lib/util/deterministicGrouping.js +6 -3
  139. package/lib/util/fs.js +75 -75
  140. package/lib/util/hash/BatchedHash.js +10 -9
  141. package/lib/util/hash/BulkUpdateHash.js +138 -0
  142. package/lib/util/hash/DebugHash.js +75 -0
  143. package/lib/util/hash/hash-digest.js +216 -0
  144. package/lib/util/identifier.js +82 -17
  145. package/lib/util/internalSerializables.js +2 -6
  146. package/lib/util/runtime.js +3 -3
  147. package/lib/util/source.js +2 -2
  148. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  149. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
  150. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  151. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
  152. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  153. package/lib/webpack.js +1 -1
  154. package/package.json +30 -25
  155. package/schemas/WebpackOptions.check.js +1 -1
  156. package/schemas/WebpackOptions.json +59 -82
  157. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  158. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  159. package/types.d.ts +225 -158
  160. package/lib/ModuleSourceTypesConstants.js +0 -117
  161. package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
  162. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
  163. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
  164. package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
  165. package/lib/util/jsonParseEvenBetterErrors.js +0 -10
  166. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  167. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  168. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  169. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  170. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  171. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  173. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  174. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  175. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  176. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  177. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -20,6 +20,7 @@ const Compilation = require("../Compilation");
20
20
  const { tryRunOrWebpackError } = require("../HookWebpackError");
21
21
  const HotUpdateChunk = require("../HotUpdateChunk");
22
22
  const InitFragment = require("../InitFragment");
23
+ const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
23
24
  const {
24
25
  JAVASCRIPT_MODULE_TYPE_AUTO,
25
26
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
@@ -79,7 +80,7 @@ const chunkHasJs = (chunk, chunkGraph) => {
79
80
  if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
80
81
 
81
82
  return Boolean(
82
- chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
83
+ chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
83
84
  );
84
85
  };
85
86
 
@@ -99,7 +100,7 @@ const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
99
100
  }
100
101
 
101
102
  return Boolean(
102
- chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
103
+ chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
103
104
  );
104
105
  };
105
106
 
@@ -181,7 +182,7 @@ const printGeneratedCodeForStack = (module, code) => {
181
182
  * @property {ChunkGraph} chunkGraph the chunk graph
182
183
  * @property {CodeGenerationResults} codeGenerationResults results of code generation
183
184
  * @property {boolean | undefined} strictMode rendering in strict context
184
- * @property {boolean } inlined inlined
185
+ * @property {boolean} inlined inlined
185
186
  * @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE
186
187
  */
187
188
 
@@ -197,6 +198,7 @@ const printGeneratedCodeForStack = (module, code) => {
197
198
  * @property {boolean | undefined} strictMode rendering in strict context
198
199
  * @property {boolean} factory true: renders as factory method, false: pure module content
199
200
  * @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE, existing only when `factory` is set to false
201
+ * @property {boolean=} renderInObject render module in object container
200
202
  */
201
203
 
202
204
  /**
@@ -276,7 +278,7 @@ class JavascriptModulesPlugin {
276
278
 
277
279
  constructor(options = {}) {
278
280
  this.options = options;
279
- /** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined }>} */
281
+ /** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined, renderShorthand: boolean }>} */
280
282
  this._moduleFactoryCache = new WeakMap();
281
283
  }
282
284
 
@@ -487,7 +489,7 @@ class JavascriptModulesPlugin {
487
489
  });
488
490
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
489
491
  chunk,
490
- "javascript"
492
+ JAVASCRIPT_TYPE
491
493
  );
492
494
  if (modules) {
493
495
  const xor = new StringXor();
@@ -527,7 +529,8 @@ class JavascriptModulesPlugin {
527
529
  }
528
530
  );
529
531
  compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
530
- const source = options.codeGenerationResult.sources.get("javascript");
532
+ const source =
533
+ options.codeGenerationResult.sources.get(JAVASCRIPT_TYPE);
531
534
  if (source === undefined) return;
532
535
  const { module } = options;
533
536
  const code = source.source();
@@ -615,11 +618,12 @@ class JavascriptModulesPlugin {
615
618
  runtimeTemplate,
616
619
  codeGenerationResults,
617
620
  strictMode,
618
- factory
621
+ factory,
622
+ renderInObject
619
623
  } = renderContext;
620
624
  try {
621
625
  const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
622
- const moduleSource = codeGenResult.sources.get("javascript");
626
+ const moduleSource = codeGenResult.sources.get(JAVASCRIPT_TYPE);
623
627
  if (!moduleSource) return null;
624
628
  if (codeGenResult.data !== undefined) {
625
629
  const chunkInitFragments = codeGenResult.data.get("chunkInitFragments");
@@ -654,6 +658,8 @@ class JavascriptModulesPlugin {
654
658
  const cacheEntry = this._moduleFactoryCache.get(
655
659
  moduleSourcePostContent
656
660
  );
661
+ const renderShorthand =
662
+ renderInObject === true && runtimeTemplate.supportsMethodShorthand();
657
663
  let source;
658
664
  if (
659
665
  cacheEntry &&
@@ -661,7 +667,8 @@ class JavascriptModulesPlugin {
661
667
  cacheEntry.needExports === needExports &&
662
668
  cacheEntry.needRequire === needRequire &&
663
669
  cacheEntry.needThisAsExports === needThisAsExports &&
664
- cacheEntry.needStrict === needStrict
670
+ cacheEntry.needStrict === needStrict &&
671
+ cacheEntry.renderShorthand === renderShorthand
665
672
  ) {
666
673
  source = cacheEntry.source;
667
674
  } else {
@@ -682,16 +689,24 @@ class JavascriptModulesPlugin {
682
689
  );
683
690
  }
684
691
  if (needRequire) args.push(RuntimeGlobals.require);
685
- if (!needThisAsExports && runtimeTemplate.supportsArrowFunction()) {
692
+
693
+ if (renderShorthand) {
694
+ // we can optimize function to methodShorthand if render module factory in object
695
+ factorySource.add(`(${args.join(", ")}) {\n\n`);
696
+ } else if (
697
+ !needThisAsExports &&
698
+ runtimeTemplate.supportsArrowFunction()
699
+ ) {
686
700
  factorySource.add(`/***/ ((${args.join(", ")}) => {\n\n`);
687
701
  } else {
688
702
  factorySource.add(`/***/ (function(${args.join(", ")}) {\n\n`);
689
703
  }
704
+
690
705
  if (needStrict) {
691
706
  factorySource.add('"use strict";\n');
692
707
  }
693
708
  factorySource.add(moduleSourcePostContent);
694
- factorySource.add("\n\n/***/ })");
709
+ factorySource.add(`\n\n/***/ }${renderShorthand ? "" : ")"}`);
695
710
  source = new CachedSource(factorySource);
696
711
  this._moduleFactoryCache.set(moduleSourcePostContent, {
697
712
  source,
@@ -699,7 +714,8 @@ class JavascriptModulesPlugin {
699
714
  needExports,
700
715
  needRequire,
701
716
  needThisAsExports,
702
- needStrict
717
+ needStrict,
718
+ renderShorthand
703
719
  });
704
720
  }
705
721
  moduleSourcePostContainer = tryRunOrWebpackError(
@@ -734,7 +750,7 @@ class JavascriptModulesPlugin {
734
750
  const { chunk, chunkGraph } = renderContext;
735
751
  const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
736
752
  chunk,
737
- "javascript",
753
+ JAVASCRIPT_TYPE,
738
754
  compareModulesByIdOrIdentifier(chunkGraph)
739
755
  );
740
756
  const allModules = modules ? [...modules] : [];
@@ -757,12 +773,15 @@ class JavascriptModulesPlugin {
757
773
  strictMode: allStrict
758
774
  };
759
775
  const moduleSources =
760
- Template.renderChunkModules(chunkRenderContext, allModules, (module) =>
761
- this.renderModule(
762
- module,
763
- { ...chunkRenderContext, factory: true },
764
- hooks
765
- )
776
+ Template.renderChunkModules(
777
+ chunkRenderContext,
778
+ allModules,
779
+ (module, renderInObject) =>
780
+ this.renderModule(
781
+ module,
782
+ { ...chunkRenderContext, factory: true, renderInObject },
783
+ hooks
784
+ )
766
785
  ) || new RawSource("{}");
767
786
  let source = tryRunOrWebpackError(
768
787
  () => hooks.renderChunk.call(moduleSources, chunkRenderContext),
@@ -818,7 +837,7 @@ class JavascriptModulesPlugin {
818
837
  const allModules = [
819
838
  ...(chunkGraph.getOrderedChunkModulesIterableBySourceType(
820
839
  chunk,
821
- "javascript",
840
+ JAVASCRIPT_TYPE,
822
841
  compareModulesByIdOrIdentifier(chunkGraph)
823
842
  ) || [])
824
843
  ];
@@ -874,10 +893,10 @@ class JavascriptModulesPlugin {
874
893
  (m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
875
894
  )
876
895
  : allModules,
877
- (module) =>
896
+ (module, renderInObject) =>
878
897
  this.renderModule(
879
898
  module,
880
- { ...chunkRenderContext, factory: true },
899
+ { ...chunkRenderContext, factory: true, renderInObject },
881
900
  hooks
882
901
  ),
883
902
  prefix
@@ -1280,7 +1299,9 @@ class JavascriptModulesPlugin {
1280
1299
  entryModule,
1281
1300
  entrypoint
1282
1301
  ] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) {
1283
- if (!chunkGraph.getModuleSourceTypes(entryModule).has("javascript")) {
1302
+ if (
1303
+ !chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE)
1304
+ ) {
1284
1305
  i--;
1285
1306
  continue;
1286
1307
  }
@@ -1540,6 +1561,19 @@ class JavascriptModulesPlugin {
1540
1561
  ])
1541
1562
  : Template.indent("return cachedModule.exports;"),
1542
1563
  "}",
1564
+ // Add helpful error message in development mode when module is not found
1565
+ ...(outputOptions.pathinfo
1566
+ ? [
1567
+ "// Check if module exists (development only)",
1568
+ "if (__webpack_modules__[moduleId] === undefined) {",
1569
+ Template.indent([
1570
+ 'var e = new Error("Cannot find module \'" + moduleId + "\'");',
1571
+ "e.code = 'MODULE_NOT_FOUND';",
1572
+ "throw e;"
1573
+ ]),
1574
+ "}"
1575
+ ]
1576
+ : []),
1543
1577
  "// Create a new module (and put it into the cache)",
1544
1578
  "var module = __webpack_module_cache__[moduleId] = {",
1545
1579
  Template.indent([
@@ -1652,7 +1686,6 @@ class JavascriptModulesPlugin {
1652
1686
  const inlinedModulesToInfo = new Map();
1653
1687
  /** @type {Set<string>} */
1654
1688
  const nonInlinedModuleThroughIdentifiers = new Set();
1655
- /** @type {Map<Module, Source>} */
1656
1689
 
1657
1690
  for (const m of allModules) {
1658
1691
  const isInlinedModule = inlinedModules && inlinedModules.has(m);
@@ -100,6 +100,19 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
100
100
  /** @typedef {import("../Parser").ParserState} ParserState */
101
101
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
102
102
 
103
+ /** @typedef {import("../dependencies/LocalModule")} LocalModule */
104
+ /** @typedef {import("../dependencies/HarmonyExportImportedSpecifierDependency").HarmonyStarExportsList} HarmonyStarExportsList */
105
+
106
+ /**
107
+ * @typedef {object} KnownJavascriptParserState
108
+ * @property {Set<string>=} harmonyNamedExports
109
+ * @property {HarmonyStarExportsList=} harmonyStarExports
110
+ * @property {number=} lastHarmonyImportOrder
111
+ * @property {LocalModule[]=} localModules
112
+ */
113
+
114
+ /** @typedef {ParserState & KnownJavascriptParserState} JavascriptParserState */
115
+
103
116
  /** @typedef {import("../Compilation")} Compilation */
104
117
  /** @typedef {import("../Module")} Module */
105
118
 
@@ -666,7 +679,7 @@ class JavascriptParser extends Parser {
666
679
 
667
680
  /** @type {ScopeInfo} */
668
681
  this.scope = /** @type {EXPECTED_ANY} */ (undefined);
669
- /** @type {ParserState} */
682
+ /** @type {JavascriptParserState} */
670
683
  this.state = /** @type {EXPECTED_ANY} */ (undefined);
671
684
  /** @type {Comment[] | undefined} */
672
685
  this.comments = undefined;
@@ -1898,7 +1911,7 @@ class JavascriptParser extends Parser {
1898
1911
  const expr = /** @type {ChainExpression} */ (_expr);
1899
1912
  /** @type {Expression[]} */
1900
1913
  const optionalExpressionsStack = [];
1901
- /** @type {Expression|Super} */
1914
+ /** @type {Expression | Super} */
1902
1915
  let next = expr.expression;
1903
1916
 
1904
1917
  while (
@@ -5133,7 +5146,7 @@ class JavascriptParser extends Parser {
5133
5146
  if (comments.length === 0) {
5134
5147
  return EMPTY_COMMENT_OPTIONS;
5135
5148
  }
5136
- /** @type {Record<string, EXPECTED_ANY> } */
5149
+ /** @type {Record<string, EXPECTED_ANY>} */
5137
5150
  const options = {};
5138
5151
  /** @type {(Error & { comment: Comment })[]} */
5139
5152
  const errors = [];
@@ -5235,8 +5248,8 @@ class JavascriptParser extends Parser {
5235
5248
  return { info, name };
5236
5249
  }
5237
5250
 
5238
- /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => CalleeMembers, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges}} CallExpressionInfo */
5239
- /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges}} ExpressionExpressionInfo */
5251
+ /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => CalleeMembers, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} CallExpressionInfo */
5252
+ /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} ExpressionExpressionInfo */
5240
5253
 
5241
5254
  /**
5242
5255
  * @param {Expression | Super} expression a member expression
@@ -5297,7 +5310,7 @@ class JavascriptParser extends Parser {
5297
5310
 
5298
5311
  /**
5299
5312
  * @param {Expression} expression an expression
5300
- * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members} | undefined} name info
5313
+ * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members } | undefined} name info
5301
5314
  */
5302
5315
  getNameForExpression(expression) {
5303
5316
  return this.getMemberExpressionInfo(
@@ -9,7 +9,7 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const { UsageState } = require("../ExportsInfo");
11
11
  const Generator = require("../Generator");
12
- const { JS_TYPES } = require("../ModuleSourceTypesConstants");
12
+ const { JAVASCRIPT_TYPES } = require("../ModuleSourceTypeConstants");
13
13
  const RuntimeGlobals = require("../RuntimeGlobals");
14
14
 
15
15
  /** @typedef {import("webpack-sources").Source} Source */
@@ -17,6 +17,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
17
17
  /** @typedef {import("../ExportsInfo")} ExportsInfo */
18
18
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
19
19
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
20
+ /** @typedef {import("../Module").SourceType} SourceType */
20
21
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
21
22
  /** @typedef {import("../NormalModule")} NormalModule */
22
23
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
@@ -26,7 +27,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
26
27
 
27
28
  /**
28
29
  * @param {JsonValue} data Raw JSON data
29
- * @returns {undefined|string} stringified data
30
+ * @returns {undefined | string} stringified data
30
31
  */
31
32
  const stringifySafe = (data) => {
32
33
  const stringified = JSON.stringify(data);
@@ -132,12 +133,12 @@ class JsonGenerator extends Generator {
132
133
  * @returns {SourceTypes} available types (do not mutate)
133
134
  */
134
135
  getTypes(module) {
135
- return JS_TYPES;
136
+ return JAVASCRIPT_TYPES;
136
137
  }
137
138
 
138
139
  /**
139
140
  * @param {NormalModule} module the module
140
- * @param {string=} type source type
141
+ * @param {SourceType=} type source type
141
142
  * @returns {number} estimate size of the module
142
143
  */
143
144
  getSize(module, type) {
@@ -54,7 +54,8 @@ class JsonParser extends Parser {
54
54
  : parseFn(source[0] === "\uFEFF" ? source.slice(1) : source);
55
55
  } catch (err) {
56
56
  throw new Error(
57
- `Cannot parse JSON: ${/** @type {Error} */ (err).message}`
57
+ `Cannot parse JSON: ${/** @type {Error} */ (err).message}`,
58
+ { cause: err }
58
59
  );
59
60
  }
60
61
  const jsonData = new JsonData(/** @type {Buffer | JsonValue} */ (data));
@@ -308,7 +308,7 @@ class AbstractLibraryPlugin {
308
308
  * @param {Source} source source
309
309
  * @param {Module} module module
310
310
  * @param {ModuleRenderContext} renderContext render context
311
- * @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
311
+ * @param {Omit<LibraryContext<T>, "options">} libraryContext context
312
312
  * @returns {Source} source with library export
313
313
  */
314
314
  renderModuleContent(source, module, renderContext, libraryContext) {
@@ -17,7 +17,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
17
17
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
18
18
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
19
19
  /** @typedef {import("../util/Hash")} Hash */
20
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
20
+ /**
21
+ * @template T
22
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
23
+ */
21
24
 
22
25
  /**
23
26
  * @typedef {object} AmdLibraryPluginOptions
@@ -20,7 +20,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
20
20
  /** @typedef {import("../Module")} Module */
21
21
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
22
22
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
23
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
23
+ /**
24
+ * @template T
25
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
26
+ */
24
27
 
25
28
  /**
26
29
  * @typedef {object} ExportPropertyLibraryPluginParsed
@@ -21,6 +21,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
21
21
  /** @typedef {import("../Chunk")} Chunk */
22
22
  /** @typedef {import("../Compiler")} Compiler */
23
23
  /** @typedef {import("../Module")} Module */
24
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
24
25
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
25
26
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
26
27
  /** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
@@ -69,7 +70,28 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
69
70
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
70
71
  const { onDemandExportsGeneration } =
71
72
  ConcatenatedModule.getCompilationHooks(compilation);
72
- onDemandExportsGeneration.tap(PLUGIN_NAME, (_module) => true);
73
+ onDemandExportsGeneration.tap(
74
+ PLUGIN_NAME,
75
+ (module, runtimes, source, finalName) => {
76
+ /** @type {BuildMeta} */
77
+ const buildMeta = module.buildMeta || (module.buildMeta = {});
78
+
79
+ const exportsSourceByRuntime =
80
+ buildMeta.exportsSourceByRuntime ||
81
+ (buildMeta.exportsSourceByRuntime = new Map());
82
+
83
+ const exportsFinalNameByRuntime =
84
+ buildMeta.exportsFinalNameByRuntime ||
85
+ (buildMeta.exportsFinalNameByRuntime = new Map());
86
+
87
+ for (const runtime of runtimes) {
88
+ exportsSourceByRuntime.set(runtime, source);
89
+ exportsFinalNameByRuntime.set(runtime, finalName);
90
+ }
91
+
92
+ return true;
93
+ }
94
+ );
73
95
  });
74
96
  }
75
97
 
@@ -152,10 +174,16 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
152
174
  )
153
175
  ]
154
176
  : moduleGraph.getExportsInfo(module).orderedExports;
177
+
178
+ const exportsFinalNameByRuntime =
179
+ (module.buildMeta &&
180
+ module.buildMeta.exportsFinalNameByRuntime &&
181
+ module.buildMeta.exportsFinalNameByRuntime.get(chunk.runtime)) ||
182
+ {};
183
+
155
184
  const definitions =
156
- inlined && !inlinedInIIFE
157
- ? (module.buildMeta && module.buildMeta.exportsFinalName) || {}
158
- : {};
185
+ inlined && !inlinedInIIFE ? exportsFinalNameByRuntime : {};
186
+
159
187
  /** @type {string[]} */
160
188
  const shortHandedExports = [];
161
189
  /** @type {[string, string][]} */
@@ -268,23 +296,23 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
268
296
  * @param {Source} source source
269
297
  * @param {Module} module module
270
298
  * @param {ModuleRenderContext} renderContext render context
271
- * @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
299
+ * @param {Omit<LibraryContext<T>, "options">} libraryContext context
272
300
  * @returns {Source} source with library export
273
301
  */
274
302
  renderModuleContent(
275
303
  source,
276
304
  module,
277
- { factory, inlinedInIIFE },
305
+ { factory, inlinedInIIFE, chunk },
278
306
  libraryContext
279
307
  ) {
280
- // Re-add `factoryExportsBinding` to the source
281
- // when the module is rendered as a factory or treated as an inlined (startup) module but wrapped in an IIFE
282
- if (
283
- (inlinedInIIFE || factory) &&
308
+ const exportsSource =
284
309
  module.buildMeta &&
285
- module.buildMeta.factoryExportsBinding
286
- ) {
287
- return new ConcatSource(module.buildMeta.factoryExportsBinding, source);
310
+ module.buildMeta.exportsSourceByRuntime &&
311
+ module.buildMeta.exportsSourceByRuntime.get(chunk.runtime);
312
+
313
+ // Re-add the module's exports source when rendered in factory or as an inlined startup module wrapped in an IIFE
314
+ if ((inlinedInIIFE || factory) && exportsSource) {
315
+ return new ConcatSource(exportsSource, source);
288
316
  }
289
317
  return source;
290
318
  }
@@ -19,7 +19,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
19
19
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
20
20
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
21
21
  /** @typedef {import("../util/Hash")} Hash */
22
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
22
+ /**
23
+ * @template T
24
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
25
+ */
23
26
 
24
27
  /**
25
28
  * @typedef {object} SystemLibraryPluginOptions
@@ -34,7 +34,7 @@ const accessorToObjectAccess = (accessor) =>
34
34
  /** @typedef {string | string[]} Accessor */
35
35
 
36
36
  /**
37
- * @param {string|undefined} base the path prefix
37
+ * @param {string | undefined} base the path prefix
38
38
  * @param {Accessor} accessor the accessor
39
39
  * @param {string=} joinWith the element separator
40
40
  * @returns {string} the path
@@ -30,6 +30,7 @@ const LogType = Object.freeze({
30
30
  module.exports.LogType = LogType;
31
31
 
32
32
  /** @typedef {typeof LogType[keyof typeof LogType]} LogTypeEnum */
33
+ /** @typedef {Map<string | undefined, [number, number]>} TimersMap */
33
34
 
34
35
  const LOG_SYMBOL = Symbol("webpack logger raw log method");
35
36
  const TIMERS_SYMBOL = Symbol("webpack logger times");
@@ -143,7 +144,7 @@ class WebpackLogger {
143
144
  * @param {string} label label
144
145
  */
145
146
  time(label) {
146
- /** @type {Map<string | undefined, [number, number]>} */
147
+ /** @type {TimersMap} */
147
148
  this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map();
148
149
  this[TIMERS_SYMBOL].set(label, process.hrtime());
149
150
  }
@@ -169,7 +170,7 @@ class WebpackLogger {
169
170
  throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
170
171
  }
171
172
  const time = process.hrtime(prev);
172
- /** @type {Map<string | undefined, [number, number]>} */
173
+ /** @type {TimersMap} */
173
174
  (this[TIMERS_SYMBOL]).delete(label);
174
175
  this[LOG_SYMBOL](LogType.time, [label, ...time]);
175
176
  }
@@ -185,9 +186,9 @@ class WebpackLogger {
185
186
  );
186
187
  }
187
188
  const time = process.hrtime(prev);
188
- /** @type {Map<string | undefined, [number, number]>} */
189
+ /** @type {TimersMap} */
189
190
  (this[TIMERS_SYMBOL]).delete(label);
190
- /** @type {Map<string | undefined, [number, number]>} */
191
+ /** @type {TimersMap} */
191
192
  this[TIMERS_AGGREGATES_SYMBOL] =
192
193
  this[TIMERS_AGGREGATES_SYMBOL] || new Map();
193
194
  const current = this[TIMERS_AGGREGATES_SYMBOL].get(label);
@@ -35,8 +35,8 @@ const { LogType } = require("./Logger");
35
35
 
36
36
  /**
37
37
  * @typedef {object} LoggerOptions
38
- * @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} level loglevel
39
- * @property {FilterTypes|boolean} debug filter for debug logging
38
+ * @property {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level loglevel
39
+ * @property {FilterTypes | boolean} debug filter for debug logging
40
40
  * @property {LoggerConsole} console the console to log to
41
41
  */
42
42