webpack 5.107.0 → 5.107.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/lib/BannerPlugin.js +3 -4
  2. package/lib/Chunk.js +21 -25
  3. package/lib/ChunkGroup.js +57 -15
  4. package/lib/Compilation.js +33 -11
  5. package/lib/Compiler.js +27 -3
  6. package/lib/ContextModuleFactory.js +45 -38
  7. package/lib/EvalSourceMapDevToolPlugin.js +0 -1
  8. package/lib/ExportsInfo.js +30 -34
  9. package/lib/ExternalModule.js +15 -11
  10. package/lib/ExternalModuleFactoryPlugin.js +2 -1
  11. package/lib/Module.js +1 -1
  12. package/lib/ModuleNotFoundError.js +10 -0
  13. package/lib/ModuleSourceTypeConstants.js +24 -22
  14. package/lib/MultiCompiler.js +14 -0
  15. package/lib/NormalModule.js +531 -53
  16. package/lib/NormalModuleFactory.js +38 -26
  17. package/lib/ProgressPlugin.js +1 -1
  18. package/lib/RuntimePlugin.js +1 -1
  19. package/lib/SourceMapDevToolPlugin.js +335 -57
  20. package/lib/Template.js +1 -1
  21. package/lib/TemplatedPathPlugin.js +22 -4
  22. package/lib/asset/AssetBytesGenerator.js +6 -6
  23. package/lib/asset/AssetGenerator.js +14 -14
  24. package/lib/asset/AssetModulesPlugin.js +3 -7
  25. package/lib/asset/AssetSourceGenerator.js +6 -6
  26. package/lib/buildChunkGraph.js +24 -2
  27. package/lib/cache/getLazyHashedEtag.js +9 -2
  28. package/lib/css/CssModulesPlugin.js +2 -2
  29. package/lib/dependencies/CommonJsImportsParserPlugin.js +108 -1
  30. package/lib/dependencies/CssUrlDependency.js +3 -2
  31. package/lib/dependencies/HarmonyDetectionParserPlugin.js +21 -1
  32. package/lib/dependencies/HarmonyExportInitFragment.js +8 -9
  33. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -14
  34. package/lib/dependencies/HtmlInlineStyleDependency.js +17 -0
  35. package/lib/dependencies/HtmlScriptSrcDependency.js +265 -65
  36. package/lib/dependencies/HtmlSourceDependency.js +21 -2
  37. package/lib/dependencies/WorkerPlugin.js +18 -4
  38. package/lib/hmr/LazyCompilationPlugin.js +104 -0
  39. package/lib/html/HtmlGenerator.js +81 -33
  40. package/lib/html/HtmlModulesPlugin.js +87 -28
  41. package/lib/html/walkHtmlTokens.js +641 -125
  42. package/lib/index.js +2 -0
  43. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  44. package/lib/javascript/JavascriptParser.js +1 -1
  45. package/lib/library/ModuleLibraryPlugin.js +30 -24
  46. package/lib/node/NodeWatchFileSystem.js +37 -22
  47. package/lib/optimize/ConcatenatedModule.js +3 -2
  48. package/lib/optimize/SideEffectsFlagPlugin.js +1 -2
  49. package/lib/optimize/SplitChunksPlugin.js +4 -4
  50. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -3
  51. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -5
  52. package/lib/sharing/ConsumeSharedPlugin.js +2 -8
  53. package/lib/sharing/ProvideSharedPlugin.js +4 -4
  54. package/lib/util/fs.js +6 -1
  55. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -2
  56. package/package.json +5 -5
  57. package/schemas/WebpackOptions.check.js +1 -1
  58. package/schemas/WebpackOptions.json +11 -9
  59. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  60. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  61. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  62. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  63. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  64. package/types.d.ts +472 -149
@@ -13,10 +13,9 @@ const Template = require("./Template");
13
13
  /** @typedef {import("webpack-sources").Source} Source */
14
14
  /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
15
15
  /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
16
- /** @typedef {import("./Compilation").PathData} PathData */
16
+ /** @typedef {import("./Compilation").PathDataChunk} PathDataChunk */
17
17
  /** @typedef {import("./Compiler")} Compiler */
18
18
  /** @typedef {import("./Chunk")} Chunk */
19
- /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
20
19
 
21
20
  /** @typedef {(data: { hash?: string, chunk: Chunk, filename: string }) => string} BannerFunction */
22
21
 
@@ -117,11 +116,11 @@ class BannerPlugin {
117
116
  continue;
118
117
  }
119
118
 
120
- /** @type {PathData} */
119
+ /** @type {PathDataChunk} */
121
120
  const data = { chunk, filename: file };
122
121
 
123
122
  const comment = compilation.getPath(
124
- /** @type {TemplatePath} */
123
+ /** @type {string | import("./TemplatedPathPlugin").TemplatePathFn<PathDataChunk>} */
125
124
  (banner),
126
125
  data
127
126
  );
package/lib/Chunk.js CHANGED
@@ -26,7 +26,9 @@ const { mergeRuntime } = require("./util/runtime");
26
26
  /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
27
27
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
28
28
  /** @typedef {import("./Module")} Module */
29
- /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
29
+ /** @typedef {import("./Compilation").PathDataChunk} PathDataChunk */
30
+ /** @typedef {import("./TemplatedPathPlugin").TemplatePathFn<PathDataChunk>} ChunkFilenameTemplateFn */
31
+ /** @typedef {string | ChunkFilenameTemplateFn} ChunkFilenameTemplate */
30
32
  /** @typedef {import("./util/Hash")} Hash */
31
33
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
32
34
 
@@ -98,9 +100,9 @@ class Chunk {
98
100
  this.idNameHints = new SortableSet();
99
101
  /** @type {boolean} */
100
102
  this.preventIntegration = false;
101
- /** @type {TemplatePath | undefined} */
103
+ /** @type {ChunkFilenameTemplate | undefined} */
102
104
  this.filenameTemplate = undefined;
103
- /** @type {TemplatePath | undefined} */
105
+ /** @type {ChunkFilenameTemplate | undefined} */
104
106
  this.cssFilenameTemplate = undefined;
105
107
  /**
106
108
  * @private
@@ -792,26 +794,21 @@ class Chunk {
792
794
  for (const group of this.groupsIterable) {
793
795
  if (group.chunks[group.chunks.length - 1] === this) {
794
796
  for (const childGroup of group.childrenIterable) {
795
- for (const key of Object.keys(childGroup.options)) {
796
- if (key.endsWith("Order")) {
797
- const name = key.slice(0, key.length - "Order".length);
798
- let list = lists.get(name);
799
- if (list === undefined) {
800
- list = [];
801
- lists.set(name, list);
802
- }
803
- list.push({
804
- order:
805
- /** @type {number} */
806
- (
807
- childGroup.options[
808
- /** @type {keyof ChunkGroupOptions} */
809
- (key)
810
- ]
811
- ),
812
- group: childGroup
813
- });
797
+ const edgeOptions = group.getChildOrderOptions(
798
+ childGroup,
799
+ chunkGraph
800
+ );
801
+ for (const key of Object.keys(edgeOptions)) {
802
+ const name = key.slice(0, key.length - "Order".length);
803
+ let list = lists.get(name);
804
+ if (list === undefined) {
805
+ list = [];
806
+ lists.set(name, list);
814
807
  }
808
+ list.push({
809
+ order: edgeOptions[key],
810
+ group: childGroup
811
+ });
815
812
  }
816
813
  }
817
814
  }
@@ -850,9 +847,8 @@ class Chunk {
850
847
  const list = [];
851
848
  for (const group of this.groupsIterable) {
852
849
  for (const childGroup of group.childrenIterable) {
853
- const order =
854
- /** @type {number} */
855
- (childGroup.options[/** @type {keyof ChunkGroupOptions} */ (type)]);
850
+ const edgeOptions = group.getChildOrderOptions(childGroup, chunkGraph);
851
+ const order = edgeOptions[type];
856
852
  if (order === undefined) continue;
857
853
  list.push({
858
854
  order,
package/lib/ChunkGroup.js CHANGED
@@ -544,6 +544,53 @@ class ChunkGroup {
544
544
  );
545
545
  }
546
546
 
547
+ /**
548
+ * Aggregates per-block `*Order` options for the blocks that bridge this
549
+ * chunk group to the given child chunk group. `*Order` options are tied to
550
+ * the originating `import()` call and must not be sourced from the child's
551
+ * shared options, otherwise a webpackPrefetch/Preload directive from one
552
+ * parent would leak into other parents that share the child by name.
553
+ * @param {ChunkGroup} childGroup the child chunk group
554
+ * @param {ChunkGraph} chunkGraph the chunk graph
555
+ * @returns {Record<string, number>} merged `*Order` options for the edge from this group to `childGroup`
556
+ */
557
+ getChildOrderOptions(childGroup, chunkGraph) {
558
+ /** @type {Record<string, number>} */
559
+ const result = Object.create(null);
560
+ let bridged = false;
561
+ for (const block of childGroup.blocksIterable) {
562
+ const rootModule = /** @type {Module} */ (block.getRootBlock());
563
+ if (!chunkGraph.isModuleInChunkGroup(rootModule, this)) continue;
564
+ bridged = true;
565
+ const opts = block.groupOptions;
566
+ if (!opts) continue;
567
+ for (const key of Object.keys(opts)) {
568
+ if (!key.endsWith("Order")) continue;
569
+ const value =
570
+ /** @type {number} */
571
+ (opts[/** @type {keyof ChunkGroupOptions} */ (key)]);
572
+ if (typeof value !== "number") continue;
573
+ if (result[key] === undefined || value > result[key]) {
574
+ result[key] = value;
575
+ }
576
+ }
577
+ }
578
+ // Fall back to the child's own options only when no block bridges
579
+ // this edge (e.g. a chunk group created by APIs that don't go through
580
+ // an AsyncDependenciesBlock). Otherwise we'd reintroduce the leak.
581
+ if (!bridged) {
582
+ for (const key of Object.keys(childGroup.options)) {
583
+ if (!key.endsWith("Order")) continue;
584
+ const value =
585
+ childGroup.options[/** @type {keyof ChunkGroupOptions} */ (key)];
586
+ if (typeof value === "number") {
587
+ result[key] = value;
588
+ }
589
+ }
590
+ }
591
+ return result;
592
+ }
593
+
547
594
  /**
548
595
  * Groups child chunk groups by their `*Order` options and sorts each group
549
596
  * by descending order and deterministic chunk-group comparison.
@@ -555,22 +602,17 @@ class ChunkGroup {
555
602
  /** @type {Map<string, { order: number, group: ChunkGroup }[]>} */
556
603
  const lists = new Map();
557
604
  for (const childGroup of this._children) {
558
- for (const key of Object.keys(childGroup.options)) {
559
- if (key.endsWith("Order")) {
560
- const name = key.slice(0, key.length - "Order".length);
561
- let list = lists.get(name);
562
- if (list === undefined) {
563
- lists.set(name, (list = []));
564
- }
565
- list.push({
566
- order:
567
- /** @type {number} */
568
- (
569
- childGroup.options[/** @type {keyof ChunkGroupOptions} */ (key)]
570
- ),
571
- group: childGroup
572
- });
605
+ const edgeOptions = this.getChildOrderOptions(childGroup, chunkGraph);
606
+ for (const key of Object.keys(edgeOptions)) {
607
+ const name = key.slice(0, key.length - "Order".length);
608
+ let list = lists.get(name);
609
+ if (list === undefined) {
610
+ lists.set(name, (list = []));
573
611
  }
612
+ list.push({
613
+ order: edgeOptions[key],
614
+ group: childGroup
615
+ });
574
616
  }
575
617
  }
576
618
  /** @type {Record<string, ChunkGroup[]>} */
@@ -372,6 +372,24 @@ const { isSourceEqual } = require("./util/source");
372
372
  * @property {PrepareIdFunction=} prepareId
373
373
  */
374
374
 
375
+ /**
376
+ * Path data narrowed for the chunk filename / chunk asset interpolation context,
377
+ * where `chunk` is always provided. Use as the type parameter to `TemplatePathFn`
378
+ * for callbacks that receive a chunk context (for example `output.filename`,
379
+ * `output.chunkFilename`, `output.cssFilename`, `output.cssChunkFilename`,
380
+ * `optimization.splitChunks.cacheGroups[*].filename`).
381
+ * @typedef {PathData & { chunk: Chunk | ChunkPathData }} PathDataChunk
382
+ */
383
+
384
+ /**
385
+ * Path data narrowed for the module asset interpolation context, where `module`
386
+ * and `chunkGraph` are always provided. Use as the type parameter to
387
+ * `TemplatePathFn` for callbacks that receive a module context (for example
388
+ * `output.assetModuleFilename`, the per-module `generator.filename` /
389
+ * `generator.outputPath`, and `module.parser.css.localIdentName`).
390
+ * @typedef {PathData & { module: Module | ModulePathData, chunkGraph: ChunkGraph }} PathDataModule
391
+ */
392
+
375
393
  /** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
376
394
 
377
395
  /**
@@ -5239,7 +5257,7 @@ This prevents using hashes of each other and should be avoided.`);
5239
5257
  );
5240
5258
 
5241
5259
  assetCacheItem.get((err, sourceFromCache) => {
5242
- /** @type {TemplatePath} */
5260
+ /** @type {string | import("./TemplatedPathPlugin").TemplatePathFn<EXPECTED_ANY>} */
5243
5261
  let filenameTemplate;
5244
5262
  /** @type {string} */
5245
5263
  let file;
@@ -5357,11 +5375,12 @@ This prevents using hashes of each other and should be avoided.`);
5357
5375
 
5358
5376
  /**
5359
5377
  * Returns interpolated path.
5360
- * @param {TemplatePath} filename used to get asset path with hash
5361
- * @param {PathData} data context data
5378
+ * @template {PathData} [T=PathData]
5379
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5380
+ * @param {T=} data context data
5362
5381
  * @returns {string} interpolated path
5363
5382
  */
5364
- getPath(filename, data = {}) {
5383
+ getPath(filename, data = /** @type {T} */ ({})) {
5365
5384
  if (!data.hash) {
5366
5385
  data = {
5367
5386
  hash: this.hash,
@@ -5373,11 +5392,12 @@ This prevents using hashes of each other and should be avoided.`);
5373
5392
 
5374
5393
  /**
5375
5394
  * Gets path with info.
5376
- * @param {TemplatePath} filename used to get asset path with hash
5377
- * @param {PathData} data context data
5395
+ * @template {PathData} [T=PathData]
5396
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5397
+ * @param {T=} data context data
5378
5398
  * @returns {InterpolatedPathAndAssetInfo} interpolated path and asset info
5379
5399
  */
5380
- getPathWithInfo(filename, data = {}) {
5400
+ getPathWithInfo(filename, data = /** @type {T} */ ({})) {
5381
5401
  if (!data.hash) {
5382
5402
  data = {
5383
5403
  hash: this.hash,
@@ -5389,8 +5409,9 @@ This prevents using hashes of each other and should be avoided.`);
5389
5409
 
5390
5410
  /**
5391
5411
  * Returns interpolated path.
5392
- * @param {TemplatePath} filename used to get asset path with hash
5393
- * @param {PathData} data context data
5412
+ * @template {PathData} [T=PathData]
5413
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5414
+ * @param {T} data context data
5394
5415
  * @returns {string} interpolated path
5395
5416
  */
5396
5417
  getAssetPath(filename, data) {
@@ -5403,8 +5424,9 @@ This prevents using hashes of each other and should be avoided.`);
5403
5424
 
5404
5425
  /**
5405
5426
  * Gets asset path with info.
5406
- * @param {TemplatePath} filename used to get asset path with hash
5407
- * @param {PathData} data context data
5427
+ * @template {PathData} [T=PathData]
5428
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5429
+ * @param {T} data context data
5408
5430
  * @returns {InterpolatedPathAndAssetInfo} interpolated path and asset info
5409
5431
  */
5410
5432
  getAssetPathWithInfo(filename, data) {
package/lib/Compiler.js CHANGED
@@ -491,6 +491,25 @@ class Compiler {
491
491
  }
492
492
  }
493
493
 
494
+ /**
495
+ * Release fields on a finished compilation that nothing reads after emit,
496
+ * so the heap can shrink while user code still holds the Stats reference.
497
+ * Recurses into child compilations. Stats output is preserved — only
498
+ * codeGen byproducts are dropped.
499
+ * @param {Compilation} compilation finished compilation to slim down
500
+ * @returns {void}
501
+ */
502
+ _releaseUnusedCompilationData(compilation) {
503
+ for (const child of compilation.children) {
504
+ this._releaseUnusedCompilationData(child);
505
+ }
506
+ // Rendered source per (module × runtime) — used only during seal/emit,
507
+ // never read by Stats, and not serialized to the persistent cache.
508
+ if (compilation.codeGenerationResults !== undefined) {
509
+ compilation.codeGenerationResults.map.clear();
510
+ }
511
+ }
512
+
494
513
  /**
495
514
  * Returns a compiler watcher.
496
515
  * @param {WatchOptions} watchOptions the watcher's options
@@ -1439,9 +1458,14 @@ ${other}`);
1439
1458
  }
1440
1459
  this.hooks.shutdown.callAsync((err) => {
1441
1460
  if (err) return callback(err);
1442
- // Get rid of reference to last compilation to avoid leaking memory
1443
- // We can't run this._cleanupLastCompilation() as the Stats to this compilation
1444
- // might be still in use. We try to get rid of the reference to the cache instead.
1461
+ // Defer a microtask so a close() made inside the run callback can't
1462
+ // release codeGenerationResults before afterDone fires on the same stack.
1463
+ const lastCompilation = this._lastCompilation;
1464
+ if (lastCompilation !== undefined) {
1465
+ Promise.resolve().then(() => {
1466
+ this._releaseUnusedCompilationData(lastCompilation);
1467
+ });
1468
+ }
1445
1469
  this._lastCompilation = undefined;
1446
1470
  this._lastNormalModuleFactory = undefined;
1447
1471
  this.cache.shutdown(callback);
@@ -379,6 +379,8 @@ class ContextModuleFactory extends ModuleFactory {
379
379
  if (!processedFiles || processedFiles.length === 0) {
380
380
  return callback(null, []);
381
381
  }
382
+ /** @type {ContextAlternativeRequest[]} */
383
+ const fileObjs = [];
382
384
  asyncLib.map(
383
385
  processedFiles.filter((p) => p.indexOf(".") !== 0),
384
386
  (segment, callback) => {
@@ -404,41 +406,16 @@ class ContextModuleFactory extends ModuleFactory {
404
406
  stat.isFile() &&
405
407
  (!include || include.test(subResource))
406
408
  ) {
407
- /** @type {{ context: string, request: string }} */
408
- const obj = {
409
+ // Collect for a single batched alternativeRequests call
410
+ // per directory below. Calling the hook once per file
411
+ // would pay per-call overhead (closure, resolverFactory
412
+ // lookup, array allocations) for every file in the
413
+ // context — which is the bulk of work on rebuilds.
414
+ fileObjs.push({
409
415
  context: ctx,
410
416
  request: `.${subResource.slice(ctx.length).replace(/\\/g, "/")}`
411
- };
412
-
413
- this.hooks.alternativeRequests.callAsync(
414
- [obj],
415
- options,
416
- (err, alternatives) => {
417
- if (err) return callback(err);
418
- callback(
419
- null,
420
- /** @type {ContextAlternativeRequest[]} */
421
- (alternatives)
422
- .filter((obj) =>
423
- regExp.test(/** @type {string} */ (obj.request))
424
- )
425
- .map((obj) => {
426
- const dep = new ContextElementDependency(
427
- `${obj.request}${resourceQuery}${resourceFragment}`,
428
- obj.request,
429
- typePrefix,
430
- /** @type {string} */
431
- (category),
432
- referencedExports,
433
- obj.context,
434
- attributes
435
- );
436
- dep.optional = true;
437
- return dep;
438
- })
439
- );
440
- }
441
- );
417
+ });
418
+ callback();
442
419
  } else {
443
420
  callback();
444
421
  }
@@ -450,16 +427,46 @@ class ContextModuleFactory extends ModuleFactory {
450
427
  (err, result) => {
451
428
  if (err) return callback(err);
452
429
 
453
- if (!result) return callback(null, []);
454
-
455
430
  /** @type {ContextElementDependency[]} */
456
431
  const flattenedResult = [];
457
432
 
458
- for (const item of result) {
459
- if (item) flattenedResult.push(...item);
433
+ if (result) {
434
+ for (const item of result) {
435
+ if (item) flattenedResult.push(...item);
436
+ }
460
437
  }
461
438
 
462
- callback(null, flattenedResult);
439
+ if (fileObjs.length === 0) {
440
+ return callback(null, flattenedResult);
441
+ }
442
+
443
+ this.hooks.alternativeRequests.callAsync(
444
+ fileObjs,
445
+ options,
446
+ (err, alternatives) => {
447
+ if (err) return callback(err);
448
+ for (const alt of /** @type {ContextAlternativeRequest[]} */ (
449
+ alternatives
450
+ )) {
451
+ if (!regExp.test(/** @type {string} */ (alt.request))) {
452
+ continue;
453
+ }
454
+ const dep = new ContextElementDependency(
455
+ `${alt.request}${resourceQuery}${resourceFragment}`,
456
+ alt.request,
457
+ typePrefix,
458
+ /** @type {string} */
459
+ (category),
460
+ referencedExports,
461
+ alt.context,
462
+ attributes
463
+ );
464
+ dep.optional = true;
465
+ flattenedResult.push(dep);
466
+ }
467
+ callback(null, flattenedResult);
468
+ }
469
+ );
463
470
  }
464
471
  );
465
472
  });
@@ -23,7 +23,6 @@ const { makePathsAbsolute } = require("./util/identifier");
23
23
  /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
24
24
  /** @typedef {import("./Compiler")} Compiler */
25
25
  /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
26
- /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
27
26
 
28
27
  /** @type {WeakMap<Source, Source>} */
29
28
  const cache = new WeakMap();
@@ -114,6 +114,21 @@ class ExportsInfo {
114
114
  constructor() {
115
115
  /** @type {Exports} */
116
116
  this._exports = new Map();
117
+
118
+ // `_otherExportsInfo` is a fallback entry for unlisted exports. Two roles:
119
+ // 1. factory template — `getExportInfo` creates `new ExportInfo(name, this)`,
120
+ // so created export info extends its properties.
121
+ // 2. flags whether the whole exportsInfo can be statically analyzed.
122
+ // Its `used` reachable values:
123
+ // - NoInfo: no use analysis yet (`optimization#usedExports` off), or used without info
124
+ // - Unused: analyzed, no unlisted export needed
125
+ // - Unknown: used in unknown way
126
+ // - Used/OnlyPropertiesUsed: never reached
127
+ // Its `provided` reachable values:
128
+ // - undefined: provision not determined yet
129
+ // - false: determined, no unlisted export is provided
130
+ // - null: only runtime knows (dynamic/unknown exports)
131
+ // - true: never reached
117
132
  /** @type {ExportInfo} */
118
133
  this._otherExportsInfo = new ExportInfo(null);
119
134
  /** @type {ExportInfo} */
@@ -239,22 +254,12 @@ class ExportsInfo {
239
254
 
240
255
  setHasProvideInfo() {
241
256
  for (const exportInfo of this._exports.values()) {
242
- if (exportInfo.provided === undefined) {
243
- exportInfo.provided = false;
244
- }
245
- if (exportInfo.canMangleProvide === undefined) {
246
- exportInfo.canMangleProvide = true;
247
- }
257
+ exportInfo.setHasProvideInfo();
248
258
  }
249
259
  if (this._redirectTo !== undefined) {
250
260
  this._redirectTo.setHasProvideInfo();
251
261
  } else {
252
- if (this._otherExportsInfo.provided === undefined) {
253
- this._otherExportsInfo.provided = false;
254
- }
255
- if (this._otherExportsInfo.canMangleProvide === undefined) {
256
- this._otherExportsInfo.canMangleProvide = true;
257
- }
262
+ this._otherExportsInfo.setHasProvideInfo();
258
263
  }
259
264
  }
260
265
 
@@ -436,20 +441,8 @@ class ExportsInfo {
436
441
  if (this._redirectTo.setUsedInUnknownWay(runtime)) {
437
442
  changed = true;
438
443
  }
439
- } else {
440
- if (
441
- this._otherExportsInfo.setUsedConditionally(
442
- (used) => used < UsageState.Unknown,
443
- UsageState.Unknown,
444
- runtime
445
- )
446
- ) {
447
- changed = true;
448
- }
449
- if (this._otherExportsInfo.canMangleUse !== false) {
450
- this._otherExportsInfo.canMangleUse = false;
451
- changed = true;
452
- }
444
+ } else if (this._otherExportsInfo.setUsedInUnknownWay(runtime)) {
445
+ changed = true;
453
446
  }
454
447
  return changed;
455
448
  }
@@ -470,14 +463,8 @@ class ExportsInfo {
470
463
  if (this._redirectTo.setUsedWithoutInfo(runtime)) {
471
464
  changed = true;
472
465
  }
473
- } else {
474
- if (this._otherExportsInfo.setUsed(UsageState.NoInfo, runtime)) {
475
- changed = true;
476
- }
477
- if (this._otherExportsInfo.canMangleUse !== false) {
478
- this._otherExportsInfo.canMangleUse = false;
479
- changed = true;
480
- }
466
+ } else if (this._otherExportsInfo.setUsedWithoutInfo(runtime)) {
467
+ changed = true;
481
468
  }
482
469
  return changed;
483
470
  }
@@ -1030,6 +1017,15 @@ class ExportInfo {
1030
1017
  return changed;
1031
1018
  }
1032
1019
 
1020
+ setHasProvideInfo() {
1021
+ if (this.provided === undefined) {
1022
+ this.provided = false;
1023
+ }
1024
+ if (this.canMangleProvide === undefined) {
1025
+ this.canMangleProvide = true;
1026
+ }
1027
+ }
1028
+
1033
1029
  setHasUseInfo() {
1034
1030
  if (!this._hasUseInRuntimeInfo) {
1035
1031
  this._hasUseInRuntimeInfo = true;
@@ -12,8 +12,9 @@ const { UsageState } = require("./ExportsInfo");
12
12
  const InitFragment = require("./InitFragment");
13
13
  const Module = require("./Module");
14
14
  const {
15
+ ASSET_URL_TYPE,
16
+ ASSET_URL_TYPES,
15
17
  CSS_IMPORT_TYPES,
16
- CSS_URL_TYPES,
17
18
  JAVASCRIPT_TYPE,
18
19
  JAVASCRIPT_TYPES
19
20
  } = require("./ModuleSourceTypeConstants");
@@ -72,7 +73,7 @@ const { register } = require("./util/serialization");
72
73
 
73
74
  /** @typedef {{ attributes?: ImportAttributes, phase?: ImportPhaseType, externalType: "import" | "module" | undefined }} ImportDependencyMeta */
74
75
  /** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
75
- /** @typedef {{ sourceType: "css-url" }} AssetDependencyMeta */
76
+ /** @typedef {{ sourceType: "asset-url" | "css-url" }} AssetDependencyMeta */
76
77
 
77
78
  /** @typedef {ImportDependencyMeta | CssImportDependencyMeta | AssetDependencyMeta} DependencyMeta */
78
79
 
@@ -736,13 +737,14 @@ class ExternalModule extends Module {
736
737
  * @returns {SourceTypes} types available (do not mutate)
737
738
  */
738
739
  getSourceTypes() {
739
- if (
740
- this.externalType === "asset" &&
741
- this.dependencyMeta &&
742
- /** @type {AssetDependencyMeta} */
743
- (this.dependencyMeta).sourceType === "css-url"
744
- ) {
745
- return CSS_URL_TYPES;
740
+ if (this.externalType === "asset" && this.dependencyMeta) {
741
+ const sourceType =
742
+ /** @type {AssetDependencyMeta} */
743
+ (this.dependencyMeta).sourceType;
744
+ // TODO webpack 6 drop "css-url" once the alias is removed
745
+ if (sourceType === ASSET_URL_TYPE || sourceType === "css-url") {
746
+ return ASSET_URL_TYPES;
747
+ }
746
748
  } else if (this.externalType === "css-import") {
747
749
  return CSS_IMPORT_TYPES;
748
750
  }
@@ -1113,12 +1115,14 @@ class ExternalModule extends Module {
1113
1115
  data.set("url", { javascript: /** @type {string} */ (request) });
1114
1116
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
1115
1117
  }
1116
- case "css-url": {
1118
+ // TODO webpack 6 remove "css-url" alias
1119
+ case "css-url":
1120
+ case "asset-url": {
1117
1121
  /** @type {Sources} */
1118
1122
  const sources = new Map();
1119
1123
  /** @type {CodeGenerationResultData} */
1120
1124
  const data = new Map();
1121
- data.set("url", { "css-url": /** @type {string} */ (request) });
1125
+ data.set("url", { [ASSET_URL_TYPE]: /** @type {string} */ (request) });
1122
1126
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
1123
1127
  }
1124
1128
  case "css-import": {
@@ -7,6 +7,7 @@
7
7
 
8
8
  const util = require("util");
9
9
  const ExternalModule = require("./ExternalModule");
10
+ const { ASSET_URL_TYPE } = require("./ModuleSourceTypeConstants");
10
11
  const ContextElementDependency = require("./dependencies/ContextElementDependency");
11
12
  const CssImportDependency = require("./dependencies/CssImportDependency");
12
13
  const CssUrlDependency = require("./dependencies/CssUrlDependency");
@@ -212,7 +213,7 @@ class ExternalModuleFactoryPlugin {
212
213
  resolvedType === "asset" &&
213
214
  dependency instanceof CssUrlDependency
214
215
  ) {
215
- dependencyMeta = { sourceType: "css-url" };
216
+ dependencyMeta = { sourceType: ASSET_URL_TYPE };
216
217
  }
217
218
 
218
219
  callback(
package/lib/Module.js CHANGED
@@ -119,7 +119,7 @@ const makeSerializable = require("./util/makeSerializable");
119
119
  * @typedef {object} AllCodeGenerationSchemas
120
120
  * @property {Set<string>} topLevelDeclarations top level declarations for javascript modules
121
121
  * @property {InitFragment<EXPECTED_ANY>[]} chunkInitFragments chunk init fragments for javascript modules
122
- * @property {{ javascript?: string, ["css-url"]?: string }} url url for css and javascript modules
122
+ * @property {{ javascript?: string, ["asset-url"]?: string }} url url for asset modules
123
123
  * @property {string} filename a filename for asset modules
124
124
  * @property {AssetInfo} assetInfo an asset info for asset modules
125
125
  * @property {string} fullContentHash a full content hash for asset modules
@@ -0,0 +1,10 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ // TODO remove in webpack 6
9
+ // Some old plugins use `require("webpack/lib/ModuleNotFoundError")`, in webpack@6 developer should migrate to `compiler.webpack.ModuleNotFoundError`
10
+ module.exports = require("./errors/ModuleNotFoundError");