webpack 5.103.0 → 5.104.1

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 (177) hide show
  1. package/hot/dev-server.js +18 -3
  2. package/hot/emitter-event-target.js +7 -0
  3. package/hot/lazy-compilation-node.js +45 -29
  4. package/hot/lazy-compilation-universal.js +18 -0
  5. package/hot/lazy-compilation-web.js +15 -5
  6. package/hot/load-http.js +7 -0
  7. package/hot/only-dev-server.js +19 -4
  8. package/lib/APIPlugin.js +6 -0
  9. package/lib/Chunk.js +1 -1
  10. package/lib/ChunkGraph.js +9 -7
  11. package/lib/ChunkGroup.js +8 -5
  12. package/lib/CleanPlugin.js +6 -3
  13. package/lib/CodeGenerationResults.js +2 -1
  14. package/lib/CompatibilityPlugin.js +3 -0
  15. package/lib/Compilation.js +33 -19
  16. package/lib/Compiler.js +3 -3
  17. package/lib/ContextModule.js +6 -3
  18. package/lib/ContextModuleFactory.js +6 -4
  19. package/lib/DefinePlugin.js +34 -3
  20. package/lib/DelegatedModule.js +7 -4
  21. package/lib/DllModule.js +6 -3
  22. package/lib/DotenvPlugin.js +11 -6
  23. package/lib/ExportsInfo.js +5 -5
  24. package/lib/ExternalModule.js +8 -7
  25. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  26. package/lib/FileSystemInfo.js +1 -1
  27. package/lib/Generator.js +10 -7
  28. package/lib/HookWebpackError.js +33 -4
  29. package/lib/HotModuleReplacementPlugin.js +22 -0
  30. package/lib/ManifestPlugin.js +1 -1
  31. package/lib/Module.js +24 -15
  32. package/lib/ModuleBuildError.js +1 -1
  33. package/lib/ModuleError.js +1 -1
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +27 -12
  36. package/lib/ModuleGraphConnection.js +2 -2
  37. package/lib/ModuleSourceTypeConstants.js +189 -0
  38. package/lib/ModuleTypeConstants.js +1 -4
  39. package/lib/ModuleWarning.js +1 -1
  40. package/lib/NodeStuffPlugin.js +52 -42
  41. package/lib/NormalModule.js +6 -4
  42. package/lib/NormalModuleFactory.js +7 -10
  43. package/lib/Parser.js +1 -1
  44. package/lib/RawModule.js +7 -4
  45. package/lib/RuntimeModule.js +1 -1
  46. package/lib/RuntimeTemplate.js +5 -1
  47. package/lib/SizeFormatHelpers.js +1 -1
  48. package/lib/SourceMapDevToolPlugin.js +6 -1
  49. package/lib/Template.js +17 -6
  50. package/lib/TemplatedPathPlugin.js +5 -6
  51. package/lib/WebpackError.js +0 -1
  52. package/lib/WebpackOptionsApply.js +37 -9
  53. package/lib/asset/AssetBytesGenerator.js +15 -11
  54. package/lib/asset/AssetGenerator.js +30 -24
  55. package/lib/asset/AssetSourceGenerator.js +15 -11
  56. package/lib/asset/RawDataUrlModule.js +6 -3
  57. package/lib/buildChunkGraph.js +4 -2
  58. package/lib/cache/PackFileCacheStrategy.js +6 -5
  59. package/lib/cli.js +2 -43
  60. package/lib/config/browserslistTargetHandler.js +19 -0
  61. package/lib/config/defaults.js +128 -43
  62. package/lib/config/normalization.js +2 -2
  63. package/lib/config/target.js +5 -0
  64. package/lib/container/ContainerEntryModule.js +6 -3
  65. package/lib/container/FallbackModule.js +6 -3
  66. package/lib/container/RemoteModule.js +1 -3
  67. package/lib/css/CssGenerator.js +26 -24
  68. package/lib/css/CssLoadingRuntimeModule.js +12 -4
  69. package/lib/css/CssModulesPlugin.js +29 -74
  70. package/lib/css/CssParser.js +828 -341
  71. package/lib/css/walkCssTokens.js +33 -13
  72. package/lib/dependencies/CachedConstDependency.js +24 -10
  73. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  74. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  75. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  76. package/lib/dependencies/CssIcssExportDependency.js +242 -104
  77. package/lib/dependencies/CssIcssImportDependency.js +61 -4
  78. package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
  79. package/lib/dependencies/CssImportDependency.js +2 -1
  80. package/lib/dependencies/CssUrlDependency.js +3 -2
  81. package/lib/dependencies/DynamicExports.js +7 -7
  82. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  83. package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
  84. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
  85. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
  86. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -4
  87. package/lib/dependencies/HarmonyExports.js +4 -4
  88. package/lib/dependencies/HarmonyImportDependency.js +8 -3
  89. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  90. package/lib/dependencies/ImportMetaPlugin.js +57 -0
  91. package/lib/dependencies/ImportParserPlugin.js +2 -2
  92. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  93. package/lib/dependencies/WorkerPlugin.js +2 -2
  94. package/lib/dependencies/getFunctionExpression.js +1 -1
  95. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  96. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  97. package/lib/hmr/LazyCompilationPlugin.js +4 -3
  98. package/lib/ids/IdHelpers.js +16 -7
  99. package/lib/javascript/ChunkHelpers.js +1 -1
  100. package/lib/javascript/JavascriptGenerator.js +4 -3
  101. package/lib/javascript/JavascriptModulesPlugin.js +57 -24
  102. package/lib/javascript/JavascriptParser.js +19 -6
  103. package/lib/json/JsonGenerator.js +5 -4
  104. package/lib/json/JsonParser.js +2 -1
  105. package/lib/library/AbstractLibraryPlugin.js +1 -1
  106. package/lib/library/AmdLibraryPlugin.js +4 -1
  107. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  108. package/lib/library/ModuleLibraryPlugin.js +41 -13
  109. package/lib/library/SystemLibraryPlugin.js +4 -1
  110. package/lib/library/UmdLibraryPlugin.js +1 -1
  111. package/lib/logging/Logger.js +5 -4
  112. package/lib/logging/createConsoleLogger.js +2 -2
  113. package/lib/optimize/ConcatenatedModule.js +47 -32
  114. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  115. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  116. package/lib/optimize/SplitChunksPlugin.js +60 -46
  117. package/lib/rules/RuleSetCompiler.js +1 -1
  118. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  119. package/lib/schemes/HttpUriPlugin.js +97 -10
  120. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  121. package/lib/serialization/ObjectMiddleware.js +0 -2
  122. package/lib/serialization/SingleItemMiddleware.js +1 -1
  123. package/lib/sharing/ConsumeSharedModule.js +1 -1
  124. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  125. package/lib/sharing/ProvideSharedModule.js +1 -1
  126. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  127. package/lib/sharing/utils.js +1 -1
  128. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  129. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  130. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  131. package/lib/util/StringXor.js +1 -1
  132. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  133. package/lib/util/binarySearchBounds.js +2 -2
  134. package/lib/util/comparators.js +53 -76
  135. package/lib/util/compileBooleanMatcher.js +78 -6
  136. package/lib/util/createHash.js +20 -199
  137. package/lib/util/deprecation.js +1 -1
  138. package/lib/util/deterministicGrouping.js +6 -3
  139. package/lib/util/fs.js +75 -75
  140. package/lib/util/hash/BatchedHash.js +10 -9
  141. package/lib/util/hash/BulkUpdateHash.js +138 -0
  142. package/lib/util/hash/DebugHash.js +75 -0
  143. package/lib/util/hash/hash-digest.js +216 -0
  144. package/lib/util/identifier.js +82 -17
  145. package/lib/util/internalSerializables.js +2 -6
  146. package/lib/util/runtime.js +3 -3
  147. package/lib/util/source.js +2 -2
  148. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  149. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
  150. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  151. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
  152. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  153. package/lib/webpack.js +1 -1
  154. package/package.json +30 -25
  155. package/schemas/WebpackOptions.check.js +1 -1
  156. package/schemas/WebpackOptions.json +59 -82
  157. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  158. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  159. package/types.d.ts +225 -158
  160. package/lib/ModuleSourceTypesConstants.js +0 -117
  161. package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
  162. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
  163. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
  164. package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
  165. package/lib/util/jsonParseEvenBetterErrors.js +0 -10
  166. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  167. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  168. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  169. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  170. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  171. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  173. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  174. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  175. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  176. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  177. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -281,7 +281,7 @@ ModuleFilenameHelpers.createFilename = (
281
281
  * @template T
282
282
  * @param {T[]} array the array with duplicates to be replaced
283
283
  * @param {(duplicateItem: T, duplicateItemIndex: number, numberOfTimesReplaced: number) => T} fn callback function to generate new values for the duplicate items
284
- * @param {(firstElement:T, nextElement:T) => -1 | 0 | 1=} comparator optional comparator function to sort the duplicate items
284
+ * @param {(firstElement: T, nextElement: T) => -1 | 0 | 1=} comparator optional comparator function to sort the duplicate items
285
285
  * @returns {T[]} the array with duplicates replaced
286
286
  * @example
287
287
  * ```js
@@ -169,6 +169,12 @@ class ModuleGraph {
169
169
  * @private
170
170
  */
171
171
  this._dependencySourceOrderMap = new WeakMap();
172
+
173
+ /**
174
+ * @type {Set<Module>}
175
+ * @private
176
+ */
177
+ this._modulesNeedingSort = new Set();
172
178
  }
173
179
 
174
180
  /**
@@ -305,17 +311,15 @@ class ModuleGraph {
305
311
  // import { a, b } from "lib" -> a and b have the same source order -> a = b = 1
306
312
  // import { d } from "lib/d" -> d = 2
307
313
  const currentSourceOrder =
308
- /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ (
309
- dependency
310
- ).sourceOrder;
314
+ /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
315
+ (dependency).sourceOrder;
311
316
 
312
317
  // lib/index.js (reexport)
313
318
  // import { a } from "lib/a" -> a = 0
314
319
  // import { b } from "lib/b" -> b = 1
315
320
  const originSourceOrder =
316
- /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ (
317
- originDependency
318
- ).sourceOrder;
321
+ /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
322
+ (originDependency).sourceOrder;
319
323
  if (
320
324
  typeof currentSourceOrder === "number" &&
321
325
  typeof originSourceOrder === "number"
@@ -330,17 +334,28 @@ class ModuleGraph {
330
334
  sub: originSourceOrder
331
335
  });
332
336
 
337
+ // Save for later batch sorting
338
+ this._modulesNeedingSort.add(parentModule);
339
+ }
340
+ }
341
+
342
+ /**
343
+ * @returns {void}
344
+ */
345
+ finishUpdateParent() {
346
+ if (this._modulesNeedingSort.size === 0) {
347
+ return;
348
+ }
349
+ for (const mod of this._modulesNeedingSort) {
333
350
  // If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder,
334
351
  // we sort based on it; otherwise, we preserve the original order.
335
352
  sortWithSourceOrder(
336
- parentModule.dependencies,
337
- this._dependencySourceOrderMap
353
+ mod.dependencies,
354
+ this._dependencySourceOrderMap,
355
+ (dep, index) => this.setParentDependenciesBlockIndex(dep, index)
338
356
  );
339
-
340
- for (const [index, dep] of parentModule.dependencies.entries()) {
341
- this.setParentDependenciesBlockIndex(dep, index);
342
- }
343
357
  }
358
+ this._modulesNeedingSort.clear();
344
359
  }
345
360
 
346
361
  /**
@@ -52,8 +52,8 @@ const intersectConnectionStates = (a, b) => {
52
52
 
53
53
  class ModuleGraphConnection {
54
54
  /**
55
- * @param {Module|null} originModule the referencing module
56
- * @param {Dependency|null} dependency the referencing dependency
55
+ * @param {Module | null} originModule the referencing module
56
+ * @param {Dependency | null} dependency the referencing dependency
57
57
  * @param {Module} module the referenced module
58
58
  * @param {string=} explanation some extra detail
59
59
  * @param {boolean=} weak the reference is weak
@@ -0,0 +1,189 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * @type {Readonly<"javascript">}
10
+ */
11
+ const JAVASCRIPT_TYPE = "javascript";
12
+
13
+ /**
14
+ * @type {Readonly<"runtime">}
15
+ */
16
+ const RUNTIME_TYPE = "runtime";
17
+
18
+ /**
19
+ * @type {Readonly<"webassembly">}
20
+ */
21
+ const WEBASSEMBLY_TYPE = "webassembly";
22
+
23
+ /**
24
+ * @type {Readonly<"asset">}
25
+ */
26
+ const ASSET_TYPE = "asset";
27
+
28
+ /**
29
+ * @type {Readonly<"css">}
30
+ */
31
+ const CSS_TYPE = "css";
32
+
33
+ /**
34
+ * @type {Readonly<"css-import">}
35
+ */
36
+ const CSS_IMPORT_TYPE = "css-import";
37
+
38
+ /**
39
+ * @type {Readonly<"css-url">}
40
+ */
41
+ const CSS_URL_TYPE = "css-url";
42
+
43
+ /**
44
+ * @type {Readonly<"share-init">}
45
+ */
46
+ const SHARED_INIT_TYPE = "share-init";
47
+
48
+ /**
49
+ * @type {Readonly<"remote">}
50
+ */
51
+ const REMOTE_GENERATOR_TYPE = "remote";
52
+
53
+ /**
54
+ * @type {Readonly<"consume-shared">}
55
+ */
56
+ const CONSUME_SHARED_GENERATOR_TYPE = "consume-shared";
57
+
58
+ /**
59
+ * @type {Readonly<"unknown">}
60
+ */
61
+ const UNKNOWN_TYPE = "unknown";
62
+
63
+ /**
64
+ * @typedef {JAVASCRIPT_TYPE |
65
+ * RUNTIME_TYPE |
66
+ * WEBASSEMBLY_TYPE |
67
+ * ASSET_TYPE |
68
+ * CSS_TYPE |
69
+ * CSS_IMPORT_TYPE |
70
+ * CSS_URL_TYPE |
71
+ * SHARED_INIT_TYPE |
72
+ * REMOTE_GENERATOR_TYPE |
73
+ * CONSUME_SHARED_GENERATOR_TYPE |
74
+ * UNKNOWN_TYPE} AllTypes
75
+ */
76
+
77
+ /**
78
+ * @type {ReadonlySet<never>}
79
+ */
80
+ const NO_TYPES = new Set();
81
+
82
+ /**
83
+ * @type {ReadonlySet<"asset">}
84
+ */
85
+ const ASSET_TYPES = new Set([ASSET_TYPE]);
86
+
87
+ /**
88
+ * @type {ReadonlySet<"asset" | "javascript" | "asset">}
89
+ */
90
+ const ASSET_AND_JAVASCRIPT_TYPES = new Set([ASSET_TYPE, JAVASCRIPT_TYPE]);
91
+
92
+ /**
93
+ * @type {ReadonlySet<"css-url" | "asset">}
94
+ */
95
+ const ASSET_AND_CSS_URL_TYPES = new Set([ASSET_TYPE, CSS_URL_TYPE]);
96
+
97
+ /**
98
+ * @type {ReadonlySet<"javascript" | "css-url" | "asset">}
99
+ */
100
+ const ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES = new Set([
101
+ ASSET_TYPE,
102
+ JAVASCRIPT_TYPE,
103
+ CSS_URL_TYPE
104
+ ]);
105
+
106
+ /**
107
+ * @type {ReadonlySet<"javascript">}
108
+ */
109
+ const JAVASCRIPT_TYPES = new Set([JAVASCRIPT_TYPE]);
110
+
111
+ /**
112
+ * @type {ReadonlySet<"javascript" | "css-url">}
113
+ */
114
+ const JAVASCRIPT_AND_CSS_URL_TYPES = new Set([JAVASCRIPT_TYPE, CSS_URL_TYPE]);
115
+
116
+ /**
117
+ * @type {ReadonlySet<"javascript" | "css">}
118
+ */
119
+ const JAVASCRIPT_AND_CSS_TYPES = new Set([JAVASCRIPT_TYPE, CSS_TYPE]);
120
+
121
+ /**
122
+ * @type {ReadonlySet<"css">}
123
+ */
124
+ const CSS_TYPES = new Set([CSS_TYPE]);
125
+
126
+ /**
127
+ * @type {ReadonlySet<"css-url">}
128
+ */
129
+ const CSS_URL_TYPES = new Set([CSS_URL_TYPE]);
130
+ /**
131
+ * @type {ReadonlySet<"css-import">}
132
+ */
133
+ const CSS_IMPORT_TYPES = new Set([CSS_IMPORT_TYPE]);
134
+
135
+ /**
136
+ * @type {ReadonlySet<"webassembly">}
137
+ */
138
+ const WEBASSEMBLY_TYPES = new Set([WEBASSEMBLY_TYPE]);
139
+
140
+ /**
141
+ * @type {ReadonlySet<"runtime">}
142
+ */
143
+ const RUNTIME_TYPES = new Set([RUNTIME_TYPE]);
144
+
145
+ /**
146
+ * @type {ReadonlySet<"remote" | "share-init">}
147
+ */
148
+ const REMOTE_AND_SHARE_INIT_TYPES = new Set([
149
+ REMOTE_GENERATOR_TYPE,
150
+ SHARED_INIT_TYPE
151
+ ]);
152
+
153
+ /**
154
+ * @type {ReadonlySet<"consume-shared">}
155
+ */
156
+ const CONSUME_SHARED_TYPES = new Set([CONSUME_SHARED_GENERATOR_TYPE]);
157
+
158
+ /**
159
+ * @type {ReadonlySet<"share-init">}
160
+ */
161
+ const SHARED_INIT_TYPES = new Set([SHARED_INIT_TYPE]);
162
+
163
+ module.exports.ASSET_AND_CSS_URL_TYPES = ASSET_AND_CSS_URL_TYPES;
164
+ module.exports.ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES =
165
+ ASSET_AND_JAVASCRIPT_AND_CSS_URL_TYPES;
166
+ module.exports.ASSET_AND_JAVASCRIPT_TYPES = ASSET_AND_JAVASCRIPT_TYPES;
167
+ module.exports.ASSET_TYPE = ASSET_TYPE;
168
+ module.exports.ASSET_TYPES = ASSET_TYPES;
169
+ module.exports.CONSUME_SHARED_TYPES = CONSUME_SHARED_TYPES;
170
+ module.exports.CSS_IMPORT_TYPE = CSS_IMPORT_TYPE;
171
+ module.exports.CSS_IMPORT_TYPES = CSS_IMPORT_TYPES;
172
+ module.exports.CSS_TYPE = CSS_TYPE;
173
+ module.exports.CSS_TYPE = CSS_TYPE;
174
+ module.exports.CSS_TYPES = CSS_TYPES;
175
+ module.exports.CSS_URL_TYPE = CSS_URL_TYPE;
176
+ module.exports.CSS_URL_TYPES = CSS_URL_TYPES;
177
+ module.exports.JAVASCRIPT_AND_CSS_TYPES = JAVASCRIPT_AND_CSS_TYPES;
178
+ module.exports.JAVASCRIPT_AND_CSS_URL_TYPES = JAVASCRIPT_AND_CSS_URL_TYPES;
179
+ module.exports.JAVASCRIPT_TYPE = JAVASCRIPT_TYPE;
180
+ module.exports.JAVASCRIPT_TYPES = JAVASCRIPT_TYPES;
181
+ module.exports.NO_TYPES = NO_TYPES;
182
+ module.exports.REMOTE_AND_SHARE_INIT_TYPES = REMOTE_AND_SHARE_INIT_TYPES;
183
+ module.exports.RUNTIME_TYPE = RUNTIME_TYPE;
184
+ module.exports.RUNTIME_TYPES = RUNTIME_TYPES;
185
+ module.exports.SHARED_INIT_TYPE = SHARED_INIT_TYPE;
186
+ module.exports.SHARED_INIT_TYPES = SHARED_INIT_TYPES;
187
+ module.exports.UNKNOWN_TYPE = UNKNOWN_TYPE;
188
+ module.exports.WEBASSEMBLY_TYPE = WEBASSEMBLY_TYPE;
189
+ module.exports.WEBASSEMBLY_TYPES = WEBASSEMBLY_TYPES;
@@ -97,7 +97,7 @@ const ASSET_MODULE_TYPE_BYTES = "asset/bytes";
97
97
 
98
98
  /**
99
99
  * @type {Readonly<"asset/raw-data-url">}
100
- * TODO: Document what this asset type is for. See css-loader tests for its usage.
100
+ * This is the module type used for the ignored asset module.
101
101
  */
102
102
  const ASSET_MODULE_TYPE_RAW_DATA_URL = "asset/raw-data-url";
103
103
 
@@ -110,21 +110,18 @@ const WEBPACK_MODULE_TYPE_RUNTIME = "runtime";
110
110
  /**
111
111
  * @type {Readonly<"fallback-module">}
112
112
  * This is the module type used for the ModuleFederation feature's FallbackModule class.
113
- * TODO: Document this better.
114
113
  */
115
114
  const WEBPACK_MODULE_TYPE_FALLBACK = "fallback-module";
116
115
 
117
116
  /**
118
117
  * @type {Readonly<"remote-module">}
119
118
  * This is the module type used for the ModuleFederation feature's RemoteModule class.
120
- * TODO: Document this better.
121
119
  */
122
120
  const WEBPACK_MODULE_TYPE_REMOTE = "remote-module";
123
121
 
124
122
  /**
125
123
  * @type {Readonly<"provide-module">}
126
124
  * This is the module type used for the ModuleFederation feature's ProvideModule class.
127
- * TODO: Document this better.
128
125
  */
129
126
  const WEBPACK_MODULE_TYPE_PROVIDE = "provide-module";
130
127
 
@@ -15,7 +15,7 @@ const makeSerializable = require("./util/makeSerializable");
15
15
  class ModuleWarning extends WebpackError {
16
16
  /**
17
17
  * @param {Error} warning error thrown
18
- * @param {{from?: string|null}} info additional info
18
+ * @param {{from?: string | null}} info additional info
19
19
  */
20
20
  constructor(warning, { from = null } = {}) {
21
21
  let message = "Module Warning";
@@ -245,45 +245,46 @@ class NodeStuffPlugin {
245
245
  parser.hooks.expression
246
246
  .for(expressionName)
247
247
  .tap(PLUGIN_NAME, (expr) => {
248
+ // We use `CachedConstDependency` because of `eval` devtool, there is no `import.meta` inside `eval()`
248
249
  const { importMetaName, environment, module } =
249
250
  compilation.outputOptions;
250
251
 
251
- if (
252
- module &&
253
- importMetaName === "import.meta" &&
254
- (expressionName === "import.meta.filename" ||
255
- expressionName === "import.meta.dirname") &&
256
- environment.importMetaDirnameAndFilename
257
- ) {
258
- return true;
259
- }
260
-
261
252
  // Generate `import.meta.dirname` and `import.meta.filename` when:
262
253
  // - they are supported by the environment
263
254
  // - it is a universal target, because we can't use `import mod from "node:url"; ` at the top file
264
- const dep =
255
+ if (
265
256
  environment.importMetaDirnameAndFilename ||
266
257
  (compiler.platform.web === null &&
267
258
  compiler.platform.node === null &&
268
259
  module)
269
- ? new ConstDependency(
270
- `${importMetaName}.${property}`,
271
- /** @type {Range} */
272
- (expr.range)
273
- )
274
- : new ExternalModuleDependency(
275
- "url",
276
- [
277
- {
278
- name: "fileURLToPath",
279
- value: URL_MODULE_CONSTANT_FUNCTION_NAME
280
- }
281
- ],
282
- undefined,
283
- `${URL_MODULE_CONSTANT_FUNCTION_NAME}(${value()})`,
284
- /** @type {Range} */ (expr.range),
285
- `__webpack_${property}__`
286
- );
260
+ ) {
261
+ const dep = new CachedConstDependency(
262
+ `${importMetaName}.${property}`,
263
+ /** @type {Range} */
264
+ (expr.range),
265
+ `__webpack_${property}__`,
266
+ CachedConstDependency.PLACE_CHUNK
267
+ );
268
+
269
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
270
+ parser.state.module.addPresentationalDependency(dep);
271
+ return;
272
+ }
273
+
274
+ const dep = new ExternalModuleDependency(
275
+ "url",
276
+ [
277
+ {
278
+ name: "fileURLToPath",
279
+ value: URL_MODULE_CONSTANT_FUNCTION_NAME
280
+ }
281
+ ],
282
+ undefined,
283
+ `${URL_MODULE_CONSTANT_FUNCTION_NAME}(${value()})`,
284
+ /** @type {Range} */ (expr.range),
285
+ `__webpack_${property}__`,
286
+ ExternalModuleDependency.PLACE_CHUNK
287
+ );
287
288
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
288
289
  parser.state.module.addPresentationalDependency(dep);
289
290
 
@@ -300,20 +301,25 @@ class NodeStuffPlugin {
300
301
  compilation.outputOptions;
301
302
 
302
303
  if (
303
- module &&
304
- importMetaName === "import.meta" &&
305
- (expressionName === "import.meta.filename" ||
306
- expressionName === "import.meta.dirname") &&
307
- environment.importMetaDirnameAndFilename
304
+ environment.importMetaDirnameAndFilename ||
305
+ (compiler.platform.web === null &&
306
+ compiler.platform.node === null &&
307
+ module)
308
308
  ) {
309
- return `${property}: ${importMetaName}.${property},`;
310
- }
311
-
312
- if (environment.importMetaDirnameAndFilename) {
313
- return `${property}: ${importMetaName}.${property},`;
309
+ const dep = new CachedConstDependency(
310
+ `${importMetaName}.${property}`,
311
+ null,
312
+ `__webpack_${property}__`,
313
+ CachedConstDependency.PLACE_CHUNK
314
+ );
315
+ dep.loc = /** @type {DependencyLocation} */ (
316
+ usingProperty.loc
317
+ );
318
+ parser.state.module.addPresentationalDependency(dep);
319
+ return `${property}: __webpack_${property}__,`;
314
320
  }
315
321
 
316
- const dep = new ExternalModuleInitFragmentDependency(
322
+ const dep = new ExternalModuleDependency(
317
323
  "url",
318
324
  [
319
325
  {
@@ -321,13 +327,17 @@ class NodeStuffPlugin {
321
327
  value: URL_MODULE_CONSTANT_FUNCTION_NAME
322
328
  }
323
329
  ],
324
- undefined
330
+ undefined,
331
+ `${URL_MODULE_CONSTANT_FUNCTION_NAME}(${value()})`,
332
+ null,
333
+ `__webpack_${property}__`,
334
+ ExternalModuleDependency.PLACE_CHUNK
325
335
  );
326
336
 
327
337
  dep.loc = /** @type {DependencyLocation} */ (usingProperty.loc);
328
338
  parser.state.module.addPresentationalDependency(dep);
329
339
 
330
- return `${property}: ${URL_MODULE_CONSTANT_FUNCTION_NAME}(${value()}),`;
340
+ return `${property}: __webpack_${property}__,`;
331
341
  }
332
342
  });
333
343
  }
@@ -79,7 +79,8 @@ const memoize = require("./util/memoize");
79
79
  /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
80
80
  /** @typedef {import("./Module").BuildCallback} BuildCallback */
81
81
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
82
- /** @typedef {import("./Generator").SourceTypes} SourceTypes */
82
+ /** @typedef {import("./Module").SourceType} SourceType */
83
+ /** @typedef {import("./Module").SourceTypes} SourceTypes */
83
84
  /** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
84
85
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
85
86
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -394,7 +395,7 @@ class NormalModule extends Module {
394
395
  this._source = null;
395
396
  /**
396
397
  * @private
397
- * @type {Map<string | undefined, number> | undefined}
398
+ * @type {Map<undefined | SourceType, number> | undefined}
398
399
  */
399
400
  this._sourceSizes = undefined;
400
401
  /**
@@ -699,7 +700,8 @@ class NormalModule extends Module {
699
700
  options = parseJson(options);
700
701
  } catch (err) {
701
702
  throw new Error(
702
- `Cannot parse string options: ${/** @type {Error} */ (err).message}`
703
+ `Cannot parse string options: ${/** @type {Error} */ (err).message}`,
704
+ { cause: err }
703
705
  );
704
706
  }
705
707
  } else {
@@ -1307,7 +1309,7 @@ class NormalModule extends Module {
1307
1309
  /** @type {undefined | Set<string>} */
1308
1310
  let nonAbsoluteDependencies;
1309
1311
  /**
1310
- * @param {LazySet<string>} deps deps
1312
+ * @param {FileSystemDependencies} deps deps
1311
1313
  */
1312
1314
  const checkDependencies = (deps) => {
1313
1315
  for (const dep of deps) {
@@ -38,6 +38,7 @@ const {
38
38
  /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
39
39
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
40
40
  /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
41
+ /** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
41
42
  /** @typedef {import("./Generator")} Generator */
42
43
  /** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
43
44
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
@@ -61,7 +62,7 @@ const {
61
62
  * @typedef {import("./Compiler").Callback<T>} Callback
62
63
  */
63
64
 
64
- /** @typedef {Pick<RuleSetRule, 'type' | 'sideEffects' | 'parser' | 'generator' | 'resolve' | 'layer' | 'extractSourceMap'>} ModuleSettings */
65
+ /** @typedef {Pick<RuleSetRule, "type" | "sideEffects" | "parser" | "generator" | "resolve" | "layer" | "extractSourceMap">} ModuleSettings */
65
66
  /** @typedef {Partial<NormalModuleCreateData & { settings: ModuleSettings }>} CreateData */
66
67
 
67
68
  /**
@@ -74,9 +75,9 @@ const {
74
75
  * @property {ModuleDependency[]} dependencies
75
76
  * @property {string} dependencyType
76
77
  * @property {CreateData} createData
77
- * @property {LazySet<string>} fileDependencies
78
- * @property {LazySet<string>} missingDependencies
79
- * @property {LazySet<string>} contextDependencies
78
+ * @property {FileSystemDependencies} fileDependencies
79
+ * @property {FileSystemDependencies} missingDependencies
80
+ * @property {FileSystemDependencies} contextDependencies
80
81
  * @property {Module=} ignoredModule
81
82
  * @property {boolean} cacheable allow to use the unsafe cache
82
83
  */
@@ -296,14 +297,10 @@ const ruleSetCompiler = new RuleSetCompiler([
296
297
 
297
298
  /** @typedef {import("./css/CssParser")} CssParser */
298
299
  /** @typedef {import("../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
299
- /** @typedef {import("../declarations/WebpackOptions").CssAutoParserOptions} CssAutoParserOptions */
300
- /** @typedef {import("../declarations/WebpackOptions").CssGlobalParserOptions} CssGlobalParserOptions */
301
300
  /** @typedef {import("../declarations/WebpackOptions").CssModuleParserOptions} CssModuleParserOptions */
302
301
  /** @typedef {import("./css/CssGenerator")} CssGenerator */
303
302
  /** @typedef {import("../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
304
- /** @typedef {import("../declarations/WebpackOptions").CssGlobalGeneratorOptions} CssGlobalGeneratorOptions */
305
303
  /** @typedef {import("../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
306
- /** @typedef {import("../declarations/WebpackOptions").CssAutoGeneratorOptions} CssAutoGeneratorOptions */
307
304
 
308
305
  /**
309
306
  * @typedef {[
@@ -319,9 +316,9 @@ const ruleSetCompiler = new RuleSetCompiler([
319
316
  * [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
320
317
  * [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
321
318
  * [CSS_MODULE_TYPE, CssParser, CssParserOptions, CssGenerator, CssGeneratorOptions],
322
- * [CSS_MODULE_TYPE_AUTO, CssParser, CssAutoParserOptions, CssGenerator, CssAutoGeneratorOptions],
319
+ * [CSS_MODULE_TYPE_AUTO, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
323
320
  * [CSS_MODULE_TYPE_MODULE, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
324
- * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssGlobalParserOptions, CssGenerator, CssGlobalGeneratorOptions],
321
+ * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
325
322
  * [string, Parser, ParserOptions, Generator, GeneratorOptions],
326
323
  * ]} ParsersAndGeneratorsByTypes
327
324
  */
package/lib/Parser.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * @property {WebpackOptions} options
21
21
  */
22
22
 
23
- /** @typedef {Record<string, EXPECTED_ANY> & ParserStateBase} ParserState */
23
+ /** @typedef {ParserStateBase & Record<string, EXPECTED_ANY>} ParserState */
24
24
 
25
25
  class Parser {
26
26
  /* istanbul ignore next */
package/lib/RawModule.js CHANGED
@@ -7,7 +7,10 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
- const { JS_TYPES } = require("./ModuleSourceTypesConstants");
10
+ const {
11
+ JAVASCRIPT_TYPE,
12
+ JAVASCRIPT_TYPES
13
+ } = require("./ModuleSourceTypeConstants");
11
14
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
12
15
  const makeSerializable = require("./util/makeSerializable");
13
16
 
@@ -49,7 +52,7 @@ class RawModule extends Module {
49
52
  * @returns {SourceTypes} types available (do not mutate)
50
53
  */
51
54
  getSourceTypes() {
52
- return JS_TYPES;
55
+ return JAVASCRIPT_TYPES;
53
56
  }
54
57
 
55
58
  /**
@@ -122,11 +125,11 @@ class RawModule extends Module {
122
125
  const sources = new Map();
123
126
  if (this.useSourceMap || this.useSimpleSourceMap) {
124
127
  sources.set(
125
- "javascript",
128
+ JAVASCRIPT_TYPE,
126
129
  new OriginalSource(this.sourceStr, this.identifier())
127
130
  );
128
131
  } else {
129
- sources.set("javascript", new RawSource(this.sourceStr));
132
+ sources.set(JAVASCRIPT_TYPE, new RawSource(this.sourceStr));
130
133
  }
131
134
  return { sources, runtimeRequirements: this.runtimeRequirements };
132
135
  }
@@ -8,7 +8,7 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const OriginalSource = require("webpack-sources").OriginalSource;
10
10
  const Module = require("./Module");
11
- const { RUNTIME_TYPES } = require("./ModuleSourceTypesConstants");
11
+ const { RUNTIME_TYPES } = require("./ModuleSourceTypeConstants");
12
12
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
13
13
 
14
14
  /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
@@ -127,6 +127,10 @@ class RuntimeTemplate {
127
127
  return this.outputOptions.environment.const;
128
128
  }
129
129
 
130
+ supportsMethodShorthand() {
131
+ return this.outputOptions.environment.methodShorthand;
132
+ }
133
+
130
134
  supportsArrowFunction() {
131
135
  return this.outputOptions.environment.arrowFunction;
132
136
  }
@@ -956,7 +960,7 @@ class RuntimeTemplate {
956
960
  * @param {string} options.request the request
957
961
  * @param {string | string[]} options.exportName the export name
958
962
  * @param {Module} options.originModule the origin module
959
- * @param {boolean|undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
963
+ * @param {boolean | undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
960
964
  * @param {boolean} options.isCall true, if expression will be called
961
965
  * @param {boolean | null} options.callContext when false, call context will not be preserved
962
966
  * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
@@ -6,7 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /**
9
- * @param {number} size the size in bytes
9
+ * @param {number=} size the size in bytes
10
10
  * @returns {string} the formatted size
11
11
  */
12
12
  module.exports.formatSize = (size) => {
@@ -496,7 +496,12 @@ class SourceMapDevToolPlugin {
496
496
  if (options.debugIds) {
497
497
  const debugId = generateDebugId(source, sourceMap.file);
498
498
  sourceMap.debugId = debugId;
499
- currentSourceMappingURLComment = `\n//# debugId=${debugId}${currentSourceMappingURLComment}`;
499
+
500
+ const debugIdComment = `\n//# debugId=${debugId}`;
501
+ currentSourceMappingURLComment =
502
+ currentSourceMappingURLComment
503
+ ? `${debugIdComment}${currentSourceMappingURLComment}`
504
+ : debugIdComment;
500
505
  }
501
506
 
502
507
  const sourceMapString = JSON.stringify(sourceMap);