webpack 5.108.4 → 5.109.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 (200) hide show
  1. package/bin/webpack.js +12 -0
  2. package/lib/APIPlugin.js +48 -29
  3. package/lib/CacheFacade.js +8 -0
  4. package/lib/ChunkGraph.js +17 -15
  5. package/lib/ChunkGroup.js +1 -0
  6. package/lib/CompatibilityPlugin.js +62 -29
  7. package/lib/Compilation.js +58 -6
  8. package/lib/ConstPlugin.js +11 -11
  9. package/lib/ContextModule.js +239 -6
  10. package/lib/ContextModuleFactory.js +139 -14
  11. package/lib/DefinePlugin.js +433 -112
  12. package/lib/Entrypoint.js +1 -1
  13. package/lib/ExportsInfo.js +22 -5
  14. package/lib/ExportsInfoApiPlugin.js +2 -2
  15. package/lib/ExternalModule.js +107 -5
  16. package/lib/ExternalModuleFactoryPlugin.js +20 -1
  17. package/lib/FileSystemInfo.js +256 -100
  18. package/lib/FlagDependencyUsagePlugin.js +33 -12
  19. package/lib/HotModuleReplacementPlugin.js +18 -15
  20. package/lib/InitFragment.js +20 -32
  21. package/lib/Module.js +3 -0
  22. package/lib/ModuleFilenameHelpers.js +2 -2
  23. package/lib/ModuleTypeConstants.js +8 -1
  24. package/lib/MultiCompiler.js +13 -2
  25. package/lib/MultiWatching.js +1 -0
  26. package/lib/NodeStuffPlugin.js +51 -33
  27. package/lib/NormalModule.js +175 -401
  28. package/lib/NormalModuleFactory.js +76 -2
  29. package/lib/ProgressPlugin.js +211 -119
  30. package/lib/ProvidePlugin.js +2 -2
  31. package/lib/RuntimeGlobals.js +47 -0
  32. package/lib/RuntimePlugin.js +67 -107
  33. package/lib/RuntimeTemplate.js +304 -16
  34. package/lib/Template.js +23 -3
  35. package/lib/UseStrictPlugin.js +1 -1
  36. package/lib/WebpackIsIncludedPlugin.js +1 -1
  37. package/lib/WebpackOptionsApply.js +24 -19
  38. package/lib/asset/AssetGenerator.js +110 -28
  39. package/lib/asset/AssetModulesPlugin.js +92 -2
  40. package/lib/asset/WebManifestGenerator.js +164 -0
  41. package/lib/asset/WebManifestParser.js +130 -0
  42. package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
  43. package/lib/async-modules/isGeneratorLowered.js +26 -0
  44. package/lib/cache/PackFileCacheStrategy.js +9 -3
  45. package/lib/config/browserslistTargetHandler.js +40 -0
  46. package/lib/config/defaults.js +219 -29
  47. package/lib/config/normalization.js +26 -0
  48. package/lib/config/target.js +9 -1
  49. package/lib/container/HoistContainerReferencesPlugin.js +47 -55
  50. package/lib/css/CssGenerator.js +40 -31
  51. package/lib/css/CssLoadingRuntimeModule.js +5 -1
  52. package/lib/css/CssModulesPlugin.js +13 -0
  53. package/lib/css/CssParser.js +729 -313
  54. package/lib/css/syntax.js +1371 -861
  55. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
  56. package/lib/dependencies/AMDPlugin.js +2 -2
  57. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
  58. package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
  59. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
  60. package/lib/dependencies/CommonJsExportsDependency.js +47 -2
  61. package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
  62. package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
  63. package/lib/dependencies/CommonJsPlugin.js +2 -2
  64. package/lib/dependencies/CommonJsRequireDependency.js +26 -1
  65. package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
  66. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  67. package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
  68. package/lib/dependencies/CssIcssExportDependency.js +162 -71
  69. package/lib/dependencies/CssUrlDependency.js +35 -4
  70. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
  71. package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
  72. package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
  73. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -1
  74. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
  75. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +17 -9
  76. package/lib/dependencies/HarmonyImportDependency.js +13 -2
  77. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
  78. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -7
  79. package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
  80. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  81. package/lib/dependencies/HtmlEntryDependency.js +797 -172
  82. package/lib/dependencies/HtmlSourceDependency.js +26 -0
  83. package/lib/dependencies/ImportDependency.js +43 -1
  84. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
  85. package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
  86. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  87. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  88. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  89. package/lib/dependencies/ImportMetaPlugin.js +532 -180
  90. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  91. package/lib/dependencies/ImportParserPlugin.js +80 -17
  92. package/lib/dependencies/ImportPhase.js +10 -8
  93. package/lib/dependencies/LoaderPlugin.js +5 -1
  94. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  95. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
  96. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
  97. package/lib/dependencies/SystemPlugin.js +2 -4
  98. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  99. package/lib/dependencies/URLDependency.js +141 -21
  100. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
  101. package/lib/dependencies/WorkerDependency.js +86 -18
  102. package/lib/dependencies/WorkletDependency.js +278 -0
  103. package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
  104. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
  105. package/lib/errors/LoaderLoadingError.js +20 -0
  106. package/lib/errors/ModuleParseError.js +39 -22
  107. package/lib/errors/NodeStuffInWebError.js +1 -1
  108. package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
  109. package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
  110. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
  111. package/lib/hmr/lazyCompilationBackend.js +51 -12
  112. package/lib/html/HtmlGenerator.js +907 -15
  113. package/lib/html/HtmlModule.js +2 -2
  114. package/lib/html/HtmlModulesPlugin.js +610 -166
  115. package/lib/html/HtmlParser.js +603 -247
  116. package/lib/html/favicon.svg +1 -0
  117. package/lib/html/syntax.js +3451 -2762
  118. package/lib/ids/IdHelpers.js +25 -11
  119. package/lib/index.js +6 -0
  120. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
  121. package/lib/javascript/BasicEvaluatedExpression.js +366 -48
  122. package/lib/javascript/JavascriptGenerator.js +197 -49
  123. package/lib/javascript/JavascriptModulesPlugin.js +178 -24
  124. package/lib/javascript/JavascriptParser.js +704 -355
  125. package/lib/javascript/JavascriptParserHelpers.js +3 -6
  126. package/lib/javascript/syntax.js +5037 -0
  127. package/lib/library/ModuleLibraryPlugin.js +38 -1
  128. package/lib/loaders/LoaderRunner.js +714 -0
  129. package/lib/loaders/loadLoader.js +100 -0
  130. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +29 -2
  131. package/lib/node/ReadFileCompileWasmPlugin.js +24 -2
  132. package/lib/optimize/AggressiveMergingPlugin.js +19 -15
  133. package/lib/optimize/ConcatenatedModule.js +139 -31
  134. package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
  135. package/lib/optimize/InnerGraphPlugin.js +50 -30
  136. package/lib/optimize/ModuleConcatenationPlugin.js +139 -24
  137. package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
  138. package/lib/optimize/SplitChunksPlugin.js +146 -44
  139. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
  140. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
  141. package/lib/prefetch/ResourceHintPlugin.js +687 -0
  142. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  143. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  144. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  145. package/lib/rules/RuleSetCompiler.js +114 -0
  146. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  147. package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
  148. package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
  149. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  150. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  151. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
  152. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
  153. package/lib/schemes/HttpUriPlugin.js +40 -1
  154. package/lib/schemes/VirtualUrlPlugin.js +1 -2
  155. package/lib/serialization/BinaryMiddleware.js +270 -938
  156. package/lib/serialization/FileMiddleware.js +29 -3
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +229 -194
  158. package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
  159. package/lib/stats/DefaultStatsPrinterPlugin.js +36 -168
  160. package/lib/stats/StatsFactory.js +46 -17
  161. package/lib/url/URLParserPlugin.js +66 -13
  162. package/lib/util/AsyncQueue.js +122 -72
  163. package/lib/util/SetHelpers.js +1 -1
  164. package/lib/util/StackedMap.js +122 -48
  165. package/lib/util/binarySearchBounds.js +2 -2
  166. package/lib/util/concatenate.js +40 -14
  167. package/lib/util/createHooksRegistry.js +13 -5
  168. package/lib/util/dataURL.js +2 -2
  169. package/lib/util/deterministicGrouping.js +7 -5
  170. package/lib/util/formatSize.js +6 -2
  171. package/lib/util/globUtils.js +710 -0
  172. package/lib/util/identifier.js +23 -6
  173. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  174. package/lib/util/internalSerializables.js +88 -71
  175. package/lib/util/magicComment.js +121 -25
  176. package/lib/util/numberHash.js +2 -2
  177. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
  178. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
  179. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
  180. package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
  181. package/lib/web/FetchCompileWasmPlugin.js +14 -0
  182. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
  183. package/lib/webpack.js +65 -0
  184. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
  185. package/module.d.ts +21 -0
  186. package/package.json +12 -11
  187. package/schemas/WebpackOptions.check.js +1 -1
  188. package/schemas/WebpackOptions.json +759 -36
  189. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  190. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  191. package/schemas/plugins/ProgressPlugin.json +17 -1
  192. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  194. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  195. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  197. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  198. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  199. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  200. package/types.d.ts +1212 -99
@@ -363,9 +363,10 @@ const _parseResource = (str) => {
363
363
 
364
364
  // Handle `\0`
365
365
  if (firstEscape !== -1) {
366
- const match =
367
- /** @type {[string, string, string | undefined, string | undefined]} */
368
- (/** @type {unknown} */ (PATH_QUERY_FRAGMENT_REGEXP.exec(str)));
366
+ const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
367
+
368
+ // malformed escaping (e.g. a trailing lone \0) never matches; treat as path
369
+ if (!match) return { resource: str, path: str, query: "", fragment: "" };
369
370
 
370
371
  return {
371
372
  resource: str,
@@ -421,9 +422,10 @@ const _parseResourceWithoutFragment = (str) => {
421
422
 
422
423
  // Handle `\0`
423
424
  if (firstEscape !== -1) {
424
- const match =
425
- /** @type {[string, string, string | undefined]} */
426
- (/** @type {unknown} */ (PATH_QUERY_REGEXP.exec(str)));
425
+ const match = PATH_QUERY_REGEXP.exec(str);
426
+
427
+ // malformed escaping (e.g. a trailing lone \0) never matches; treat as path
428
+ if (!match) return { resource: str, path: str, query: "" };
427
429
 
428
430
  return {
429
431
  resource: str,
@@ -530,6 +532,20 @@ const escapeHashInPathRequest = (request) => {
530
532
  return pathPart.replace(HASH_REGEXP, "\0#") + request.slice(lastSep);
531
533
  };
532
534
 
535
+ const LINE_SEPARATOR_REGEXP = /[\u2028\u2029]/g;
536
+
537
+ /**
538
+ * Quotes a string as a JS string literal safe to inline in generated code.
539
+ * `JSON.stringify` leaves U+2028/U+2029 raw, but both terminate a JS string
540
+ * literal (valid in JSON, not in JS), so escape them (matches JsonGenerator).
541
+ * @param {string} str raw string
542
+ * @returns {string} a quoted, inline-safe JS string literal
543
+ */
544
+ const toJsStringLiteral = (str) =>
545
+ JSON.stringify(str).replace(LINE_SEPARATOR_REGEXP, (c) =>
546
+ c === "\u2029" ? "\\u2029" : "\\u2028"
547
+ );
548
+
533
549
  module.exports.ABSOLUTE_PATH_REGEXP = ABSOLUTE_PATH_REGEXP;
534
550
  module.exports.WINDOWS_ABS_PATH_REGEXP = WINDOWS_ABS_PATH_REGEXP;
535
551
  module.exports.absolutify = absolutify;
@@ -543,3 +559,4 @@ module.exports.parseResource = makeCacheable(_parseResource);
543
559
  module.exports.parseResourceWithoutFragment = makeCacheable(
544
560
  _parseResourceWithoutFragment
545
561
  );
562
+ module.exports.toJsStringLiteral = toJsStringLiteral;
@@ -0,0 +1,62 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("../ModuleTypeConstants");
9
+ const { parseResource } = require("./identifier");
10
+
11
+ /** @typedef {import("../NormalModuleFactory")} NormalModuleFactory */
12
+
13
+ /**
14
+ * When a built-in module type is only enabled implicitly (`experiments.css` /
15
+ * `experiments.html` resolved from their `"auto"` default), modules that reach
16
+ * the factory with loaders applied — an inline request or loaders injected via
17
+ * hooks (e.g. html-webpack-plugin's template loader) — keep the pre-existing
18
+ * behavior: the loader result is parsed as JavaScript, not as the built-in type.
19
+ * A `!=!` matchResource is an explicit re-type of the loader result and wins.
20
+ *
21
+ * TODO webpack 6: css/html are enabled unconditionally (`experiments.*: true`),
22
+ * so this implicit-only workaround can be removed together with the `"auto"`
23
+ * marker in `applyExperimentsDefaults`.
24
+ * @param {NormalModuleFactory} normalModuleFactory the normal module factory
25
+ * @param {string} pluginName name of the calling plugin, used for the tap
26
+ * @param {RegExp} test resource path test of the built-in default rule
27
+ * @param {string} type built-in module type assigned by that default rule
28
+ * @returns {void}
29
+ */
30
+ module.exports = (normalModuleFactory, pluginName, test, type) => {
31
+ normalModuleFactory.hooks.createModule.tap(
32
+ pluginName,
33
+ (createData, _resolveData) => {
34
+ if (
35
+ createData.settings.type !== type ||
36
+ createData.loaders.length === 0 ||
37
+ createData.matchResource !== undefined ||
38
+ !test.test(parseResource(createData.resource).path)
39
+ ) {
40
+ return;
41
+ }
42
+ // Drop the default rule's type-specific effects along with the type
43
+ createData.settings = {
44
+ ...createData.settings,
45
+ type: JAVASCRIPT_MODULE_TYPE_AUTO,
46
+ parser: undefined,
47
+ generator: undefined,
48
+ resolve: undefined
49
+ };
50
+ createData.type = JAVASCRIPT_MODULE_TYPE_AUTO;
51
+ createData.parser = normalModuleFactory.getParser(
52
+ JAVASCRIPT_MODULE_TYPE_AUTO
53
+ );
54
+ createData.parserOptions = undefined;
55
+ createData.generator = normalModuleFactory.getGenerator(
56
+ JAVASCRIPT_MODULE_TYPE_AUTO
57
+ );
58
+ createData.generatorOptions = undefined;
59
+ createData.resolveOptions = undefined;
60
+ }
61
+ );
62
+ };
@@ -5,15 +5,15 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ // AUTO-GENERATED by tooling/generate-internal-serializables.js
8
9
  // We need to include a list of requires here
9
10
  // to allow webpack to be bundled with only static requires
10
11
  // We could use a dynamic require(`../${request}`) but this
11
12
  // would include too many modules and not every tool is able
12
13
  // to process this
13
14
  module.exports = {
14
- AsyncDependenciesBlock: () => require("../AsyncDependenciesBlock"),
15
- ContextModule: () => require("../ContextModule"),
16
15
  "asset/AssetModule": () => require("../asset/AssetModule"),
16
+ "asset/RawDataUrlModule": () => require("../asset/RawDataUrlModule"),
17
17
  "cache/PackFileCacheStrategy": () =>
18
18
  require("../cache/PackFileCacheStrategy"),
19
19
  "cache/ResolverCachePlugin": () => require("../cache/ResolverCachePlugin"),
@@ -45,20 +45,14 @@ module.exports = {
45
45
  require("../dependencies/AMDRequireItemDependency"),
46
46
  "dependencies/CachedConstDependency": () =>
47
47
  require("../dependencies/CachedConstDependency"),
48
- "dependencies/ExternalModuleDependency": () =>
49
- require("../dependencies/ExternalModuleDependency"),
50
- "dependencies/ExternalModuleInitFragment": () =>
51
- require("../dependencies/ExternalModuleInitFragment"),
52
- "dependencies/CreateScriptUrlDependency": () =>
53
- require("../dependencies/CreateScriptUrlDependency"),
54
- "dependencies/CommonJsRequireContextDependency": () =>
55
- require("../dependencies/CommonJsRequireContextDependency"),
56
48
  "dependencies/CommonJsExportRequireDependency": () =>
57
49
  require("../dependencies/CommonJsExportRequireDependency"),
58
50
  "dependencies/CommonJsExportsDependency": () =>
59
51
  require("../dependencies/CommonJsExportsDependency"),
60
52
  "dependencies/CommonJsFullRequireDependency": () =>
61
53
  require("../dependencies/CommonJsFullRequireDependency"),
54
+ "dependencies/CommonJsRequireContextDependency": () =>
55
+ require("../dependencies/CommonJsRequireContextDependency"),
62
56
  "dependencies/CommonJsRequireDependency": () =>
63
57
  require("../dependencies/CommonJsRequireDependency"),
64
58
  "dependencies/CommonJsSelfReferenceDependency": () =>
@@ -69,18 +63,20 @@ module.exports = {
69
63
  require("../dependencies/ContextDependency"),
70
64
  "dependencies/ContextElementDependency": () =>
71
65
  require("../dependencies/ContextElementDependency"),
66
+ "dependencies/CreateScriptUrlDependency": () =>
67
+ require("../dependencies/CreateScriptUrlDependency"),
72
68
  "dependencies/CriticalDependencyWarning": () =>
73
69
  require("../dependencies/CriticalDependencyWarning"),
74
- "dependencies/CssImportDependency": () =>
75
- require("../dependencies/CssImportDependency"),
76
- "dependencies/CssUrlDependency": () =>
77
- require("../dependencies/CssUrlDependency"),
78
- "dependencies/CssIcssImportDependency": () =>
79
- require("../dependencies/CssIcssImportDependency"),
80
70
  "dependencies/CssIcssExportDependency": () =>
81
71
  require("../dependencies/CssIcssExportDependency"),
72
+ "dependencies/CssIcssImportDependency": () =>
73
+ require("../dependencies/CssIcssImportDependency"),
82
74
  "dependencies/CssIcssSymbolDependency": () =>
83
75
  require("../dependencies/CssIcssSymbolDependency"),
76
+ "dependencies/CssImportDependency": () =>
77
+ require("../dependencies/CssImportDependency"),
78
+ "dependencies/CssUrlDependency": () =>
79
+ require("../dependencies/CssUrlDependency"),
84
80
  "dependencies/DelegatedSourceDependency": () =>
85
81
  require("../dependencies/DelegatedSourceDependency"),
86
82
  "dependencies/DllEntryDependency": () =>
@@ -89,12 +85,22 @@ module.exports = {
89
85
  require("../dependencies/EntryDependency"),
90
86
  "dependencies/ExportsInfoDependency": () =>
91
87
  require("../dependencies/ExportsInfoDependency"),
88
+ "dependencies/ExternalModuleConstDependency": () =>
89
+ require("../dependencies/ExternalModuleInitFragmentDependency"),
90
+ "dependencies/ExternalModuleDependency": () =>
91
+ require("../dependencies/ExternalModuleDependency"),
92
+ "dependencies/ExternalModuleInitFragment": () =>
93
+ require("../dependencies/ExternalModuleInitFragment"),
94
+ "dependencies/ExternalModuleInitFragmentDependency": () =>
95
+ require("../dependencies/ExternalModuleInitFragmentDependency"),
92
96
  "dependencies/HarmonyAcceptDependency": () =>
93
97
  require("../dependencies/HarmonyAcceptDependency"),
94
98
  "dependencies/HarmonyAcceptImportDependency": () =>
95
99
  require("../dependencies/HarmonyAcceptImportDependency"),
96
100
  "dependencies/HarmonyCompatibilityDependency": () =>
97
101
  require("../dependencies/HarmonyCompatibilityDependency"),
102
+ "dependencies/HarmonyEvaluatedImportSpecifierDependency": () =>
103
+ require("../dependencies/HarmonyEvaluatedImportSpecifierDependency"),
98
104
  "dependencies/HarmonyExportExpressionDependency": () =>
99
105
  require("../dependencies/HarmonyExportExpressionDependency"),
100
106
  "dependencies/HarmonyExportHeaderDependency": () =>
@@ -107,16 +113,14 @@ module.exports = {
107
113
  require("../dependencies/HarmonyImportSideEffectDependency"),
108
114
  "dependencies/HarmonyImportSpecifierDependency": () =>
109
115
  require("../dependencies/HarmonyImportSpecifierDependency"),
110
- "dependencies/HarmonyEvaluatedImportSpecifierDependency": () =>
111
- require("../dependencies/HarmonyEvaluatedImportSpecifierDependency"),
116
+ "dependencies/HtmlEntryDependency": () =>
117
+ require("../dependencies/HtmlEntryDependency"),
112
118
  "dependencies/HtmlInlineHtmlDependency": () =>
113
119
  require("../dependencies/HtmlInlineHtmlDependency"),
114
120
  "dependencies/HtmlInlineScriptDependency": () =>
115
121
  require("../dependencies/HtmlInlineScriptDependency"),
116
122
  "dependencies/HtmlInlineStyleDependency": () =>
117
123
  require("../dependencies/HtmlInlineStyleDependency"),
118
- "dependencies/HtmlEntryDependency": () =>
119
- require("../dependencies/HtmlEntryDependency"),
120
124
  "dependencies/HtmlSourceDependency": () =>
121
125
  require("../dependencies/HtmlSourceDependency"),
122
126
  "dependencies/ImportContextDependency": () =>
@@ -125,6 +129,16 @@ module.exports = {
125
129
  require("../dependencies/ImportDependency"),
126
130
  "dependencies/ImportEagerDependency": () =>
127
131
  require("../dependencies/ImportEagerDependency"),
132
+ "dependencies/ImportMetaContextDependency": () =>
133
+ require("../dependencies/ImportMetaContextDependency"),
134
+ "dependencies/ImportMetaGlobDependency": () =>
135
+ require("../dependencies/ImportMetaGlobDependency"),
136
+ "dependencies/ImportMetaHotAcceptDependency": () =>
137
+ require("../dependencies/ImportMetaHotAcceptDependency"),
138
+ "dependencies/ImportMetaHotDeclineDependency": () =>
139
+ require("../dependencies/ImportMetaHotDeclineDependency"),
140
+ "dependencies/ImportMetaResolveDependency": () =>
141
+ require("../dependencies/ImportMetaResolveDependency"),
128
142
  "dependencies/ImportWeakDependency": () =>
129
143
  require("../dependencies/ImportWeakDependency"),
130
144
  "dependencies/JsonExportsDependency": () =>
@@ -138,12 +152,8 @@ module.exports = {
138
152
  require("../dependencies/ModuleHotAcceptDependency"),
139
153
  "dependencies/ModuleHotDeclineDependency": () =>
140
154
  require("../dependencies/ModuleHotDeclineDependency"),
141
- "dependencies/ImportMetaHotAcceptDependency": () =>
142
- require("../dependencies/ImportMetaHotAcceptDependency"),
143
- "dependencies/ImportMetaHotDeclineDependency": () =>
144
- require("../dependencies/ImportMetaHotDeclineDependency"),
145
- "dependencies/ImportMetaContextDependency": () =>
146
- require("../dependencies/ImportMetaContextDependency"),
155
+ "dependencies/ModuleInitFragmentDependency": () =>
156
+ require("../dependencies/ModuleInitFragmentDependency"),
147
157
  "dependencies/ProvidedDependency": () =>
148
158
  require("../dependencies/ProvidedDependency"),
149
159
  "dependencies/PureExpressionDependency": () =>
@@ -173,11 +183,13 @@ module.exports = {
173
183
  "dependencies/StaticExportsDependency": () =>
174
184
  require("../dependencies/StaticExportsDependency"),
175
185
  "dependencies/SystemPlugin": () => require("../dependencies/SystemPlugin"),
176
- "dependencies/UnsupportedDependency": () =>
177
- require("../dependencies/UnsupportedDependency"),
178
- "dependencies/URLDependency": () => require("../dependencies/URLDependency"),
186
+ "dependencies/TopLevelAwaitDependency": () =>
187
+ require("../dependencies/TopLevelAwaitDependency"),
179
188
  "dependencies/URLContextDependency": () =>
180
189
  require("../dependencies/URLContextDependency"),
190
+ "dependencies/URLDependency": () => require("../dependencies/URLDependency"),
191
+ "dependencies/UnsupportedDependency": () =>
192
+ require("../dependencies/UnsupportedDependency"),
181
193
  "dependencies/WebAssemblyExportImportedDependency": () =>
182
194
  require("../dependencies/WebAssemblyExportImportedDependency"),
183
195
  "dependencies/WebAssemblyImportDependency": () =>
@@ -186,6 +198,32 @@ module.exports = {
186
198
  require("../dependencies/WebpackIsIncludedDependency"),
187
199
  "dependencies/WorkerDependency": () =>
188
200
  require("../dependencies/WorkerDependency"),
201
+ "dependencies/WorkletDependency": () =>
202
+ require("../dependencies/WorkletDependency"),
203
+ "dll/DelegatedModule": () => require("../dll/DelegatedModule"),
204
+ "dll/DllModule": () => require("../dll/DllModule"),
205
+ "errors/CommentCompilationWarning": () =>
206
+ require("../errors/CommentCompilationWarning"),
207
+ "errors/EnvironmentNotSupportAsyncWarning": () =>
208
+ require("../errors/EnvironmentNotSupportAsyncWarning"),
209
+ "errors/HookWebpackError": () => require("../errors/HookWebpackError"),
210
+ "errors/InvalidDependenciesModuleWarning": () =>
211
+ require("../errors/InvalidDependenciesModuleWarning"),
212
+ "errors/JSONParseError": () => require("../errors/JSONParseError"),
213
+ "errors/ModuleBuildError": () => require("../errors/ModuleBuildError"),
214
+ "errors/ModuleDependencyWarning": () =>
215
+ require("../errors/ModuleDependencyWarning"),
216
+ "errors/ModuleError": () => require("../errors/ModuleError"),
217
+ "errors/ModuleParseError": () => require("../errors/ModuleParseError"),
218
+ "errors/ModuleWarning": () => require("../errors/ModuleWarning"),
219
+ "errors/NodeStuffInWebError": () => require("../errors/NodeStuffInWebError"),
220
+ "errors/NonErrorEmittedError": () =>
221
+ require("../errors/NonErrorEmittedError"),
222
+ "errors/UnhandledSchemeError": () =>
223
+ require("../errors/UnhandledSchemeError"),
224
+ "errors/UnsupportedFeatureWarning": () =>
225
+ require("../errors/UnsupportedFeatureWarning"),
226
+ "errors/WebpackError": () => require("../errors/WebpackError"),
189
227
  "html/HtmlModule": () => require("../html/HtmlModule"),
190
228
  "javascript/JavascriptModule": () =>
191
229
  require("../javascript/JavascriptModule"),
@@ -193,55 +231,34 @@ module.exports = {
193
231
  "json/JsonModule": () => require("../json/JsonModule"),
194
232
  "optimize/ConcatenatedModule": () =>
195
233
  require("../optimize/ConcatenatedModule"),
234
+ "optimize/InlineExports": () => require("../optimize/InlineExports"),
235
+ "sharing/ConsumeSharedFallbackDependency": () =>
236
+ require("../sharing/ConsumeSharedFallbackDependency"),
237
+ "sharing/ConsumeSharedModule": () =>
238
+ require("../sharing/ConsumeSharedModule"),
239
+ "sharing/ProvideForSharedDependency": () =>
240
+ require("../sharing/ProvideForSharedDependency"),
241
+ "sharing/ProvideSharedDependency": () =>
242
+ require("../sharing/ProvideSharedDependency"),
243
+ "sharing/ProvideSharedModule": () =>
244
+ require("../sharing/ProvideSharedModule"),
245
+ "util/LazySet": () => require("../util/LazySet"),
246
+ "util/registerExternalSerializer": () => {
247
+ // already registered
248
+ },
196
249
  "wasm-async/AsyncWasmModule": () => require("../wasm-async/AsyncWasmModule"),
197
250
  "wasm-sync/SyncWasmModule": () => require("../wasm-sync/SyncWasmModule"),
198
-
251
+ AsyncDependenciesBlock: () => require("../AsyncDependenciesBlock"),
252
+ ContextModule: () => require("../ContextModule"),
253
+ CssModule: () => require("../css/CssModule"),
199
254
  DependenciesBlock: () => require("../DependenciesBlock"),
200
255
  ExternalModule: () => require("../ExternalModule"),
201
256
  FileSystemInfo: () => require("../FileSystemInfo"),
202
257
  InitFragment: () => require("../InitFragment"),
258
+ Module: () => require("../Module"),
203
259
  ModuleGraph: () => require("../ModuleGraph"),
260
+ NodeStuffInWebError: () => require("../errors/NodeStuffInWebError"),
204
261
  NormalModule: () => require("../NormalModule"),
205
- CssModule: () => require("../css/CssModule"),
206
262
  RawDataUrlModule: () => require("../asset/RawDataUrlModule"),
207
- RawModule: () => require("../RawModule"),
208
- "sharing/ConsumeSharedModule": () =>
209
- require("../sharing/ConsumeSharedModule"),
210
- "sharing/ConsumeSharedFallbackDependency": () =>
211
- require("../sharing/ConsumeSharedFallbackDependency"),
212
- "sharing/ProvideSharedModule": () =>
213
- require("../sharing/ProvideSharedModule"),
214
- "sharing/ProvideSharedDependency": () =>
215
- require("../sharing/ProvideSharedDependency"),
216
- "sharing/ProvideForSharedDependency": () =>
217
- require("../sharing/ProvideForSharedDependency"),
218
-
219
- "errors/WebpackError": () => require("../errors/WebpackError"),
220
- "errors/InvalidDependenciesModuleWarning": () =>
221
- require("../errors/InvalidDependenciesModuleWarning"),
222
- "errors/Module": () => require("../Module"),
223
- "errors/ModuleParseError": () => require("../errors/ModuleParseError"),
224
- "errors/ModuleWarning": () => require("../errors/ModuleWarning"),
225
- "errors/ModuleBuildError": () => require("../errors/ModuleBuildError"),
226
- "errors/ModuleDependencyWarning": () =>
227
- require("../errors/ModuleDependencyWarning"),
228
- "errors/ModuleError": () => require("../errors/ModuleError"),
229
- "errors/UnhandledSchemeError": () =>
230
- require("../errors/UnhandledSchemeError"),
231
- "errors/UnsupportedFeatureWarning": () =>
232
- require("../errors/UnsupportedFeatureWarning"),
233
- "errors/EnvironmentNotSupportAsyncWarning": () =>
234
- require("../errors/EnvironmentNotSupportAsyncWarning"),
235
- "errors/CommentCompilationWarning": () =>
236
- require("../errors/CommentCompilationWarning"),
237
- "errors/NodeStuffInWebError": () => require("../errors/NodeStuffInWebError"),
238
- "errors/JSONParseError": () => require("../errors/JSONParseError"),
239
-
240
- "dll/DelegatedModule": () => require("../dll/DelegatedModule"),
241
- "dll/DllModule": () => require("../dll/DllModule"),
242
-
243
- "util/LazySet": () => require("../util/LazySet"),
244
- "util/registerExternalSerializer": () => {
245
- // already registered
246
- }
263
+ RawModule: () => require("../RawModule")
247
264
  };
@@ -5,54 +5,60 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const binarySearchBounds = require("./binarySearchBounds");
8
9
  const memoize = require("./memoize");
9
10
 
10
11
  const getVm = memoize(() => require("vm"));
11
12
 
12
- module.exports.CompilerHintNotationRegExp = Object.freeze({
13
+ const CompilerHintNotationRegExp = Object.freeze({
13
14
  Pure: /^\s*(?:#|@)__PURE__\s*$/,
14
15
  NoSideEffects: /^\s*[#@]__NO_SIDE_EFFECTS__\s*$/
15
16
  });
16
17
 
18
+ // Whole-comment `webpackXxx: <bool|number|null>` pair — parsed without `vm`.
19
+ const MAGIC_COMMENT_FAST_PATH =
20
+ /^\s*(webpack[A-Z][A-Za-z]+)\s*:\s*(true|false|null|-?\d+(?:\.\d+)?)\s*$/;
21
+
22
+ const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z][A-Za-z]+:/);
23
+
24
+ /** @type {Readonly<{ options: null, errors: null }>} */
25
+ const EMPTY_COMMENT_OPTIONS = Object.freeze({
26
+ options: null,
27
+ errors: null
28
+ });
29
+
17
30
  /**
18
- * regexp to match at least one "magic comment"
19
31
  * @returns {import("vm").Context} magic comment context
20
32
  */
21
- module.exports.createMagicCommentContext = () =>
33
+ const createMagicCommentContext = () =>
22
34
  getVm().createContext(undefined, {
23
35
  name: "Webpack Magic Comment Parser",
24
36
  codeGeneration: { strings: false, wasm: false }
25
37
  });
26
38
 
27
- // Whole-comment `webpackXxx: <bool|number|null>` pair — parsed without `vm`.
28
- const MAGIC_COMMENT_FAST_PATH =
29
- /^\s*(webpack[A-Z][A-Za-z]+)\s*:\s*(true|false|null|-?\d+(?:\.\d+)?)\s*$/;
30
-
31
39
  /**
32
- * Parse one magic comment's text into its options object. Values are detached
40
+ * Parse one magic comment's text and merge into `options`. Values are detached
33
41
  * from the vm context (RegExps recreated, other objects JSON-cloned). Throws
34
42
  * when the comment body fails to evaluate.
43
+ * @param {Record<string, EXPECTED_ANY>} options target to merge into
35
44
  * @param {string} value comment text (should already match `webpackCommentRegExp`)
36
45
  * @param {import("vm").Context} context context from `createMagicCommentContext`
37
- * @returns {Record<string, EXPECTED_ANY>} parsed options
46
+ * @returns {void}
38
47
  */
39
- module.exports.parseMagicComment = (value, context) => {
48
+ const assignMagicCommentOptions = (options, value, context) => {
40
49
  const fast = MAGIC_COMMENT_FAST_PATH.exec(value);
41
50
  if (fast !== null) {
42
51
  const raw = fast[2];
43
- return {
44
- [fast[1]]:
45
- raw === "true"
46
- ? true
47
- : raw === "false"
48
- ? false
49
- : raw === "null"
50
- ? null
51
- : Number(raw)
52
- };
52
+ options[fast[1]] =
53
+ raw === "true"
54
+ ? true
55
+ : raw === "false"
56
+ ? false
57
+ : raw === "null"
58
+ ? null
59
+ : Number(raw);
60
+ return;
53
61
  }
54
- /** @type {Record<string, EXPECTED_ANY>} */
55
- const options = {};
56
62
  for (let [key, val] of Object.entries(
57
63
  getVm().runInContext(`(function(){return {${value}};})()`, context)
58
64
  )) {
@@ -64,8 +70,98 @@ module.exports.parseMagicComment = (value, context) => {
64
70
  }
65
71
  options[key] = val;
66
72
  }
73
+ };
74
+
75
+ /**
76
+ * Parse one magic comment's text into its options object.
77
+ * @param {string} value comment text (should already match `webpackCommentRegExp`)
78
+ * @param {import("vm").Context} context context from `createMagicCommentContext`
79
+ * @returns {Record<string, EXPECTED_ANY>} parsed options
80
+ */
81
+ const parseMagicComment = (value, context) => {
82
+ /** @type {Record<string, EXPECTED_ANY>} */
83
+ const options = {};
84
+ assignMagicCommentOptions(options, value, context);
67
85
  return options;
68
86
  };
69
- module.exports.webpackCommentRegExp = new RegExp(
70
- /(^|\W)webpack[A-Z][A-Za-z]+:/
71
- );
87
+
88
+ /**
89
+ * `binarySearchBounds` comparator for `getCommentsInRange`.
90
+ * @param {{ range: [number, number] }} comment comment
91
+ * @param {number} needle needle (byte offset)
92
+ * @returns {number} comparison
93
+ */
94
+ const compareCommentStart = (comment, needle) => comment.range[0] - needle;
95
+
96
+ /**
97
+ * Comments fully inside `range`, via binary search over source-ordered `comments`.
98
+ * @template {object} TComment
99
+ * @param {(TComment & { range: [number, number] })[]} comments source-ordered comments
100
+ * @param {[number, number]} range range
101
+ * @returns {TComment[]} comments in the range
102
+ */
103
+ const getCommentsInRange = (comments, range) => {
104
+ if (comments.length === 0) return [];
105
+ const [start, end] = range;
106
+ let idx = binarySearchBounds.ge(comments, start, compareCommentStart);
107
+ /** @type {TComment[]} */
108
+ const commentsInRange = [];
109
+ while (comments[idx] && comments[idx].range[1] <= end) {
110
+ commentsInRange.push(comments[idx]);
111
+ idx++;
112
+ }
113
+ return commentsInRange;
114
+ };
115
+
116
+ /**
117
+ * Merge webpack magic-comment options from `comments` in source order.
118
+ * @template {object} TComment
119
+ * @param {(TComment & { value: string })[]} comments comments fully inside the range
120
+ * @param {import("vm").Context} context context from `createMagicCommentContext`
121
+ * @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: TComment })[] | null }} result
122
+ */
123
+ const parseMagicCommentOptions = (comments, context) => {
124
+ if (comments.length === 0) {
125
+ return /** @type {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: TComment })[] | null }} */ (
126
+ EMPTY_COMMENT_OPTIONS
127
+ );
128
+ }
129
+ /** @type {Record<string, EXPECTED_ANY>} */
130
+ const options = {};
131
+ /** @type {(Error & { comment: TComment })[]} */
132
+ const errors = [];
133
+ for (const comment of comments) {
134
+ const { value } = comment;
135
+ if (value && webpackCommentRegExp.test(value)) {
136
+ try {
137
+ assignMagicCommentOptions(options, value, context);
138
+ } catch (err) {
139
+ const newErr = new Error(String(/** @type {Error} */ (err).message));
140
+ newErr.stack = String(/** @type {Error} */ (err).stack);
141
+ Object.assign(newErr, { comment });
142
+ errors.push(/** @type {Error & { comment: TComment }} */ (newErr));
143
+ }
144
+ }
145
+ }
146
+ return { options, errors };
147
+ };
148
+
149
+ /**
150
+ * Merge webpack magic-comment options from comments inside `range`.
151
+ * @template {object} TComment
152
+ * @param {(TComment & { range: [number, number], value: string })[]} comments source-ordered comments
153
+ * @param {[number, number]} range range
154
+ * @param {import("vm").Context} context context from `createMagicCommentContext`
155
+ * @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: TComment })[] | null }} result
156
+ */
157
+ const parseCommentOptionsInRange = (comments, range, context) =>
158
+ parseMagicCommentOptions(getCommentsInRange(comments, range), context);
159
+
160
+ module.exports = {
161
+ CompilerHintNotationRegExp,
162
+ createMagicCommentContext,
163
+ getCommentsInRange,
164
+ parseCommentOptionsInRange,
165
+ parseMagicComment,
166
+ webpackCommentRegExp
167
+ };
@@ -83,8 +83,8 @@ function fnv1a64(str) {
83
83
  * @example
84
84
  * ```js
85
85
  * const numberHash = require("webpack/lib/util/numberHash");
86
- * numberHash("hello", 1000); // 73
87
- * numberHash("hello world"); // 72
86
+ * numberHash("hello", 1000); // 723
87
+ * numberHash("hello world", 1000); // 159
88
88
  * ```
89
89
  */
90
90
  module.exports = (str, range) => {
@@ -53,13 +53,15 @@ class AsyncWasmCompileRuntimeModule extends RuntimeModule {
53
53
  const compilation = /** @type {Compilation} */ (this.compilation);
54
54
  const chunk = /** @type {Chunk} */ (this.chunk);
55
55
  const { outputOptions, runtimeTemplate } = compilation;
56
+ // Opt-out fallback to non-streaming when the server serves wasm with a wrong MIME type.
57
+ const streamingFallback = outputOptions.wasmStreamingFallback;
56
58
  const fn = RuntimeGlobals.compileWasm;
57
59
  const wasmModuleSrcPath = compilation.getPath(
58
60
  JSON.stringify(outputOptions.webassemblyModuleFilename),
59
61
  {
60
62
  hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
61
63
  hashWithLength: (length) =>
62
- `" + ${RuntimeGlobals.getFullHash}}().slice(0, ${length}) + "`,
64
+ `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
63
65
  module: {
64
66
  id: '" + wasmModuleId + "',
65
67
  hash: '" + wasmModuleHash + "',
@@ -105,24 +107,28 @@ class AsyncWasmCompileRuntimeModule extends RuntimeModule {
105
107
  ? this.generateBeforeCompileStreaming()
106
108
  : ""
107
109
  ),
108
- Template.indent([
109
- "return WebAssembly.compileStreaming(res)",
110
- Template.indent([
111
- ".catch(",
112
- Template.indent([
113
- runtimeTemplate.basicFunction("e", [
114
- 'if(res.headers.get("Content-Type") !== "application/wasm") {',
110
+ Template.indent(
111
+ streamingFallback
112
+ ? [
113
+ "return WebAssembly.compileStreaming(res)",
115
114
  Template.indent([
116
- 'console.warn("`WebAssembly.compileStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.compile` which is slower. Original error:\\n", e);',
117
- "return fallback();"
118
- ]),
119
- "}",
120
- "throw e;"
121
- ])
122
- ]),
123
- ");"
124
- ])
125
- ]),
115
+ ".catch(",
116
+ Template.indent([
117
+ runtimeTemplate.basicFunction("e", [
118
+ 'if(res.headers.get("Content-Type") !== "application/wasm") {',
119
+ Template.indent([
120
+ 'console.warn("`WebAssembly.compileStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.compile` which is slower. Original error:\\n", e);',
121
+ "return fallback();"
122
+ ]),
123
+ "}",
124
+ "throw e;"
125
+ ])
126
+ ]),
127
+ ");"
128
+ ])
129
+ ]
130
+ : ["return WebAssembly.compileStreaming(res);"]
131
+ ),
126
132
  "}",
127
133
  "return fallback();"
128
134
  ]),