webpack 5.59.0 → 5.76.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 (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
@@ -14,10 +14,14 @@ const ImportDependency = require("./ImportDependency");
14
14
  const ImportEagerDependency = require("./ImportEagerDependency");
15
15
  const ImportWeakDependency = require("./ImportWeakDependency");
16
16
 
17
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
17
18
  /** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
18
19
  /** @typedef {import("../ContextModule").ContextMode} ContextMode */
19
20
 
20
21
  class ImportParserPlugin {
22
+ /**
23
+ * @param {JavascriptParserOptions} options options
24
+ */
21
25
  constructor(options) {
22
26
  this.options = options;
23
27
  }
@@ -28,7 +32,7 @@ class ImportParserPlugin {
28
32
 
29
33
  let chunkName = null;
30
34
  /** @type {ContextMode} */
31
- let mode = "lazy";
35
+ let mode = this.options.dynamicImportMode;
32
36
  let include = null;
33
37
  let exclude = null;
34
38
  /** @type {string[][] | null} */
@@ -36,6 +40,17 @@ class ImportParserPlugin {
36
40
  /** @type {RawChunkGroupOptions} */
37
41
  const groupOptions = {};
38
42
 
43
+ const { dynamicImportPreload, dynamicImportPrefetch } = this.options;
44
+ if (dynamicImportPreload !== undefined && dynamicImportPreload !== false)
45
+ groupOptions.preloadOrder =
46
+ dynamicImportPreload === true ? 0 : dynamicImportPreload;
47
+ if (
48
+ dynamicImportPrefetch !== undefined &&
49
+ dynamicImportPrefetch !== false
50
+ )
51
+ groupOptions.prefetchOrder =
52
+ dynamicImportPrefetch === true ? 0 : dynamicImportPrefetch;
53
+
39
54
  const { options: importOptions, errors: commentErrors } =
40
55
  parser.parseCommentOptions(expr.range);
41
56
 
@@ -122,7 +137,7 @@ class ImportParserPlugin {
122
137
  if (importOptions.webpackInclude !== undefined) {
123
138
  if (
124
139
  !importOptions.webpackInclude ||
125
- importOptions.webpackInclude.constructor.name !== "RegExp"
140
+ !(importOptions.webpackInclude instanceof RegExp)
126
141
  ) {
127
142
  parser.state.module.addWarning(
128
143
  new UnsupportedFeatureWarning(
@@ -131,13 +146,13 @@ class ImportParserPlugin {
131
146
  )
132
147
  );
133
148
  } else {
134
- include = new RegExp(importOptions.webpackInclude);
149
+ include = importOptions.webpackInclude;
135
150
  }
136
151
  }
137
152
  if (importOptions.webpackExclude !== undefined) {
138
153
  if (
139
154
  !importOptions.webpackExclude ||
140
- importOptions.webpackExclude.constructor.name !== "RegExp"
155
+ !(importOptions.webpackExclude instanceof RegExp)
141
156
  ) {
142
157
  parser.state.module.addWarning(
143
158
  new UnsupportedFeatureWarning(
@@ -146,7 +161,7 @@ class ImportParserPlugin {
146
161
  )
147
162
  );
148
163
  } else {
149
- exclude = new RegExp(importOptions.webpackExclude);
164
+ exclude = importOptions.webpackExclude;
150
165
  }
151
166
  }
152
167
  if (importOptions.webpackExports !== undefined) {
@@ -175,16 +190,22 @@ class ImportParserPlugin {
175
190
  }
176
191
  }
177
192
 
178
- if (param.isString()) {
179
- if (mode !== "lazy" && mode !== "eager" && mode !== "weak") {
180
- parser.state.module.addWarning(
181
- new UnsupportedFeatureWarning(
182
- `\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}.`,
183
- expr.loc
184
- )
185
- );
186
- }
193
+ if (
194
+ mode !== "lazy" &&
195
+ mode !== "lazy-once" &&
196
+ mode !== "eager" &&
197
+ mode !== "weak"
198
+ ) {
199
+ parser.state.module.addWarning(
200
+ new UnsupportedFeatureWarning(
201
+ `\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`,
202
+ expr.loc
203
+ )
204
+ );
205
+ mode = "lazy";
206
+ }
187
207
 
208
+ if (param.isString()) {
188
209
  if (mode === "eager") {
189
210
  const dep = new ImportEagerDependency(
190
211
  param.string,
@@ -215,21 +236,6 @@ class ImportParserPlugin {
215
236
  }
216
237
  return true;
217
238
  } else {
218
- if (
219
- mode !== "lazy" &&
220
- mode !== "lazy-once" &&
221
- mode !== "eager" &&
222
- mode !== "weak"
223
- ) {
224
- parser.state.module.addWarning(
225
- new UnsupportedFeatureWarning(
226
- `\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`,
227
- expr.loc
228
- )
229
- );
230
- mode = "lazy";
231
- }
232
-
233
239
  if (mode === "weak") {
234
240
  mode = "async-weak";
235
241
  }
@@ -13,18 +13,21 @@ const NullDependency = require("./NullDependency");
13
13
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14
14
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
15
15
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
16
+ /** @typedef {import("../json/JsonData")} JsonData */
16
17
  /** @typedef {import("../util/Hash")} Hash */
17
18
 
18
19
  const getExportsFromData = data => {
19
20
  if (data && typeof data === "object") {
20
21
  if (Array.isArray(data)) {
21
- return data.map((item, idx) => {
22
- return {
23
- name: `${idx}`,
24
- canMangle: true,
25
- exports: getExportsFromData(item)
26
- };
27
- });
22
+ return data.length < 100
23
+ ? data.map((item, idx) => {
24
+ return {
25
+ name: `${idx}`,
26
+ canMangle: true,
27
+ exports: getExportsFromData(item)
28
+ };
29
+ })
30
+ : undefined;
28
31
  } else {
29
32
  const exports = [];
30
33
  for (const key of Object.keys(data)) {
@@ -42,12 +45,11 @@ const getExportsFromData = data => {
42
45
 
43
46
  class JsonExportsDependency extends NullDependency {
44
47
  /**
45
- * @param {(string | ExportSpec)[]} exports json exports
48
+ * @param {JsonData=} data json data
46
49
  */
47
- constructor(exports) {
50
+ constructor(data) {
48
51
  super();
49
- this.exports = exports;
50
- this._hashUpdate = undefined;
52
+ this.data = data;
51
53
  }
52
54
 
53
55
  get type() {
@@ -61,7 +63,7 @@ class JsonExportsDependency extends NullDependency {
61
63
  */
62
64
  getExports(moduleGraph) {
63
65
  return {
64
- exports: this.exports,
66
+ exports: getExportsFromData(this.data && this.data.get()),
65
67
  dependencies: undefined
66
68
  };
67
69
  }
@@ -73,23 +75,18 @@ class JsonExportsDependency extends NullDependency {
73
75
  * @returns {void}
74
76
  */
75
77
  updateHash(hash, context) {
76
- if (this._hashUpdate === undefined) {
77
- this._hashUpdate = this.exports
78
- ? JSON.stringify(this.exports)
79
- : "undefined";
80
- }
81
- hash.update(this._hashUpdate);
78
+ this.data.updateHash(hash);
82
79
  }
83
80
 
84
81
  serialize(context) {
85
82
  const { write } = context;
86
- write(this.exports);
83
+ write(this.data);
87
84
  super.serialize(context);
88
85
  }
89
86
 
90
87
  deserialize(context) {
91
88
  const { read } = context;
92
- this.exports = read();
89
+ this.data = read();
93
90
  super.deserialize(context);
94
91
  }
95
92
  }
@@ -100,4 +97,3 @@ makeSerializable(
100
97
  );
101
98
 
102
99
  module.exports = JsonExportsDependency;
103
- module.exports.getExportsFromData = getExportsFromData;
@@ -7,6 +7,11 @@
7
7
 
8
8
  const ModuleDependency = require("./ModuleDependency");
9
9
 
10
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
11
+ /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
12
+ /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
13
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
14
+
10
15
  class LoaderDependency extends ModuleDependency {
11
16
  /**
12
17
  * @param {string} request request string
@@ -22,6 +27,14 @@ class LoaderDependency extends ModuleDependency {
22
27
  get category() {
23
28
  return "loader";
24
29
  }
30
+
31
+ /**
32
+ * @param {ModuleGraph} moduleGraph module graph
33
+ * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
34
+ */
35
+ getCondition(moduleGraph) {
36
+ return false;
37
+ }
25
38
  }
26
39
 
27
40
  module.exports = LoaderDependency;
@@ -7,6 +7,11 @@
7
7
 
8
8
  const ModuleDependency = require("./ModuleDependency");
9
9
 
10
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
11
+ /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
12
+ /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
13
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
14
+
10
15
  class LoaderImportDependency extends ModuleDependency {
11
16
  /**
12
17
  * @param {string} request request string
@@ -23,6 +28,14 @@ class LoaderImportDependency extends ModuleDependency {
23
28
  get category() {
24
29
  return "loaderImport";
25
30
  }
31
+
32
+ /**
33
+ * @param {ModuleGraph} moduleGraph module graph
34
+ * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
35
+ */
36
+ getCondition(moduleGraph) {
37
+ return false;
38
+ }
26
39
  }
27
40
 
28
41
  module.exports = LoaderImportDependency;
@@ -16,7 +16,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
16
16
 
17
17
  /**
18
18
  * @callback LoadModuleCallback
19
- * @param {Error=} err error object
19
+ * @param {(Error | null)=} err error object
20
20
  * @param {string | Buffer=} source source code
21
21
  * @param {object=} map source map
22
22
  * @param {Module=} module loaded module if successful
@@ -24,7 +24,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
24
24
 
25
25
  /**
26
26
  * @callback ImportModuleCallback
27
- * @param {Error=} err error object
27
+ * @param {(Error | null)=} err error object
28
28
  * @param {any=} exports exports of the evaluated module
29
29
  */
30
30
 
@@ -32,6 +32,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
32
32
  * @typedef {Object} ImportModuleOptions
33
33
  * @property {string=} layer the target layer
34
34
  * @property {string=} publicPath the target public path
35
+ * @property {string=} baseUri target base uri
35
36
  */
36
37
 
37
38
  class LoaderPlugin {
@@ -199,6 +200,7 @@ class LoaderPlugin {
199
200
  referencedModule,
200
201
  {
201
202
  entryOptions: {
203
+ baseUri: options.baseUri,
202
204
  publicPath: options.publicPath
203
205
  }
204
206
  },
@@ -26,13 +26,21 @@ class ModuleDependency extends Dependency {
26
26
  // assertions must be serialized by subclasses that use it
27
27
  /** @type {Record<string, any> | undefined} */
28
28
  this.assertions = undefined;
29
+ this._context = undefined;
30
+ }
31
+
32
+ /**
33
+ * @returns {string | undefined} a request context
34
+ */
35
+ getContext() {
36
+ return this._context;
29
37
  }
30
38
 
31
39
  /**
32
40
  * @returns {string | null} an identifier to merge equal requests
33
41
  */
34
42
  getResourceIdentifier() {
35
- let str = `module${this.request}`;
43
+ let str = `context${this._context || ""}|module${this.request}`;
36
44
  if (this.assertions !== undefined) {
37
45
  str += JSON.stringify(this.assertions);
38
46
  }
@@ -63,6 +71,7 @@ class ModuleDependency extends Dependency {
63
71
  const { write } = context;
64
72
  write(this.request);
65
73
  write(this.userRequest);
74
+ write(this._context);
66
75
  write(this.range);
67
76
  super.serialize(context);
68
77
  }
@@ -71,6 +80,7 @@ class ModuleDependency extends Dependency {
71
80
  const { read } = context;
72
81
  this.request = read();
73
82
  this.userRequest = read();
83
+ this._context = read();
74
84
  this.range = read();
75
85
  super.deserialize(context);
76
86
  }
@@ -5,19 +5,21 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const Dependency = require("../Dependency");
8
9
  const InitFragment = require("../InitFragment");
9
10
  const makeSerializable = require("../util/makeSerializable");
10
11
  const ModuleDependency = require("./ModuleDependency");
11
12
 
12
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
- /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
15
16
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
16
17
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
17
18
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
18
19
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
20
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
20
21
  /** @typedef {import("../util/Hash")} Hash */
22
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
21
23
 
22
24
  /**
23
25
  * @param {string[]|null} path the property path array
@@ -29,10 +31,16 @@ const pathToString = path =>
29
31
  : "";
30
32
 
31
33
  class ProvidedDependency extends ModuleDependency {
32
- constructor(request, identifier, path, range) {
34
+ /**
35
+ * @param {string} request request
36
+ * @param {string} identifier identifier
37
+ * @param {string[]} ids ids
38
+ * @param {[number, number]} range range
39
+ */
40
+ constructor(request, identifier, ids, range) {
33
41
  super(request);
34
42
  this.identifier = identifier;
35
- this.path = path;
43
+ this.ids = ids;
36
44
  this.range = range;
37
45
  this._hashUpdate = undefined;
38
46
  }
@@ -45,6 +53,18 @@ class ProvidedDependency extends ModuleDependency {
45
53
  return "esm";
46
54
  }
47
55
 
56
+ /**
57
+ * Returns list of exports referenced by this dependency
58
+ * @param {ModuleGraph} moduleGraph module graph
59
+ * @param {RuntimeSpec} runtime the runtime for which the module is analysed
60
+ * @returns {(string[] | ReferencedExport)[]} referenced exports
61
+ */
62
+ getReferencedExports(moduleGraph, runtime) {
63
+ let ids = this.ids;
64
+ if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED;
65
+ return [ids];
66
+ }
67
+
48
68
  /**
49
69
  * Update the hash
50
70
  * @param {Hash} hash hash to be updated
@@ -53,8 +73,7 @@ class ProvidedDependency extends ModuleDependency {
53
73
  */
54
74
  updateHash(hash, context) {
55
75
  if (this._hashUpdate === undefined) {
56
- this._hashUpdate =
57
- this.identifier + (this.path ? this.path.join(",") : "null");
76
+ this._hashUpdate = this.identifier + (this.ids ? this.ids.join(",") : "");
58
77
  }
59
78
  hash.update(this._hashUpdate);
60
79
  }
@@ -62,14 +81,14 @@ class ProvidedDependency extends ModuleDependency {
62
81
  serialize(context) {
63
82
  const { write } = context;
64
83
  write(this.identifier);
65
- write(this.path);
84
+ write(this.ids);
66
85
  super.serialize(context);
67
86
  }
68
87
 
69
88
  deserialize(context) {
70
89
  const { read } = context;
71
90
  this.identifier = read();
72
- this.path = read();
91
+ this.ids = read();
73
92
  super.deserialize(context);
74
93
  }
75
94
  }
@@ -90,6 +109,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
90
109
  dependency,
91
110
  source,
92
111
  {
112
+ runtime,
93
113
  runtimeTemplate,
94
114
  moduleGraph,
95
115
  chunkGraph,
@@ -98,6 +118,9 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
98
118
  }
99
119
  ) {
100
120
  const dep = /** @type {ProvidedDependency} */ (dependency);
121
+ const connection = moduleGraph.getConnection(dep);
122
+ const exportsInfo = moduleGraph.getExportsInfo(connection.module);
123
+ const usedName = exportsInfo.getUsedName(dep.ids, runtime);
101
124
  initFragments.push(
102
125
  new InitFragment(
103
126
  `/* provided dependency */ var ${
@@ -107,7 +130,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
107
130
  chunkGraph,
108
131
  request: dep.request,
109
132
  runtimeRequirements
110
- })}${pathToString(dep.path)};\n`,
133
+ })}${pathToString(/** @type {string[]} */ (usedName))};\n`,
111
134
  InitFragment.STAGE_PROVIDES,
112
135
  1,
113
136
  `provided ${dep.identifier}`
@@ -19,22 +19,6 @@ class RequireContextDependency extends ContextDependency {
19
19
  get type() {
20
20
  return "require.context";
21
21
  }
22
-
23
- serialize(context) {
24
- const { write } = context;
25
-
26
- write(this.range);
27
-
28
- super.serialize(context);
29
- }
30
-
31
- deserialize(context) {
32
- const { read } = context;
33
-
34
- this.range = read();
35
-
36
- super.deserialize(context);
37
- }
38
22
  }
39
23
 
40
24
  makeSerializable(
@@ -85,14 +85,14 @@ RequireEnsureDependency.Template = class RequireEnsureDependencyTemplate extends
85
85
  source.replace(
86
86
  contentRange[1],
87
87
  errorHandlerRange[0] - 1,
88
- ").bind(null, __webpack_require__)).catch("
88
+ ").bind(null, __webpack_require__))['catch']("
89
89
  );
90
90
  source.replace(errorHandlerRange[1], range[1] - 1, ")");
91
91
  } else {
92
92
  source.replace(
93
93
  contentRange[1],
94
94
  range[1] - 1,
95
- `).bind(null, __webpack_require__)).catch(${RuntimeGlobals.uncaughtErrorHandler})`
95
+ `).bind(null, __webpack_require__))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`
96
96
  );
97
97
  }
98
98
  }
@@ -10,8 +10,8 @@ const ContextDependency = require("./ContextDependency");
10
10
  const ContextDependencyTemplateAsId = require("./ContextDependencyTemplateAsId");
11
11
 
12
12
  class RequireResolveContextDependency extends ContextDependency {
13
- constructor(options, range, valueRange) {
14
- super(options);
13
+ constructor(options, range, valueRange, context) {
14
+ super(options, context);
15
15
 
16
16
  this.range = range;
17
17
  this.valueRange = valueRange;
@@ -15,10 +15,11 @@ const ModuleDependencyAsId = require("./ModuleDependencyTemplateAsId");
15
15
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
16
16
 
17
17
  class RequireResolveDependency extends ModuleDependency {
18
- constructor(request, range) {
18
+ constructor(request, range, context) {
19
19
  super(request);
20
20
 
21
21
  this.range = range;
22
+ this._context = context;
22
23
  }
23
24
 
24
25
  get type() {
@@ -25,7 +25,7 @@ const ModuleDependency = require("./ModuleDependency");
25
25
  /** @typedef {import("../util/Hash")} Hash */
26
26
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
27
27
 
28
- const getRawModule = memoize(() => require("../RawModule"));
28
+ const getRawDataUrlModule = memoize(() => require("../asset/RawDataUrlModule"));
29
29
 
30
30
  class URLDependency extends ModuleDependency {
31
31
  /**
@@ -68,13 +68,8 @@ class URLDependency extends ModuleDependency {
68
68
  * @returns {Module} a module
69
69
  */
70
70
  createIgnoredModule(context) {
71
- const RawModule = getRawModule();
72
- return new RawModule(
73
- 'module.exports = "data:,";',
74
- `ignored-asset`,
75
- `(ignored asset)`,
76
- new Set([RuntimeGlobals.module])
77
- );
71
+ const RawDataUrlModule = getRawDataUrlModule();
72
+ return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
78
73
  }
79
74
 
80
75
  serialize(context) {
@@ -5,12 +5,15 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { pathToFileURL } = require("url");
9
+ const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
8
10
  const { approve } = require("../javascript/JavascriptParserHelpers");
9
11
  const InnerGraph = require("../optimize/InnerGraph");
10
12
  const URLDependency = require("./URLDependency");
11
13
 
12
14
  /** @typedef {import("estree").NewExpression} NewExpressionNode */
13
15
  /** @typedef {import("../Compiler")} Compiler */
16
+ /** @typedef {import("../NormalModule")} NormalModule */
14
17
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
15
18
 
16
19
  class URLPlugin {
@@ -27,6 +30,13 @@ class URLPlugin {
27
30
  new URLDependency.Template()
28
31
  );
29
32
 
33
+ /**
34
+ * @param {NormalModule} module module
35
+ * @returns {URL} file url
36
+ */
37
+ const getUrl = module => {
38
+ return pathToFileURL(module.resource);
39
+ };
30
40
  /**
31
41
  * @param {JavascriptParser} parser parser
32
42
  * @param {object} parserOptions options
@@ -67,6 +77,17 @@ class URLPlugin {
67
77
  };
68
78
 
69
79
  parser.hooks.canRename.for("URL").tap("URLPlugin", approve);
80
+ parser.hooks.evaluateNewExpression
81
+ .for("URL")
82
+ .tap("URLPlugin", expr => {
83
+ const request = getUrlRequest(expr);
84
+ if (!request) return;
85
+ const url = new URL(request, getUrl(parser.state.module));
86
+
87
+ return new BasicEvaluatedExpression()
88
+ .setString(url.toString())
89
+ .setRange(expr.range);
90
+ });
70
91
  parser.hooks.new.for("URL").tap("URLPlugin", _expr => {
71
92
  const expr = /** @type {NewExpressionNode} */ (_expr);
72
93
 
@@ -82,7 +103,7 @@ class URLPlugin {
82
103
  relative
83
104
  );
84
105
  dep.loc = expr.loc;
85
- parser.state.module.addDependency(dep);
106
+ parser.state.current.addDependency(dep);
86
107
  InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
87
108
  return true;
88
109
  });
@@ -190,8 +190,10 @@ class WorkerPlugin {
190
190
  } = arg2 && arg2.type === "ObjectExpression"
191
191
  ? parseObjectExpression(parser, arg2)
192
192
  : {
193
+ /** @type {Record<string, Expression | Pattern>} */
193
194
  expressions: {},
194
195
  otherElements: [],
196
+ /** @type {Record<string, any>} */
195
197
  values: {},
196
198
  spread: false,
197
199
  insertType: arg2 ? "spread" : "argument",