webpack 5.85.0 → 5.86.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 (48) hide show
  1. package/lib/APIPlugin.js +150 -99
  2. package/lib/Chunk.js +35 -17
  3. package/lib/ChunkGroup.js +10 -6
  4. package/lib/Compiler.js +1 -2
  5. package/lib/ContextModule.js +4 -2
  6. package/lib/ContextModuleFactory.js +1 -0
  7. package/lib/DependenciesBlock.js +1 -1
  8. package/lib/DllModule.js +6 -0
  9. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  10. package/lib/ExternalModule.js +15 -8
  11. package/lib/Module.js +7 -1
  12. package/lib/ProgressPlugin.js +71 -15
  13. package/lib/WebpackOptionsApply.js +3 -1
  14. package/lib/css/CssExportsGenerator.js +9 -0
  15. package/lib/css/CssGenerator.js +1 -1
  16. package/lib/css/CssLoadingRuntimeModule.js +13 -6
  17. package/lib/css/CssModulesPlugin.js +37 -12
  18. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +8 -10
  19. package/lib/dependencies/HarmonyImportSpecifierDependency.js +12 -12
  20. package/lib/dependencies/JsonExportsDependency.js +1 -1
  21. package/lib/javascript/BasicEvaluatedExpression.js +6 -5
  22. package/lib/javascript/JavascriptModulesPlugin.js +1 -0
  23. package/lib/javascript/JavascriptParser.js +23 -23
  24. package/lib/json/JsonData.js +2 -2
  25. package/lib/json/JsonParser.js +25 -12
  26. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  27. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  28. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  29. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  30. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  31. package/lib/optimize/InnerGraph.js +4 -4
  32. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  33. package/lib/optimize/MangleExportsPlugin.js +1 -1
  34. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  35. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  36. package/lib/optimize/RealContentHashPlugin.js +80 -30
  37. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  38. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  39. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  40. package/lib/optimize/SplitChunksPlugin.js +71 -31
  41. package/lib/serialization/BinaryMiddleware.js +143 -1
  42. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  43. package/lib/serialization/ObjectMiddleware.js +3 -0
  44. package/lib/serialization/types.js +1 -1
  45. package/package.json +1 -1
  46. package/schemas/WebpackOptions.check.js +1 -1
  47. package/schemas/WebpackOptions.json +12 -0
  48. package/types.d.ts +53 -41
package/lib/APIPlugin.js CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const InitFragment = require("./InitFragment");
8
9
  const {
9
10
  JAVASCRIPT_MODULE_TYPE_AUTO,
10
11
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
@@ -14,6 +15,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
14
15
  const WebpackError = require("./WebpackError");
15
16
  const ConstDependency = require("./dependencies/ConstDependency");
16
17
  const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
18
+ const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
17
19
  const {
18
20
  toConstantDependency,
19
21
  evaluateToString
@@ -24,103 +26,121 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
24
26
  /** @typedef {import("./Compiler")} Compiler */
25
27
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
26
28
 
27
- /* eslint-disable camelcase */
28
- const REPLACEMENTS = {
29
- __webpack_require__: {
30
- expr: RuntimeGlobals.require,
31
- req: [RuntimeGlobals.require],
32
- type: "function",
33
- assign: false
34
- },
35
- __webpack_public_path__: {
36
- expr: RuntimeGlobals.publicPath,
37
- req: [RuntimeGlobals.publicPath],
38
- type: "string",
39
- assign: true
40
- },
41
- __webpack_base_uri__: {
42
- expr: RuntimeGlobals.baseURI,
43
- req: [RuntimeGlobals.baseURI],
44
- type: "string",
45
- assign: true
46
- },
47
- __webpack_modules__: {
48
- expr: RuntimeGlobals.moduleFactories,
49
- req: [RuntimeGlobals.moduleFactories],
50
- type: "object",
51
- assign: false
52
- },
53
- __webpack_chunk_load__: {
54
- expr: RuntimeGlobals.ensureChunk,
55
- req: [RuntimeGlobals.ensureChunk],
56
- type: "function",
57
- assign: true
58
- },
59
- __non_webpack_require__: {
60
- expr: "require",
61
- req: null,
62
- type: undefined, // type is not known, depends on environment
63
- assign: true
64
- },
65
- __webpack_nonce__: {
66
- expr: RuntimeGlobals.scriptNonce,
67
- req: [RuntimeGlobals.scriptNonce],
68
- type: "string",
69
- assign: true
70
- },
71
- __webpack_hash__: {
72
- expr: `${RuntimeGlobals.getFullHash}()`,
73
- req: [RuntimeGlobals.getFullHash],
74
- type: "string",
75
- assign: false
76
- },
77
- __webpack_chunkname__: {
78
- expr: RuntimeGlobals.chunkName,
79
- req: [RuntimeGlobals.chunkName],
80
- type: "string",
81
- assign: false
82
- },
83
- __webpack_get_script_filename__: {
84
- expr: RuntimeGlobals.getChunkScriptFilename,
85
- req: [RuntimeGlobals.getChunkScriptFilename],
86
- type: "function",
87
- assign: true
88
- },
89
- __webpack_runtime_id__: {
90
- expr: RuntimeGlobals.runtimeId,
91
- req: [RuntimeGlobals.runtimeId],
92
- assign: false
93
- },
94
- "require.onError": {
95
- expr: RuntimeGlobals.uncaughtErrorHandler,
96
- req: [RuntimeGlobals.uncaughtErrorHandler],
97
- type: undefined, // type is not known, could be function or undefined
98
- assign: true // is never a pattern
99
- },
100
- __system_context__: {
101
- expr: RuntimeGlobals.systemContext,
102
- req: [RuntimeGlobals.systemContext],
103
- type: "object",
104
- assign: false
105
- },
106
- __webpack_share_scopes__: {
107
- expr: RuntimeGlobals.shareScopeMap,
108
- req: [RuntimeGlobals.shareScopeMap],
109
- type: "object",
110
- assign: false
111
- },
112
- __webpack_init_sharing__: {
113
- expr: RuntimeGlobals.initializeSharing,
114
- req: [RuntimeGlobals.initializeSharing],
115
- type: "function",
116
- assign: true
117
- }
118
- };
119
- /* eslint-enable camelcase */
29
+ /**
30
+ * @param {boolean} module true if ES module
31
+ * @param {string} importMetaName `import.meta` name
32
+ * @returns {Record<string, {expr: string, req: string[], type?: string, assign: boolean}>} replacements
33
+ */
34
+ function getReplacements(module, importMetaName) {
35
+ return {
36
+ __webpack_require__: {
37
+ expr: RuntimeGlobals.require,
38
+ req: [RuntimeGlobals.require],
39
+ type: "function",
40
+ assign: false
41
+ },
42
+ __webpack_public_path__: {
43
+ expr: RuntimeGlobals.publicPath,
44
+ req: [RuntimeGlobals.publicPath],
45
+ type: "string",
46
+ assign: true
47
+ },
48
+ __webpack_base_uri__: {
49
+ expr: RuntimeGlobals.baseURI,
50
+ req: [RuntimeGlobals.baseURI],
51
+ type: "string",
52
+ assign: true
53
+ },
54
+ __webpack_modules__: {
55
+ expr: RuntimeGlobals.moduleFactories,
56
+ req: [RuntimeGlobals.moduleFactories],
57
+ type: "object",
58
+ assign: false
59
+ },
60
+ __webpack_chunk_load__: {
61
+ expr: RuntimeGlobals.ensureChunk,
62
+ req: [RuntimeGlobals.ensureChunk],
63
+ type: "function",
64
+ assign: true
65
+ },
66
+ __non_webpack_require__: {
67
+ expr: module
68
+ ? `__WEBPACK_EXTERNAL_createRequire(${importMetaName}.url)`
69
+ : "require",
70
+ req: null,
71
+ type: undefined, // type is not known, depends on environment
72
+ assign: true
73
+ },
74
+ __webpack_nonce__: {
75
+ expr: RuntimeGlobals.scriptNonce,
76
+ req: [RuntimeGlobals.scriptNonce],
77
+ type: "string",
78
+ assign: true
79
+ },
80
+ __webpack_hash__: {
81
+ expr: `${RuntimeGlobals.getFullHash}()`,
82
+ req: [RuntimeGlobals.getFullHash],
83
+ type: "string",
84
+ assign: false
85
+ },
86
+ __webpack_chunkname__: {
87
+ expr: RuntimeGlobals.chunkName,
88
+ req: [RuntimeGlobals.chunkName],
89
+ type: "string",
90
+ assign: false
91
+ },
92
+ __webpack_get_script_filename__: {
93
+ expr: RuntimeGlobals.getChunkScriptFilename,
94
+ req: [RuntimeGlobals.getChunkScriptFilename],
95
+ type: "function",
96
+ assign: true
97
+ },
98
+ __webpack_runtime_id__: {
99
+ expr: RuntimeGlobals.runtimeId,
100
+ req: [RuntimeGlobals.runtimeId],
101
+ assign: false
102
+ },
103
+ "require.onError": {
104
+ expr: RuntimeGlobals.uncaughtErrorHandler,
105
+ req: [RuntimeGlobals.uncaughtErrorHandler],
106
+ type: undefined, // type is not known, could be function or undefined
107
+ assign: true // is never a pattern
108
+ },
109
+ __system_context__: {
110
+ expr: RuntimeGlobals.systemContext,
111
+ req: [RuntimeGlobals.systemContext],
112
+ type: "object",
113
+ assign: false
114
+ },
115
+ __webpack_share_scopes__: {
116
+ expr: RuntimeGlobals.shareScopeMap,
117
+ req: [RuntimeGlobals.shareScopeMap],
118
+ type: "object",
119
+ assign: false
120
+ },
121
+ __webpack_init_sharing__: {
122
+ expr: RuntimeGlobals.initializeSharing,
123
+ req: [RuntimeGlobals.initializeSharing],
124
+ type: "function",
125
+ assign: true
126
+ }
127
+ };
128
+ }
120
129
 
121
130
  const PLUGIN_NAME = "APIPlugin";
122
131
 
132
+ /**
133
+ * @typedef {Object} APIPluginOptions
134
+ * @property {boolean} [module] the output filename
135
+ */
136
+
123
137
  class APIPlugin {
138
+ /**
139
+ * @param {APIPluginOptions} [options] options
140
+ */
141
+ constructor(options = {}) {
142
+ this.options = options;
143
+ }
124
144
  /**
125
145
  * Apply the plugin
126
146
  * @param {Compiler} compiler the compiler instance
@@ -130,6 +150,12 @@ class APIPlugin {
130
150
  compiler.hooks.compilation.tap(
131
151
  PLUGIN_NAME,
132
152
  (compilation, { normalModuleFactory }) => {
153
+ const { importMetaName } = compilation.outputOptions;
154
+ const REPLACEMENTS = getReplacements(
155
+ this.options.module,
156
+ importMetaName
157
+ );
158
+
133
159
  compilation.dependencyTemplates.set(
134
160
  ConstDependency,
135
161
  new ConstDependency.Template()
@@ -152,18 +178,43 @@ class APIPlugin {
152
178
  return true;
153
179
  });
154
180
 
181
+ const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
182
+
183
+ hooks.renderModuleContent.tap(
184
+ PLUGIN_NAME,
185
+ (source, module, renderContext) => {
186
+ if (module.buildInfo.needCreateRequire) {
187
+ const chunkInitFragments = [
188
+ new InitFragment(
189
+ 'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
190
+ InitFragment.STAGE_HARMONY_IMPORTS,
191
+ 0,
192
+ "external module node-commonjs"
193
+ )
194
+ ];
195
+
196
+ renderContext.chunkInitFragments.push(...chunkInitFragments);
197
+ }
198
+
199
+ return source;
200
+ }
201
+ );
202
+
155
203
  /**
156
204
  * @param {JavascriptParser} parser the parser
157
205
  */
158
206
  const handler = parser => {
159
207
  Object.keys(REPLACEMENTS).forEach(key => {
160
208
  const info = REPLACEMENTS[key];
161
- parser.hooks.expression
162
- .for(key)
163
- .tap(
164
- PLUGIN_NAME,
165
- toConstantDependency(parser, info.expr, info.req)
166
- );
209
+ parser.hooks.expression.for(key).tap(PLUGIN_NAME, expression => {
210
+ const dep = toConstantDependency(parser, info.expr, info.req);
211
+
212
+ if (key === "__non_webpack_require__" && this.options.module) {
213
+ parser.state.module.buildInfo.needCreateRequire = true;
214
+ }
215
+
216
+ return dep(expression);
217
+ });
167
218
  if (info.assign === false) {
168
219
  parser.hooks.assign.for(key).tap(PLUGIN_NAME, expr => {
169
220
  const err = new WebpackError(`${key} must not be assigned`);
package/lib/Chunk.js CHANGED
@@ -23,6 +23,7 @@ const { mergeRuntime } = require("./util/runtime");
23
23
  /** @typedef {import("./ChunkGraph").ChunkSizeOptions} ChunkSizeOptions */
24
24
  /** @typedef {import("./ChunkGraph").ModuleFilterPredicate} ModuleFilterPredicate */
25
25
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
26
+ /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
26
27
  /** @typedef {import("./Compilation")} Compilation */
27
28
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
28
29
  /** @typedef {import("./Compilation").PathData} PathData */
@@ -32,6 +33,8 @@ const { mergeRuntime } = require("./util/runtime");
32
33
  /** @typedef {import("./util/Hash")} Hash */
33
34
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
34
35
 
36
+ /** @typedef {number | string} ChunkId */
37
+
35
38
  const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
36
39
 
37
40
  /**
@@ -66,21 +69,21 @@ class Chunk {
66
69
  * @param {boolean} backCompat enable backward-compatibility
67
70
  */
68
71
  constructor(name, backCompat = true) {
69
- /** @type {number | string | null} */
72
+ /** @type {ChunkId | null} */
70
73
  this.id = null;
71
- /** @type {(number|string)[] | null} */
74
+ /** @type {ChunkId[] | null} */
72
75
  this.ids = null;
73
76
  /** @type {number} */
74
77
  this.debugId = debugId++;
75
- /** @type {string} */
78
+ /** @type {string | undefined} */
76
79
  this.name = name;
77
80
  /** @type {SortableSet<string>} */
78
81
  this.idNameHints = new SortableSet();
79
82
  /** @type {boolean} */
80
83
  this.preventIntegration = false;
81
- /** @type {(string | function(PathData, AssetInfo=): string)?} */
84
+ /** @type {(string | function(PathData, AssetInfo=): string) | undefined} */
82
85
  this.filenameTemplate = undefined;
83
- /** @type {(string | function(PathData, AssetInfo=): string)?} */
86
+ /** @type {(string | function(PathData, AssetInfo=): string) | undefined} */
84
87
  this.cssFilenameTemplate = undefined;
85
88
  /** @private @type {SortableSet<ChunkGroup>} */
86
89
  this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
@@ -350,7 +353,7 @@ class Chunk {
350
353
  const chunkModuleHashMap = Object.create(null);
351
354
 
352
355
  for (const asyncChunk of this.getAllAsyncChunks()) {
353
- /** @type {(string|number)[]} */
356
+ /** @type {ChunkId[] | undefined} */
354
357
  let array;
355
358
  for (const module of chunkGraph.getOrderedChunkModulesIterable(
356
359
  asyncChunk,
@@ -359,7 +362,7 @@ class Chunk {
359
362
  if (filterFn(module)) {
360
363
  if (array === undefined) {
361
364
  array = [];
362
- chunkModuleIdMap[asyncChunk.id] = array;
365
+ chunkModuleIdMap[/** @type {ChunkId} */ (asyncChunk.id)] = array;
363
366
  }
364
367
  const moduleId = chunkGraph.getModuleId(module);
365
368
  array.push(moduleId);
@@ -405,15 +408,18 @@ class Chunk {
405
408
  const chunkNameMap = Object.create(null);
406
409
 
407
410
  for (const chunk of this.getAllAsyncChunks()) {
408
- chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
411
+ const id = /** @type {ChunkId} */ (chunk.id);
412
+ chunkHashMap[id] =
413
+ /** @type {string} */
414
+ (realHash ? chunk.hash : chunk.renderedHash);
409
415
  for (const key of Object.keys(chunk.contentHash)) {
410
416
  if (!chunkContentHashMap[key]) {
411
417
  chunkContentHashMap[key] = Object.create(null);
412
418
  }
413
- chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
419
+ chunkContentHashMap[key][id] = chunk.contentHash[key];
414
420
  }
415
421
  if (chunk.name) {
416
- chunkNameMap[chunk.id] = chunk.name;
422
+ chunkNameMap[id] = chunk.name;
417
423
  }
418
424
  }
419
425
 
@@ -553,7 +559,11 @@ class Chunk {
553
559
  const entryModules =
554
560
  chunkGraph.getChunkEntryModulesWithChunkGroupIterable(this);
555
561
  for (const [m, chunkGroup] of entryModules) {
556
- hash.update(`entry${chunkGraph.getModuleId(m)}${chunkGroup.id}`);
562
+ hash.update(
563
+ `entry${chunkGraph.getModuleId(m)}${
564
+ /** @type {ChunkGroup} */ (chunkGroup).id
565
+ }`
566
+ );
557
567
  }
558
568
  }
559
569
 
@@ -697,7 +707,13 @@ class Chunk {
697
707
  lists.set(name, list);
698
708
  }
699
709
  list.push({
700
- order: childGroup.options[key],
710
+ order:
711
+ /** @type {number} */
712
+ (
713
+ childGroup.options[
714
+ /** @type {keyof ChunkGroupOptions} */ (key)
715
+ ]
716
+ ),
701
717
  group: childGroup
702
718
  });
703
719
  }
@@ -718,7 +734,7 @@ class Chunk {
718
734
  for (const item of list) {
719
735
  for (const chunk of item.group.chunks) {
720
736
  if (filterFn && !filterFn(chunk, chunkGraph)) continue;
721
- chunkIdSet.add(chunk.id);
737
+ chunkIdSet.add(/** @type {ChunkId} */ (chunk.id));
722
738
  }
723
739
  }
724
740
  if (chunkIdSet.size > 0) {
@@ -731,13 +747,14 @@ class Chunk {
731
747
  /**
732
748
  * @param {ChunkGraph} chunkGraph the chunk graph
733
749
  * @param {string} type option name
734
- * @returns {{ onChunks: Chunk[], chunks: Set<Chunk> }[]} referenced chunks for a specific type
750
+ * @returns {{ onChunks: Chunk[], chunks: Set<Chunk> }[] | undefined} referenced chunks for a specific type
735
751
  */
736
752
  getChildrenOfTypeInOrder(chunkGraph, type) {
737
753
  const list = [];
738
754
  for (const group of this.groupsIterable) {
739
755
  for (const childGroup of group.childrenIterable) {
740
- const order = childGroup.options[type];
756
+ const order =
757
+ childGroup.options[/** @type {keyof ChunkGroupOptions} */ (type)];
741
758
  if (order === undefined) continue;
742
759
  list.push({
743
760
  order,
@@ -748,7 +765,8 @@ class Chunk {
748
765
  }
749
766
  if (list.length === 0) return undefined;
750
767
  list.sort((a, b) => {
751
- const cmp = b.order - a.order;
768
+ const cmp =
769
+ /** @type {number} */ (b.order) - /** @type {number} */ (a.order);
752
770
  if (cmp !== 0) return cmp;
753
771
  return a.group.compareTo(chunkGraph, b.group);
754
772
  });
@@ -792,7 +810,7 @@ class Chunk {
792
810
  if (chunkMap === undefined) {
793
811
  chunkMaps[key] = chunkMap = Object.create(null);
794
812
  }
795
- chunkMap[chunk.id] = data[key];
813
+ chunkMap[/** @type {ChunkId} */ (chunk.id)] = data[key];
796
814
  }
797
815
  };
798
816
 
package/lib/ChunkGroup.js CHANGED
@@ -97,7 +97,7 @@ class ChunkGroup {
97
97
  /** Indices in bottom-up order */
98
98
  /** @private @type {Map<Module, number>} */
99
99
  this._modulePostOrderIndices = new Map();
100
- /** @type {number} */
100
+ /** @type {number | undefined} */
101
101
  this.index = undefined;
102
102
  }
103
103
 
@@ -124,7 +124,7 @@ class ChunkGroup {
124
124
 
125
125
  /**
126
126
  * returns the name of current ChunkGroup
127
- * @returns {string|undefined} returns the ChunkGroup name
127
+ * @returns {string | undefined} returns the ChunkGroup name
128
128
  */
129
129
  get name() {
130
130
  return this.options.name;
@@ -132,7 +132,7 @@ class ChunkGroup {
132
132
 
133
133
  /**
134
134
  * sets a new name for current ChunkGroup
135
- * @param {string} value the new name for ChunkGroup
135
+ * @param {string | undefined} value the new name for ChunkGroup
136
136
  * @returns {void}
137
137
  */
138
138
  set name(value) {
@@ -496,7 +496,11 @@ class ChunkGroup {
496
496
  lists.set(name, (list = []));
497
497
  }
498
498
  list.push({
499
- order: childGroup.options[key],
499
+ order:
500
+ /** @type {number} */
501
+ (
502
+ childGroup.options[/** @type {keyof ChunkGroupOptions} */ (key)]
503
+ ),
500
504
  group: childGroup
501
505
  });
502
506
  }
@@ -528,7 +532,7 @@ class ChunkGroup {
528
532
  /**
529
533
  * Gets the top-down index of a module in this ChunkGroup
530
534
  * @param {Module} module the module
531
- * @returns {number} index
535
+ * @returns {number | undefined} index
532
536
  */
533
537
  getModulePreOrderIndex(module) {
534
538
  return this._modulePreOrderIndices.get(module);
@@ -547,7 +551,7 @@ class ChunkGroup {
547
551
  /**
548
552
  * Gets the bottom-up index of a module in this ChunkGroup
549
553
  * @param {Module} module the module
550
- * @returns {number} index
554
+ * @returns {number | undefined} index
551
555
  */
552
556
  getModulePostOrderIndex(module) {
553
557
  return this._modulePostOrderIndices.get(module);
package/lib/Compiler.js CHANGED
@@ -1011,8 +1011,7 @@ ${other}`);
1011
1011
  try {
1012
1012
  this.records = parseJson(content.toString("utf-8"));
1013
1013
  } catch (e) {
1014
- e.message = "Cannot parse records: " + e.message;
1015
- return callback(e);
1014
+ return callback(new Error(`Cannot parse records: ${e.message}`));
1016
1015
  }
1017
1016
 
1018
1017
  return callback();
@@ -64,6 +64,7 @@ const makeSerializable = require("./util/makeSerializable");
64
64
  * @property {string=} typePrefix
65
65
  * @property {string=} category
66
66
  * @property {string[][]=} referencedExports exports referenced from modules (won't be mangled)
67
+ * @property {string=} layer
67
68
  */
68
69
 
69
70
  /**
@@ -107,8 +108,9 @@ class ContextModule extends Module {
107
108
  const resourceQuery = (options && options.resourceQuery) || parsed.query;
108
109
  const resourceFragment =
109
110
  (options && options.resourceFragment) || parsed.fragment;
111
+ const layer = options && options.layer;
110
112
 
111
- super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource);
113
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource, layer);
112
114
  /** @type {ContextModuleOptions} */
113
115
  this.options = {
114
116
  ...options,
@@ -117,7 +119,7 @@ class ContextModule extends Module {
117
119
  resourceFragment
118
120
  };
119
121
  } else {
120
- super(JAVASCRIPT_MODULE_TYPE_DYNAMIC);
122
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, undefined, options.layer);
121
123
  /** @type {ContextModuleOptions} */
122
124
  this.options = {
123
125
  ...options,
@@ -95,6 +95,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
95
95
  {
96
96
  context: context,
97
97
  dependencies: dependencies,
98
+ layer: data.contextInfo.issuerLayer,
98
99
  resolveOptions,
99
100
  fileDependencies,
100
101
  missingDependencies,
@@ -32,7 +32,7 @@ class DependenciesBlock {
32
32
  this.dependencies = [];
33
33
  /** @type {AsyncDependenciesBlock[]} */
34
34
  this.blocks = [];
35
- /** @type {DependenciesBlock} */
35
+ /** @type {DependenciesBlock | undefined} */
36
36
  this.parent = undefined;
37
37
  }
38
38
 
package/lib/DllModule.js CHANGED
@@ -15,6 +15,7 @@ const makeSerializable = require("./util/makeSerializable");
15
15
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
16
16
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
17
17
  /** @typedef {import("./Compilation")} Compilation */
18
+ /** @typedef {import("./Dependency")} Dependency */
18
19
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
19
20
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
20
21
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
@@ -37,6 +38,11 @@ const RUNTIME_REQUIREMENTS = new Set([
37
38
  ]);
38
39
 
39
40
  class DllModule extends Module {
41
+ /**
42
+ * @param {string} context context path
43
+ * @param {Dependency[]} dependencies dependencies
44
+ * @param {string} name name
45
+ */
40
46
  constructor(context, dependencies, name) {
41
47
  super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, context);
42
48
 
@@ -160,7 +160,8 @@ class EvalSourceMapDevToolPlugin {
160
160
  }
161
161
  sourceMap.sourceRoot = options.sourceRoot || "";
162
162
  const moduleId = chunkGraph.getModuleId(m);
163
- sourceMap.file = `${moduleId}.js`;
163
+ sourceMap.file =
164
+ typeof moduleId === "number" ? `${moduleId}.js` : moduleId;
164
165
 
165
166
  const footer =
166
167
  this.sourceMapComment.replace(
@@ -104,9 +104,13 @@ const getSourceForCommonJsExternal = moduleAndSpecifiers => {
104
104
 
105
105
  /**
106
106
  * @param {string|string[]} moduleAndSpecifiers the module request
107
+ * @param {string} importMetaName import.meta name
107
108
  * @returns {SourceData} the generated source
108
109
  */
109
- const getSourceForCommonJsExternalInNodeModule = moduleAndSpecifiers => {
110
+ const getSourceForCommonJsExternalInNodeModule = (
111
+ moduleAndSpecifiers,
112
+ importMetaName
113
+ ) => {
110
114
  const chunkInitFragments = [
111
115
  new InitFragment(
112
116
  'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
@@ -117,18 +121,18 @@ const getSourceForCommonJsExternalInNodeModule = moduleAndSpecifiers => {
117
121
  ];
118
122
  if (!Array.isArray(moduleAndSpecifiers)) {
119
123
  return {
120
- expression: `__WEBPACK_EXTERNAL_createRequire(import.meta.url)(${JSON.stringify(
124
+ chunkInitFragments,
125
+ expression: `__WEBPACK_EXTERNAL_createRequire(${importMetaName}.url)(${JSON.stringify(
121
126
  moduleAndSpecifiers
122
- )})`,
123
- chunkInitFragments
127
+ )})`
124
128
  };
125
129
  }
126
130
  const moduleName = moduleAndSpecifiers[0];
127
131
  return {
128
- expression: `__WEBPACK_EXTERNAL_createRequire(import.meta.url)(${JSON.stringify(
132
+ chunkInitFragments,
133
+ expression: `__WEBPACK_EXTERNAL_createRequire(${importMetaName}.url)(${JSON.stringify(
129
134
  moduleName
130
- )})${propertyAccess(moduleAndSpecifiers, 1)}`,
131
- chunkInitFragments
135
+ )})${propertyAccess(moduleAndSpecifiers, 1)}`
132
136
  };
133
137
  };
134
138
 
@@ -557,7 +561,10 @@ class ExternalModule extends Module {
557
561
  return getSourceForCommonJsExternal(request);
558
562
  case "node-commonjs":
559
563
  return this.buildInfo.module
560
- ? getSourceForCommonJsExternalInNodeModule(request)
564
+ ? getSourceForCommonJsExternalInNodeModule(
565
+ request,
566
+ runtimeTemplate.outputOptions.importMetaName
567
+ )
561
568
  : getSourceForCommonJsExternal(request);
562
569
  case "amd":
563
570
  case "amd-require":
package/lib/Module.js CHANGED
@@ -107,6 +107,7 @@ const makeSerializable = require("./util/makeSerializable");
107
107
  */
108
108
 
109
109
  /** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
110
+ /** @typedef {Record<string, any>} BuildInfo */
110
111
 
111
112
  const EMPTY_RESOLVE_OPTIONS = {};
112
113
 
@@ -116,6 +117,11 @@ const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
116
117
  const DEFAULT_TYPES_JS = new Set(["javascript"]);
117
118
 
118
119
  const deprecatedNeedRebuild = util.deprecate(
120
+ /**
121
+ * @param {Module} module the module
122
+ * @param {NeedBuildContext} context context info
123
+ * @returns {boolean} true, when rebuild is needed
124
+ */
119
125
  (module, context) => {
120
126
  return module.needRebuild(
121
127
  context.fileSystemInfo.getDeprecatedFileTimestamps(),
@@ -169,7 +175,7 @@ class Module extends DependenciesBlock {
169
175
  this._errors = undefined;
170
176
  /** @type {BuildMeta | undefined} */
171
177
  this.buildMeta = undefined;
172
- /** @type {Record<string, any> | undefined} */
178
+ /** @type {BuildInfo | undefined} */
173
179
  this.buildInfo = undefined;
174
180
  /** @type {Dependency[] | undefined} */
175
181
  this.presentationalDependencies = undefined;