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
@@ -128,7 +128,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
128
128
  loadersPrefix = "";
129
129
  const idx = request.lastIndexOf("!");
130
130
  if (idx >= 0) {
131
- let loadersRequest = request.substr(0, idx + 1);
131
+ let loadersRequest = request.slice(0, idx + 1);
132
132
  let i;
133
133
  for (
134
134
  i = 0;
@@ -138,7 +138,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
138
138
  loadersPrefix += "!";
139
139
  }
140
140
  loadersRequest = loadersRequest
141
- .substr(i)
141
+ .slice(i)
142
142
  .replace(/!+$/, "")
143
143
  .replace(/!!+/g, "!");
144
144
  if (loadersRequest === "") {
@@ -146,7 +146,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
146
146
  } else {
147
147
  loaders = loadersRequest.split("!");
148
148
  }
149
- resource = request.substr(idx + 1);
149
+ resource = request.slice(idx + 1);
150
150
  } else {
151
151
  loaders = [];
152
152
  resource = request;
@@ -167,6 +167,9 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
167
167
  asyncLib.parallel(
168
168
  [
169
169
  callback => {
170
+ const results = [];
171
+ const yield_ = obj => results.push(obj);
172
+
170
173
  contextResolver.resolve(
171
174
  {},
172
175
  context,
@@ -174,11 +177,12 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
174
177
  {
175
178
  fileDependencies,
176
179
  missingDependencies,
177
- contextDependencies
180
+ contextDependencies,
181
+ yield: yield_
178
182
  },
179
- (err, result) => {
183
+ err => {
180
184
  if (err) return callback(err);
181
- callback(null, result);
185
+ callback(null, results);
182
186
  }
183
187
  );
184
188
  },
@@ -213,15 +217,25 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
213
217
  contextDependencies
214
218
  });
215
219
  }
216
-
220
+ let [contextResult, loaderResult] = result;
221
+ if (contextResult.length > 1) {
222
+ const first = contextResult[0];
223
+ contextResult = contextResult.filter(r => r.path);
224
+ if (contextResult.length === 0) contextResult.push(first);
225
+ }
217
226
  this.hooks.afterResolve.callAsync(
218
227
  {
219
228
  addon:
220
229
  loadersPrefix +
221
- result[1].join("!") +
222
- (result[1].length > 0 ? "!" : ""),
223
- resource: result[0],
230
+ loaderResult.join("!") +
231
+ (loaderResult.length > 0 ? "!" : ""),
232
+ resource:
233
+ contextResult.length > 1
234
+ ? contextResult.map(r => r.path)
235
+ : contextResult[0].path,
224
236
  resolveDependencies: this.resolveDependencies.bind(this),
237
+ resourceQuery: contextResult[0].query,
238
+ resourceFragment: contextResult[0].fragment,
225
239
  ...beforeResolveResult
226
240
  },
227
241
  (err, result) => {
@@ -278,26 +292,27 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
278
292
  } = options;
279
293
  if (!regExp || !resource) return callback(null, []);
280
294
 
281
- const addDirectoryChecked = (directory, visited, callback) => {
295
+ const addDirectoryChecked = (ctx, directory, visited, callback) => {
282
296
  fs.realpath(directory, (err, realPath) => {
283
297
  if (err) return callback(err);
284
298
  if (visited.has(realPath)) return callback(null, []);
285
299
  let recursionStack;
286
300
  addDirectory(
301
+ ctx,
287
302
  directory,
288
- (dir, callback) => {
303
+ (_, dir, callback) => {
289
304
  if (recursionStack === undefined) {
290
305
  recursionStack = new Set(visited);
291
306
  recursionStack.add(realPath);
292
307
  }
293
- addDirectoryChecked(dir, recursionStack, callback);
308
+ addDirectoryChecked(ctx, dir, recursionStack, callback);
294
309
  },
295
310
  callback
296
311
  );
297
312
  });
298
313
  };
299
314
 
300
- const addDirectory = (directory, addSubDirectory, callback) => {
315
+ const addDirectory = (ctx, directory, addSubDirectory, callback) => {
301
316
  fs.readdir(directory, (err, files) => {
302
317
  if (err) return callback(err);
303
318
  const processedFiles = cmf.hooks.contextModuleFiles.call(
@@ -324,16 +339,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
324
339
 
325
340
  if (stat.isDirectory()) {
326
341
  if (!recursive) return callback();
327
- addSubDirectory(subResource, callback);
342
+ addSubDirectory(ctx, subResource, callback);
328
343
  } else if (
329
344
  stat.isFile() &&
330
345
  (!include || subResource.match(include))
331
346
  ) {
332
347
  const obj = {
333
- context: resource,
348
+ context: ctx,
334
349
  request:
335
- "." +
336
- subResource.substr(resource.length).replace(/\\/g, "/")
350
+ "." + subResource.slice(ctx.length).replace(/\\/g, "/")
337
351
  };
338
352
 
339
353
  this.hooks.alternativeRequests.callAsync(
@@ -345,11 +359,12 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
345
359
  .filter(obj => regExp.test(obj.request))
346
360
  .map(obj => {
347
361
  const dep = new ContextElementDependency(
348
- obj.request + resourceQuery + resourceFragment,
362
+ `${obj.request}${resourceQuery}${resourceFragment}`,
349
363
  obj.request,
350
364
  typePrefix,
351
365
  category,
352
- referencedExports
366
+ referencedExports,
367
+ obj.context
353
368
  );
354
369
  dep.optional = true;
355
370
  return dep;
@@ -382,12 +397,37 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
382
397
  });
383
398
  };
384
399
 
385
- if (typeof fs.realpath === "function") {
386
- addDirectoryChecked(resource, new Set(), callback);
400
+ const addSubDirectory = (ctx, dir, callback) =>
401
+ addDirectory(ctx, dir, addSubDirectory, callback);
402
+
403
+ const visitResource = (resource, callback) => {
404
+ if (typeof fs.realpath === "function") {
405
+ addDirectoryChecked(resource, resource, new Set(), callback);
406
+ } else {
407
+ addDirectory(resource, resource, addSubDirectory, callback);
408
+ }
409
+ };
410
+
411
+ if (typeof resource === "string") {
412
+ visitResource(resource, callback);
387
413
  } else {
388
- const addSubDirectory = (dir, callback) =>
389
- addDirectory(dir, addSubDirectory, callback);
390
- addDirectory(resource, addSubDirectory, callback);
414
+ asyncLib.map(resource, visitResource, (err, result) => {
415
+ if (err) return callback(err);
416
+
417
+ // result dependencies should have unique userRequest
418
+ // ordered by resolve result
419
+ const temp = new Set();
420
+ const res = [];
421
+ for (let i = 0; i < result.length; i++) {
422
+ const inner = result[i];
423
+ for (const el of inner) {
424
+ if (temp.has(el.userRequest)) continue;
425
+ res.push(el);
426
+ temp.add(el.userRequest);
427
+ }
428
+ }
429
+ callback(null, res);
430
+ });
391
431
  }
392
432
  }
393
433
  };
@@ -91,7 +91,7 @@ class DelegatedModule extends Module {
91
91
 
92
92
  /**
93
93
  * @param {NeedBuildContext} context context info
94
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
94
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
95
95
  * @returns {void}
96
96
  */
97
97
  needBuild(context, callback) {
@@ -29,7 +29,7 @@ class DelegatedModuleFactoryPlugin {
29
29
  const [dependency] = data.dependencies;
30
30
  const { request } = dependency;
31
31
  if (request && request.startsWith(`${scope}/`)) {
32
- const innerRequest = "." + request.substr(scope.length);
32
+ const innerRequest = "." + request.slice(scope.length);
33
33
  let resolved;
34
34
  if (innerRequest in this.options.content) {
35
35
  resolved = this.options.content[innerRequest];
package/lib/Dependency.js CHANGED
@@ -172,6 +172,23 @@ class Dependency {
172
172
  this._loc = loc;
173
173
  }
174
174
 
175
+ setLoc(startLine, startColumn, endLine, endColumn) {
176
+ this._locSL = startLine;
177
+ this._locSC = startColumn;
178
+ this._locEL = endLine;
179
+ this._locEC = endColumn;
180
+ this._locI = undefined;
181
+ this._locN = undefined;
182
+ this._loc = undefined;
183
+ }
184
+
185
+ /**
186
+ * @returns {string | undefined} a request context
187
+ */
188
+ getContext() {
189
+ return undefined;
190
+ }
191
+
175
192
  /**
176
193
  * @returns {string | null} an identifier to merge equal requests
177
194
  */
@@ -7,6 +7,7 @@
7
7
 
8
8
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
9
9
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
10
+ /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
10
11
  /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
11
12
  /** @typedef {import("./Dependency")} Dependency */
12
13
  /** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
@@ -28,8 +29,16 @@
28
29
  * @property {RuntimeSpec} runtime current runtimes, for which code is generated
29
30
  * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
30
31
  * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
32
+ * @property {CodeGenerationResults} codeGenerationResults the code generation results
31
33
  */
32
34
 
35
+ /**
36
+ * @typedef {Object} CssDependencyTemplateContextExtras
37
+ * @property {Map<string, string>} cssExports the css exports
38
+ */
39
+
40
+ /** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
41
+
33
42
  class DependencyTemplate {
34
43
  /* istanbul ignore next */
35
44
  /**
@@ -57,7 +57,7 @@ class DependencyTemplates {
57
57
  }
58
58
 
59
59
  clone() {
60
- const newInstance = new DependencyTemplates();
60
+ const newInstance = new DependencyTemplates(this._hashFunction);
61
61
  newInstance._map = new Map(this._map);
62
62
  newInstance._hash = this._hash;
63
63
  return newInstance;
package/lib/DllModule.js CHANGED
@@ -96,7 +96,7 @@ class DllModule extends Module {
96
96
 
97
97
  /**
98
98
  * @param {NeedBuildContext} context context info
99
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
99
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
100
100
  * @returns {void}
101
101
  */
102
102
  needBuild(context, callback) {
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const parseJson = require("json-parse-better-errors");
8
+ const parseJson = require("json-parse-even-better-errors");
9
9
  const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
10
10
  const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
11
11
  const WebpackError = require("./WebpackError");
@@ -62,8 +62,10 @@ class EntryOptionPlugin {
62
62
  runtime: desc.runtime,
63
63
  layer: desc.layer,
64
64
  dependOn: desc.dependOn,
65
+ baseUri: desc.baseUri,
65
66
  publicPath: desc.publicPath,
66
67
  chunkLoading: desc.chunkLoading,
68
+ asyncChunks: desc.asyncChunks,
67
69
  wasmLoading: desc.wasmLoading,
68
70
  library: desc.library
69
71
  };
@@ -43,8 +43,8 @@ exports.cutOffMessage = (stack, message) => {
43
43
  if (nextLine === -1) {
44
44
  return stack === message ? "" : stack;
45
45
  } else {
46
- const firstLine = stack.substr(0, nextLine);
47
- return firstLine === message ? stack.substr(nextLine + 1) : stack;
46
+ const firstLine = stack.slice(0, nextLine);
47
+ return firstLine === message ? stack.slice(nextLine + 1) : stack;
48
48
  }
49
49
  };
50
50
 
@@ -8,6 +8,7 @@
8
8
  const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ExternalModule = require("./ExternalModule");
10
10
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
11
+ const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
@@ -77,7 +78,13 @@ class EvalDevToolModulePlugin {
77
78
  .replace(/^\//, "")
78
79
  );
79
80
  const result = new RawSource(
80
- `eval(${JSON.stringify(content + footer)});`
81
+ `eval(${
82
+ compilation.outputOptions.trustedTypes
83
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
84
+ content + footer
85
+ )})`
86
+ : JSON.stringify(content + footer)
87
+ });`
81
88
  );
82
89
  cache.set(source, result);
83
90
  return result;
@@ -95,6 +102,14 @@ class EvalDevToolModulePlugin {
95
102
  hash.update("EvalDevToolModulePlugin");
96
103
  hash.update("2");
97
104
  });
105
+ if (compilation.outputOptions.trustedTypes) {
106
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
107
+ "EvalDevToolModulePlugin",
108
+ (module, set, context) => {
109
+ set.add(RuntimeGlobals.createScript);
110
+ }
111
+ );
112
+ }
98
113
  });
99
114
  }
100
115
  }
@@ -8,6 +8,7 @@
8
8
  const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
10
  const NormalModule = require("./NormalModule");
11
+ const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
12
13
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
13
14
  const ConcatenatedModule = require("./optimize/ConcatenatedModule");
@@ -17,6 +18,7 @@ const { makePathsAbsolute } = require("./util/identifier");
17
18
  /** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */
18
19
  /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
19
20
  /** @typedef {import("./Compiler")} Compiler */
21
+ /** @typedef {import("./NormalModule").SourceMap} SourceMap */
20
22
 
21
23
  /** @type {WeakMap<Source, Source>} */
22
24
  const cache = new WeakMap();
@@ -104,15 +106,15 @@ class EvalSourceMapDevToolPlugin {
104
106
  return result(source);
105
107
  }
106
108
 
107
- /** @type {{ [key: string]: TODO; }} */
109
+ /** @type {SourceMap} */
108
110
  let sourceMap;
109
111
  let content;
110
112
  if (source.sourceAndMap) {
111
113
  const sourceAndMap = source.sourceAndMap(options);
112
- sourceMap = sourceAndMap.map;
114
+ sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
113
115
  content = sourceAndMap.source;
114
116
  } else {
115
- sourceMap = source.map(options);
117
+ sourceMap = /** @type {SourceMap} */ (source.map(options));
116
118
  content = source.source();
117
119
  }
118
120
  if (!sourceMap) {
@@ -151,6 +153,9 @@ class EvalSourceMapDevToolPlugin {
151
153
  }
152
154
  );
153
155
  sourceMap.sources = moduleFilenames;
156
+ if (options.noSources) {
157
+ sourceMap.sourcesContent = undefined;
158
+ }
154
159
  sourceMap.sourceRoot = options.sourceRoot || "";
155
160
  const moduleId = chunkGraph.getModuleId(m);
156
161
  sourceMap.file = `${moduleId}.js`;
@@ -165,7 +170,15 @@ class EvalSourceMapDevToolPlugin {
165
170
  ) + `\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
166
171
 
167
172
  return result(
168
- new RawSource(`eval(${JSON.stringify(content + footer)});`)
173
+ new RawSource(
174
+ `eval(${
175
+ compilation.outputOptions.trustedTypes
176
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
177
+ content + footer
178
+ )})`
179
+ : JSON.stringify(content + footer)
180
+ });`
181
+ )
169
182
  );
170
183
  }
171
184
  );
@@ -181,6 +194,14 @@ class EvalSourceMapDevToolPlugin {
181
194
  hash.update("EvalSourceMapDevToolPlugin");
182
195
  hash.update("2");
183
196
  });
197
+ if (compilation.outputOptions.trustedTypes) {
198
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
199
+ "EvalSourceMapDevToolPlugin",
200
+ (module, set, context) => {
201
+ set.add(RuntimeGlobals.createScript);
202
+ }
203
+ );
204
+ }
184
205
  }
185
206
  );
186
207
  }
@@ -291,15 +291,15 @@ class ExportsInfo {
291
291
  }
292
292
  }
293
293
  for (const exportInfo of this._exports.values()) {
294
+ if (!canMangle && exportInfo.canMangleProvide !== false) {
295
+ exportInfo.canMangleProvide = false;
296
+ changed = true;
297
+ }
294
298
  if (excludeExports && excludeExports.has(exportInfo.name)) continue;
295
299
  if (exportInfo.provided !== true && exportInfo.provided !== null) {
296
300
  exportInfo.provided = null;
297
301
  changed = true;
298
302
  }
299
- if (!canMangle && exportInfo.canMangleProvide !== false) {
300
- exportInfo.canMangleProvide = false;
301
- changed = true;
302
- }
303
303
  if (targetKey) {
304
304
  exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
305
305
  }
@@ -584,7 +584,7 @@ class ExportsInfo {
584
584
  if (info.exportsInfo && name.length > 1) {
585
585
  return info.exportsInfo.isExportProvided(name.slice(1));
586
586
  }
587
- return info.provided;
587
+ return info.provided ? name.length === 1 || undefined : info.provided;
588
588
  }
589
589
  const info = this.getReadOnlyExportInfo(name);
590
590
  return info.provided;
@@ -53,6 +53,7 @@ const { register } = require("./util/serialization");
53
53
  */
54
54
 
55
55
  const TYPES = new Set(["javascript"]);
56
+ const CSS_TYPES = new Set(["css-import"]);
56
57
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
57
58
  const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
58
59
  const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
@@ -392,7 +393,7 @@ class ExternalModule extends Module {
392
393
  * @returns {Set<string>} types available (do not mutate)
393
394
  */
394
395
  getSourceTypes() {
395
- return TYPES;
396
+ return this.externalType === "css-import" ? CSS_TYPES : TYPES;
396
397
  }
397
398
 
398
399
  /**
@@ -409,7 +410,9 @@ class ExternalModule extends Module {
409
410
  * @returns {boolean} true, if the chunk is ok for the module
410
411
  */
411
412
  chunkCondition(chunk, { chunkGraph }) {
412
- return chunkGraph.getNumberOfEntryModules(chunk) > 0;
413
+ return this.externalType === "css-import"
414
+ ? true
415
+ : chunkGraph.getNumberOfEntryModules(chunk) > 0;
413
416
  }
414
417
 
415
418
  /**
@@ -429,7 +432,7 @@ class ExternalModule extends Module {
429
432
 
430
433
  /**
431
434
  * @param {NeedBuildContext} context context info
432
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
435
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
433
436
  * @returns {void}
434
437
  */
435
438
  needBuild(context, callback) {
@@ -526,8 +529,14 @@ class ExternalModule extends Module {
526
529
  return { request, externalType };
527
530
  }
528
531
 
529
- _getSourceData(runtimeTemplate, moduleGraph, chunkGraph, runtime) {
530
- const { request, externalType } = this._getRequestAndExternalType();
532
+ _getSourceData(
533
+ request,
534
+ externalType,
535
+ runtimeTemplate,
536
+ moduleGraph,
537
+ chunkGraph,
538
+ runtime
539
+ ) {
531
540
  switch (externalType) {
532
541
  case "this":
533
542
  case "window":
@@ -536,11 +545,12 @@ class ExternalModule extends Module {
536
545
  case "global":
537
546
  return getSourceForGlobalVariableExternal(
538
547
  request,
539
- runtimeTemplate.outputOptions.globalObject
548
+ runtimeTemplate.globalObject
540
549
  );
541
550
  case "commonjs":
542
551
  case "commonjs2":
543
552
  case "commonjs-module":
553
+ case "commonjs-static":
544
554
  return getSourceForCommonJsExternal(request);
545
555
  case "node-commonjs":
546
556
  return this.buildInfo.module
@@ -613,60 +623,90 @@ class ExternalModule extends Module {
613
623
  runtime,
614
624
  concatenationScope
615
625
  }) {
616
- const sourceData = this._getSourceData(
617
- runtimeTemplate,
618
- moduleGraph,
619
- chunkGraph,
620
- runtime
621
- );
626
+ const { request, externalType } = this._getRequestAndExternalType();
627
+ switch (externalType) {
628
+ case "asset": {
629
+ const sources = new Map();
630
+ sources.set(
631
+ "javascript",
632
+ new RawSource(`module.exports = ${JSON.stringify(request)};`)
633
+ );
634
+ const data = new Map();
635
+ data.set("url", request);
636
+ return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
637
+ }
638
+ case "css-import": {
639
+ const sources = new Map();
640
+ sources.set(
641
+ "css-import",
642
+ new RawSource(`@import url(${JSON.stringify(request)});`)
643
+ );
644
+ return {
645
+ sources,
646
+ runtimeRequirements: EMPTY_RUNTIME_REQUIREMENTS
647
+ };
648
+ }
649
+ default: {
650
+ const sourceData = this._getSourceData(
651
+ request,
652
+ externalType,
653
+ runtimeTemplate,
654
+ moduleGraph,
655
+ chunkGraph,
656
+ runtime
657
+ );
622
658
 
623
- let sourceString = sourceData.expression;
624
- if (sourceData.iife)
625
- sourceString = `(function() { return ${sourceString}; }())`;
626
- if (concatenationScope) {
627
- sourceString = `${runtimeTemplate.supportsConst() ? "const" : "var"} ${
628
- ConcatenationScope.NAMESPACE_OBJECT_EXPORT
629
- } = ${sourceString};`;
630
- concatenationScope.registerNamespaceExport(
631
- ConcatenationScope.NAMESPACE_OBJECT_EXPORT
632
- );
633
- } else {
634
- sourceString = `module.exports = ${sourceString};`;
635
- }
636
- if (sourceData.init) sourceString = `${sourceData.init}\n${sourceString}`;
659
+ let sourceString = sourceData.expression;
660
+ if (sourceData.iife)
661
+ sourceString = `(function() { return ${sourceString}; }())`;
662
+ if (concatenationScope) {
663
+ sourceString = `${
664
+ runtimeTemplate.supportsConst() ? "const" : "var"
665
+ } ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
666
+ concatenationScope.registerNamespaceExport(
667
+ ConcatenationScope.NAMESPACE_OBJECT_EXPORT
668
+ );
669
+ } else {
670
+ sourceString = `module.exports = ${sourceString};`;
671
+ }
672
+ if (sourceData.init)
673
+ sourceString = `${sourceData.init}\n${sourceString}`;
637
674
 
638
- let data = undefined;
639
- if (sourceData.chunkInitFragments) {
640
- data = new Map();
641
- data.set("chunkInitFragments", sourceData.chunkInitFragments);
642
- }
675
+ let data = undefined;
676
+ if (sourceData.chunkInitFragments) {
677
+ data = new Map();
678
+ data.set("chunkInitFragments", sourceData.chunkInitFragments);
679
+ }
643
680
 
644
- const sources = new Map();
645
- if (this.useSourceMap || this.useSimpleSourceMap) {
646
- sources.set(
647
- "javascript",
648
- new OriginalSource(sourceString, this.identifier())
649
- );
650
- } else {
651
- sources.set("javascript", new RawSource(sourceString));
652
- }
681
+ const sources = new Map();
682
+ if (this.useSourceMap || this.useSimpleSourceMap) {
683
+ sources.set(
684
+ "javascript",
685
+ new OriginalSource(sourceString, this.identifier())
686
+ );
687
+ } else {
688
+ sources.set("javascript", new RawSource(sourceString));
689
+ }
690
+
691
+ let runtimeRequirements = sourceData.runtimeRequirements;
692
+ if (!concatenationScope) {
693
+ if (!runtimeRequirements) {
694
+ runtimeRequirements = RUNTIME_REQUIREMENTS;
695
+ } else {
696
+ const set = new Set(runtimeRequirements);
697
+ set.add(RuntimeGlobals.module);
698
+ runtimeRequirements = set;
699
+ }
700
+ }
653
701
 
654
- let runtimeRequirements = sourceData.runtimeRequirements;
655
- if (!concatenationScope) {
656
- if (!runtimeRequirements) {
657
- runtimeRequirements = RUNTIME_REQUIREMENTS;
658
- } else {
659
- const set = new Set(runtimeRequirements);
660
- set.add(RuntimeGlobals.module);
661
- runtimeRequirements = set;
702
+ return {
703
+ sources,
704
+ runtimeRequirements:
705
+ runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
706
+ data
707
+ };
662
708
  }
663
709
  }
664
-
665
- return {
666
- sources,
667
- runtimeRequirements: runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
668
- data
669
- };
670
710
  }
671
711
 
672
712
  /**