webpack 5.90.3 → 5.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -7,14 +7,16 @@
7
7
 
8
8
  const { UsageState } = require("../ExportsInfo");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
- const { filterRuntime, deepMergeRuntime } = require("../util/runtime");
10
+ const { filterRuntime, runtimeToString } = require("../util/runtime");
11
11
  const NullDependency = require("./NullDependency");
12
12
 
13
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
15
  /** @typedef {import("../Dependency")} Dependency */
16
+ /** @typedef {import("../Dependency").RuntimeSpec} RuntimeSpec */
16
17
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
17
18
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
19
+ /** @typedef {import("../Module")} Module */
18
20
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
21
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
20
22
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
@@ -31,7 +33,31 @@ class PureExpressionDependency extends NullDependency {
31
33
  this.range = range;
32
34
  /** @type {Set<string> | false} */
33
35
  this.usedByExports = false;
34
- this._hashUpdate = undefined;
36
+ }
37
+
38
+ /**
39
+ * @param {ModuleGraph} moduleGraph module graph
40
+ * @param {RuntimeSpec} runtime current runtimes
41
+ * @returns {boolean | RuntimeSpec} runtime condition
42
+ */
43
+ _getRuntimeCondition(moduleGraph, runtime) {
44
+ const usedByExports = this.usedByExports;
45
+ if (usedByExports !== false) {
46
+ const selfModule =
47
+ /** @type {Module} */
48
+ (moduleGraph.getParentModule(this));
49
+ const exportsInfo = moduleGraph.getExportsInfo(selfModule);
50
+ const runtimeCondition = filterRuntime(runtime, runtime => {
51
+ for (const exportName of usedByExports) {
52
+ if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
53
+ return true;
54
+ }
55
+ }
56
+ return false;
57
+ });
58
+ return runtimeCondition;
59
+ }
60
+ return false;
35
61
  }
36
62
 
37
63
  /**
@@ -41,10 +67,22 @@ class PureExpressionDependency extends NullDependency {
41
67
  * @returns {void}
42
68
  */
43
69
  updateHash(hash, context) {
44
- if (this._hashUpdate === undefined) {
45
- this._hashUpdate = this.range + "";
70
+ const runtimeCondition = this._getRuntimeCondition(
71
+ context.chunkGraph.moduleGraph,
72
+ context.runtime
73
+ );
74
+ if (runtimeCondition === true) {
75
+ return;
76
+ } else if (runtimeCondition === false) {
77
+ hash.update("null");
78
+ } else {
79
+ hash.update(
80
+ runtimeToString(runtimeCondition) +
81
+ "|" +
82
+ runtimeToString(context.runtime)
83
+ );
46
84
  }
47
- hash.update(this._hashUpdate);
85
+ hash.update(this.range + "");
48
86
  }
49
87
 
50
88
  /**
@@ -93,52 +131,31 @@ PureExpressionDependency.Template = class PureExpressionDependencyTemplate exten
93
131
  apply(
94
132
  dependency,
95
133
  source,
96
- {
97
- chunkGraph,
98
- moduleGraph,
99
- runtime,
100
- runtimes,
101
- runtimeTemplate,
102
- runtimeRequirements
103
- }
134
+ { chunkGraph, moduleGraph, runtime, runtimeTemplate, runtimeRequirements }
104
135
  ) {
105
136
  const dep = /** @type {PureExpressionDependency} */ (dependency);
106
-
107
- const usedByExports = dep.usedByExports;
108
- if (usedByExports !== false) {
109
- const selfModule = moduleGraph.getParentModule(dep);
110
- const exportsInfo = moduleGraph.getExportsInfo(selfModule);
111
- const merged = deepMergeRuntime(runtimes, runtime);
112
- const runtimeCondition = filterRuntime(merged, runtime => {
113
- for (const exportName of usedByExports) {
114
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
115
- return true;
116
- }
117
- }
118
- return false;
137
+ const runtimeCondition = dep._getRuntimeCondition(moduleGraph, runtime);
138
+ if (runtimeCondition === true) {
139
+ return;
140
+ } else if (runtimeCondition === false) {
141
+ source.insert(
142
+ dep.range[0],
143
+ `(/* unused pure expression or super */ null && (`
144
+ );
145
+ source.insert(dep.range[1], "))");
146
+ } else {
147
+ const condition = runtimeTemplate.runtimeConditionExpression({
148
+ chunkGraph,
149
+ runtime,
150
+ runtimeCondition,
151
+ runtimeRequirements
119
152
  });
120
- if (runtimeCondition === true) return;
121
- if (runtimeCondition !== false) {
122
- const condition = runtimeTemplate.runtimeConditionExpression({
123
- chunkGraph,
124
- runtime: merged,
125
- runtimeCondition,
126
- runtimeRequirements
127
- });
128
- source.insert(
129
- dep.range[0],
130
- `(/* runtime-dependent pure expression or super */ ${condition} ? (`
131
- );
132
- source.insert(dep.range[1], ") : null)");
133
- return;
134
- }
153
+ source.insert(
154
+ dep.range[0],
155
+ `(/* runtime-dependent pure expression or super */ ${condition} ? (`
156
+ );
157
+ source.insert(dep.range[1], ") : null)");
135
158
  }
136
-
137
- source.insert(
138
- dep.range[0],
139
- `(/* unused pure expression or super */ null && (`
140
- );
141
- source.insert(dep.range[1], "))");
142
159
  }
143
160
  };
144
161
 
@@ -80,7 +80,7 @@ class RequireContextPlugin {
80
80
  cachedSetProperty(
81
81
  options.resolveOptions || EMPTY_RESOLVE_OPTIONS,
82
82
  "dependencyType",
83
- options.category
83
+ /** @type {string} */ (options.category)
84
84
  )
85
85
  ).options;
86
86
 
@@ -11,9 +11,16 @@ const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
11
11
  const getFunctionExpression = require("./getFunctionExpression");
12
12
 
13
13
  /** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
14
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
15
+ /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
14
16
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
15
18
 
16
19
  module.exports = class RequireEnsureDependenciesBlockParserPlugin {
20
+ /**
21
+ * @param {JavascriptParser} parser the parser
22
+ * @returns {void}
23
+ */
17
24
  apply(parser) {
18
25
  parser.hooks.call
19
26
  .for("require.ensure")
@@ -45,9 +52,12 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
45
52
  const dependenciesExpr = parser.evaluateExpression(
46
53
  expr.arguments[0]
47
54
  );
48
- const dependenciesItems = dependenciesExpr.isArray()
49
- ? dependenciesExpr.items
50
- : [dependenciesExpr];
55
+ const dependenciesItems =
56
+ /** @type {BasicEvaluatedExpression[]} */ (
57
+ dependenciesExpr.isArray()
58
+ ? dependenciesExpr.items
59
+ : [dependenciesExpr]
60
+ );
51
61
  const successExpressionArg = expr.arguments[1];
52
62
  const successExpression =
53
63
  getFunctionExpression(successExpressionArg);
@@ -60,32 +70,34 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
60
70
  }
61
71
 
62
72
  const depBlock = new RequireEnsureDependenciesBlock(
63
- /** @type {ChunkGroupOptions & { entryOptions?: TODO }} */ (
64
- chunkName
65
- ),
66
- expr.loc
73
+ /** @type {ChunkGroupOptions & { entryOptions?: TODO }} */
74
+ (chunkName),
75
+ /** @type {DependencyLocation} */ (expr.loc)
67
76
  );
68
77
  const errorCallbackExists =
69
78
  expr.arguments.length === 4 ||
70
79
  (!chunkName && expr.arguments.length === 3);
71
80
  const dep = new RequireEnsureDependency(
72
- expr.range,
73
- expr.arguments[1].range,
74
- errorCallbackExists && expr.arguments[2].range
81
+ /** @type {Range} */ (expr.range),
82
+ /** @type {Range} */ (expr.arguments[1].range),
83
+ errorCallbackExists &&
84
+ /** @type {Range} */ (expr.arguments[2].range)
75
85
  );
76
- dep.loc = expr.loc;
86
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
77
87
  depBlock.addDependency(dep);
78
88
  const old = parser.state.current;
79
- parser.state.current = depBlock;
89
+ parser.state.current = /** @type {TODO} */ (depBlock);
80
90
  try {
81
91
  let failed = false;
82
92
  parser.inScope([], () => {
83
93
  for (const ee of dependenciesItems) {
84
94
  if (ee.isString()) {
85
95
  const ensureDependency = new RequireEnsureItemDependency(
86
- ee.string
96
+ /** @type {string} */ (ee.string)
87
97
  );
88
- ensureDependency.loc = ee.loc || expr.loc;
98
+ ensureDependency.loc =
99
+ /** @type {DependencyLocation} */
100
+ (expr.loc);
89
101
  depBlock.addDependency(ensureDependency);
90
102
  } else {
91
103
  failed = true;
@@ -21,7 +21,7 @@ class RequireEnsureDependency extends NullDependency {
21
21
  /**
22
22
  * @param {Range} range range
23
23
  * @param {Range} contentRange content range
24
- * @param {Range} errorHandlerRange error handler range
24
+ * @param {Range | false} errorHandlerRange error handler range
25
25
  */
26
26
  constructor(range, contentRange, errorHandlerRange) {
27
27
  super();
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
+ const RawDataUrlModule = require("../asset/RawDataUrlModule");
9
10
  const {
10
11
  getDependencyUsedByExportsCondition
11
12
  } = require("../optimize/InnerGraph");
@@ -16,6 +17,7 @@ const ModuleDependency = require("./ModuleDependency");
16
17
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
17
18
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
19
  /** @typedef {import("../Dependency")} Dependency */
20
+ /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
19
21
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
20
22
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
21
23
  /** @typedef {import("../Module")} Module */
@@ -28,7 +30,9 @@ const ModuleDependency = require("./ModuleDependency");
28
30
  /** @typedef {import("../util/Hash")} Hash */
29
31
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
30
32
 
31
- const getRawDataUrlModule = memoize(() => require("../asset/RawDataUrlModule"));
33
+ const getIgnoredRawDataUrlModule = memoize(() => {
34
+ return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
35
+ });
32
36
 
33
37
  class URLDependency extends ModuleDependency {
34
38
  /**
@@ -56,7 +60,7 @@ class URLDependency extends ModuleDependency {
56
60
 
57
61
  /**
58
62
  * @param {ModuleGraph} moduleGraph module graph
59
- * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
63
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
60
64
  */
61
65
  getCondition(moduleGraph) {
62
66
  return getDependencyUsedByExportsCondition(
@@ -71,8 +75,7 @@ class URLDependency extends ModuleDependency {
71
75
  * @returns {Module | null} a module
72
76
  */
73
77
  createIgnoredModule(context) {
74
- const RawDataUrlModule = getRawDataUrlModule();
75
- return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
78
+ return getIgnoredRawDataUrlModule();
76
79
  }
77
80
 
78
81
  /**
@@ -28,7 +28,7 @@ class WorkerDependency extends ModuleDependency {
28
28
  /**
29
29
  * @param {string} request request
30
30
  * @param {Range} range range
31
- * @param {Object} workerDependencyOptions options
31
+ * @param {object} workerDependencyOptions options
32
32
  * @param {string=} workerDependencyOptions.publicPath public path for the worker
33
33
  */
34
34
  constructor(request, range, workerDependencyOptions) {
@@ -369,7 +369,8 @@ class WorkerPlugin {
369
369
  );
370
370
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
371
371
  parser.state.module.addPresentationalDependency(dep);
372
- expressions.type = undefined;
372
+ /** @type {TODO} */
373
+ (expressions).type = undefined;
373
374
  }
374
375
  } else if (insertType === "comma") {
375
376
  if (this._module || hasSpreadInOptions) {
@@ -5,12 +5,14 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
8
9
  /** @typedef {import("estree").Expression} Expression */
10
+ /** @typedef {import("estree").FunctionExpression} FunctionExpression */
9
11
  /** @typedef {import("estree").SpreadElement} SpreadElement */
10
12
 
11
13
  /**
12
14
  * @param {Expression | SpreadElement} expr expressions
13
- * @returns {{fn: TODO, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information
15
+ * @returns {{fn: FunctionExpression | ArrowFunctionExpression, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information
14
16
  */
15
17
  module.exports = expr => {
16
18
  // <FunctionExpression>
@@ -19,9 +19,10 @@ const { getUndoPath } = require("../util/identifier");
19
19
 
20
20
  /** @typedef {import("../Chunk")} Chunk */
21
21
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
22
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
22
23
 
23
24
  /**
24
- * @typedef {Object} JsonpCompilationPluginHooks
25
+ * @typedef {object} JsonpCompilationPluginHooks
25
26
  * @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
26
27
  * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
27
28
  */
@@ -52,7 +53,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
52
53
  }
53
54
 
54
55
  /**
55
- * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
56
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
56
57
  */
57
58
  constructor(runtimeRequirements) {
58
59
  super("import chunk loading", RuntimeModule.STAGE_ATTACH);
@@ -88,7 +89,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
88
89
  const chunk = /** @type {Chunk} */ (this.chunk);
89
90
  const {
90
91
  runtimeTemplate,
91
- outputOptions: { importFunctionName }
92
+ outputOptions: { environment, importFunctionName, crossOriginLoading }
92
93
  } = compilation;
93
94
  const fn = RuntimeGlobals.ensureChunkHandlers;
94
95
  const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
@@ -104,6 +105,14 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
104
105
  const withHmr = this._runtimeRequirements.has(
105
106
  RuntimeGlobals.hmrDownloadUpdateHandlers
106
107
  );
108
+ const { linkPreload, linkPrefetch } =
109
+ ModuleChunkLoadingRuntimeModule.getCompilationHooks(compilation);
110
+ const withPrefetch =
111
+ environment.document &&
112
+ this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers);
113
+ const withPreload =
114
+ environment.document &&
115
+ this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers);
107
116
  const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
108
117
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
109
118
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
@@ -228,6 +237,86 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
228
237
  ])
229
238
  : "// no chunk on demand loading",
230
239
  "",
240
+ withPrefetch && hasJsMatcher !== false
241
+ ? `${
242
+ RuntimeGlobals.prefetchChunkHandlers
243
+ }.j = ${runtimeTemplate.basicFunction("chunkId", [
244
+ `if((!${
245
+ RuntimeGlobals.hasOwnProperty
246
+ }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
247
+ hasJsMatcher === true ? "true" : hasJsMatcher("chunkId")
248
+ }) {`,
249
+ Template.indent([
250
+ "installedChunks[chunkId] = null;",
251
+ linkPrefetch.call(
252
+ Template.asString([
253
+ "var link = document.createElement('link');",
254
+ crossOriginLoading
255
+ ? `link.crossOrigin = ${JSON.stringify(
256
+ crossOriginLoading
257
+ )};`
258
+ : "",
259
+ `if (${RuntimeGlobals.scriptNonce}) {`,
260
+ Template.indent(
261
+ `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
262
+ ),
263
+ "}",
264
+ 'link.rel = "prefetch";',
265
+ 'link.as = "script";',
266
+ `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`
267
+ ]),
268
+ chunk
269
+ ),
270
+ "document.head.appendChild(link);"
271
+ ]),
272
+ "}"
273
+ ])};`
274
+ : "// no prefetching",
275
+ "",
276
+ withPreload && hasJsMatcher !== false
277
+ ? `${
278
+ RuntimeGlobals.preloadChunkHandlers
279
+ }.j = ${runtimeTemplate.basicFunction("chunkId", [
280
+ `if((!${
281
+ RuntimeGlobals.hasOwnProperty
282
+ }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
283
+ hasJsMatcher === true ? "true" : hasJsMatcher("chunkId")
284
+ }) {`,
285
+ Template.indent([
286
+ "installedChunks[chunkId] = null;",
287
+ linkPreload.call(
288
+ Template.asString([
289
+ "var link = document.createElement('link');",
290
+ "link.charset = 'utf-8';",
291
+ `if (${RuntimeGlobals.scriptNonce}) {`,
292
+ Template.indent(
293
+ `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
294
+ ),
295
+ "}",
296
+ 'link.rel = "modulepreload";',
297
+ `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
298
+ crossOriginLoading
299
+ ? crossOriginLoading === "use-credentials"
300
+ ? 'link.crossOrigin = "use-credentials";'
301
+ : Template.asString([
302
+ "if (link.href.indexOf(window.location.origin + '/') !== 0) {",
303
+ Template.indent(
304
+ `link.crossOrigin = ${JSON.stringify(
305
+ crossOriginLoading
306
+ )};`
307
+ ),
308
+ "}"
309
+ ])
310
+ : ""
311
+ ]),
312
+ chunk
313
+ ),
314
+ "document.head.appendChild(link);"
315
+ ]),
316
+ "}"
317
+ ])};`
318
+ : "// no preloaded",
319
+ "",
231
320
  withExternalInstallChunk
232
321
  ? Template.asString([
233
322
  `${RuntimeGlobals.externalInstallChunk} = installChunk;`
@@ -38,7 +38,7 @@ const { registerNotSerializable } = require("../util/serialization");
38
38
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
39
39
 
40
40
  /**
41
- * @typedef {Object} BackendApi
41
+ * @typedef {object} BackendApi
42
42
  * @property {function(Error=): void} dispose
43
43
  * @property {function(Module): { client: string, data: string, active: boolean }} module
44
44
  */
@@ -319,7 +319,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
319
319
 
320
320
  class LazyCompilationPlugin {
321
321
  /**
322
- * @param {Object} options options
322
+ * @param {object} options options
323
323
  * @param {(function(Compiler, function(Error?, BackendApi?): void): void) | function(Compiler): Promise<BackendApi>} options.backend the backend
324
324
  * @param {boolean} options.entries true, when entries are lazy compiled
325
325
  * @param {boolean} options.imports true, when import() modules are lazy compiled
@@ -14,7 +14,7 @@ const {
14
14
  /** @typedef {import("../Compiler")} Compiler */
15
15
 
16
16
  /**
17
- * @typedef {Object} ChunkModuleIdRangePluginOptions
17
+ * @typedef {object} ChunkModuleIdRangePluginOptions
18
18
  * @property {string} name the chunk name
19
19
  * @property {("index" | "index2" | "preOrderIndex" | "postOrderIndex")=} order order
20
20
  * @property {number=} start start id
@@ -16,7 +16,7 @@ const {
16
16
  /** @typedef {import("../Module")} Module */
17
17
 
18
18
  /**
19
- * @typedef {Object} DeterministicChunkIdsPluginOptions
19
+ * @typedef {object} DeterministicChunkIdsPluginOptions
20
20
  * @property {string=} context context for ids
21
21
  * @property {number=} maxLength maximum length of ids
22
22
  */
@@ -18,7 +18,7 @@ const {
18
18
  /** @typedef {import("../Module")} Module */
19
19
 
20
20
  /**
21
- * @typedef {Object} DeterministicModuleIdsPluginOptions
21
+ * @typedef {object} DeterministicModuleIdsPluginOptions
22
22
  * @property {string=} context context relative to which module identifiers are computed
23
23
  * @property {function(Module): boolean=} test selector function for modules
24
24
  * @property {number=} maxLength maximum id length in digits (used as starting point)
@@ -78,7 +78,7 @@ const shortenLongString = (string, delimiter, hashFunction) => {
78
78
  /**
79
79
  * @param {Module} module the module
80
80
  * @param {string} context context directory
81
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
81
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
82
82
  * @returns {string} short module name
83
83
  */
84
84
  const getShortModuleName = (module, context, associatedObjectForCache) => {
@@ -98,7 +98,7 @@ exports.getShortModuleName = getShortModuleName;
98
98
  * @param {Module} module the module
99
99
  * @param {string} context context directory
100
100
  * @param {string | Hash} hashFunction hash function to use
101
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
101
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
102
102
  * @returns {string} long module name
103
103
  */
104
104
  const getLongModuleName = (
@@ -116,7 +116,7 @@ exports.getLongModuleName = getLongModuleName;
116
116
  /**
117
117
  * @param {Module} module the module
118
118
  * @param {string} context context directory
119
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
119
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
120
120
  * @returns {string} full module name
121
121
  */
122
122
  const getFullModuleName = (module, context, associatedObjectForCache) => {
@@ -134,7 +134,7 @@ exports.getFullModuleName = getFullModuleName;
134
134
  * @param {string} context context directory
135
135
  * @param {string} delimiter delimiter for names
136
136
  * @param {string | Hash} hashFunction hash function to use
137
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
137
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
138
138
  * @returns {string} short chunk name
139
139
  */
140
140
  const getShortChunkName = (
@@ -164,7 +164,7 @@ exports.getShortChunkName = getShortChunkName;
164
164
  * @param {string} context context directory
165
165
  * @param {string} delimiter delimiter for names
166
166
  * @param {string | Hash} hashFunction hash function to use
167
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
167
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
168
168
  * @returns {string} short chunk name
169
169
  */
170
170
  const getLongChunkName = (
@@ -197,7 +197,7 @@ exports.getLongChunkName = getLongChunkName;
197
197
  * @param {Chunk} chunk the chunk
198
198
  * @param {ChunkGraph} chunkGraph the chunk graph
199
199
  * @param {string} context context directory
200
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
200
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
201
201
  * @returns {string} full chunk name
202
202
  */
203
203
  const getFullChunkName = (
@@ -20,7 +20,7 @@ const {
20
20
  /** @typedef {import("../Module")} Module */
21
21
 
22
22
  /**
23
- * @typedef {Object} NamedChunkIdsPluginOptions
23
+ * @typedef {object} NamedChunkIdsPluginOptions
24
24
  * @property {string} [context] context
25
25
  * @property {string} [delimiter] delimiter
26
26
  */
@@ -19,7 +19,7 @@ const {
19
19
  /** @typedef {import("../Module")} Module */
20
20
 
21
21
  /**
22
- * @typedef {Object} NamedModuleIdsPluginOptions
22
+ * @typedef {object} NamedModuleIdsPluginOptions
23
23
  * @property {string} [context] context
24
24
  */
25
25
 
@@ -15,7 +15,7 @@ const plugin = "SyncModuleIdsPlugin";
15
15
 
16
16
  class SyncModuleIdsPlugin {
17
17
  /**
18
- * @param {Object} options options
18
+ * @param {object} options options
19
19
  * @param {string} options.path path to file
20
20
  * @param {string=} options.context context for module names
21
21
  * @param {function(Module): boolean} options.test selector for modules
@@ -63,7 +63,7 @@ class SyncModuleIdsPlugin {
63
63
  if (this._write) {
64
64
  compiler.hooks.emitRecords.tapAsync(plugin, callback => {
65
65
  if (!data || !dataChanged) return callback();
66
- /** @type {Object<string, string | number>} */
66
+ /** @type {{[key: string]: string | number}} */
67
67
  const json = {};
68
68
  const sorted = Array.from(data).sort(([a], [b]) => (a < b ? -1 : 1));
69
69
  for (const [key, value] of sorted) {
package/lib/index.js CHANGED
@@ -60,6 +60,8 @@ const memoize = require("./util/memoize");
60
60
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
61
61
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
62
62
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
63
+ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
64
+ /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
63
65
 
64
66
  /**
65
67
  * @template {Function} T
@@ -221,6 +223,9 @@ module.exports = mergeExports(fn, {
221
223
  get HotModuleReplacementPlugin() {
222
224
  return require("./HotModuleReplacementPlugin");
223
225
  },
226
+ get InitFragment() {
227
+ return require("./InitFragment");
228
+ },
224
229
  get IgnorePlugin() {
225
230
  return require("./IgnorePlugin");
226
231
  },
@@ -277,6 +282,9 @@ module.exports = mergeExports(fn, {
277
282
  get Parser() {
278
283
  return require("./Parser");
279
284
  },
285
+ get PlatformPlugin() {
286
+ return require("./PlatformPlugin");
287
+ },
280
288
  get PrefetchPlugin() {
281
289
  return require("./PrefetchPlugin");
282
290
  },
@@ -576,6 +584,9 @@ module.exports = mergeExports(fn, {
576
584
  },
577
585
  get LazySet() {
578
586
  return require("./util/LazySet");
587
+ },
588
+ get compileBooleanMatcher() {
589
+ return require("./util/compileBooleanMatcher");
579
590
  }
580
591
  },
581
592
 
@@ -27,7 +27,7 @@ const TypeBigInt = 13;
27
27
  class BasicEvaluatedExpression {
28
28
  constructor() {
29
29
  this.type = TypeUnknown;
30
- /** @type {[number, number] | undefined} */
30
+ /** @type {Range | undefined} */
31
31
  this.range = undefined;
32
32
  /** @type {boolean} */
33
33
  this.falsy = false;
@@ -420,7 +420,7 @@ class BasicEvaluatedExpression {
420
420
  *
421
421
  * @param {BasicEvaluatedExpression | null | undefined} prefix Expression to be added before the innerExpressions
422
422
  * @param {BasicEvaluatedExpression | null | undefined} postfix Expression to be added after the innerExpressions
423
- * @param {BasicEvaluatedExpression[]} innerExpressions Expressions to be wrapped
423
+ * @param {BasicEvaluatedExpression[] | undefined} innerExpressions Expressions to be wrapped
424
424
  * @returns {this} this
425
425
  */
426
426
  setWrapped(prefix, postfix, innerExpressions) {