webpack 5.102.1 → 5.104.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.
Files changed (220) hide show
  1. package/README.md +121 -134
  2. package/hot/dev-server.js +18 -3
  3. package/hot/emitter-event-target.js +7 -0
  4. package/hot/lazy-compilation-node.js +45 -29
  5. package/hot/lazy-compilation-universal.js +18 -0
  6. package/hot/lazy-compilation-web.js +15 -5
  7. package/hot/load-http.js +7 -0
  8. package/hot/only-dev-server.js +19 -4
  9. package/lib/APIPlugin.js +6 -0
  10. package/lib/Chunk.js +1 -1
  11. package/lib/ChunkGraph.js +9 -7
  12. package/lib/ChunkGroup.js +8 -5
  13. package/lib/CleanPlugin.js +6 -3
  14. package/lib/CodeGenerationResults.js +2 -1
  15. package/lib/CompatibilityPlugin.js +28 -2
  16. package/lib/Compilation.js +58 -21
  17. package/lib/Compiler.js +3 -3
  18. package/lib/ConcatenationScope.js +0 -15
  19. package/lib/ContextModule.js +6 -3
  20. package/lib/ContextModuleFactory.js +6 -4
  21. package/lib/CssModule.js +6 -1
  22. package/lib/DefinePlugin.js +45 -14
  23. package/lib/DelegatedModule.js +7 -4
  24. package/lib/Dependency.js +8 -1
  25. package/lib/DependencyTemplate.js +1 -0
  26. package/lib/DllModule.js +6 -3
  27. package/lib/DotenvPlugin.js +462 -0
  28. package/lib/EnvironmentPlugin.js +19 -16
  29. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  30. package/lib/ExportsInfo.js +6 -2
  31. package/lib/ExternalModule.js +28 -35
  32. package/lib/ExternalModuleFactoryPlugin.js +11 -9
  33. package/lib/ExternalsPlugin.js +2 -1
  34. package/lib/FileSystemInfo.js +1 -1
  35. package/lib/Generator.js +10 -7
  36. package/lib/HookWebpackError.js +33 -4
  37. package/lib/HotModuleReplacementPlugin.js +22 -0
  38. package/lib/ManifestPlugin.js +235 -0
  39. package/lib/Module.js +27 -15
  40. package/lib/ModuleBuildError.js +1 -1
  41. package/lib/ModuleError.js +1 -1
  42. package/lib/ModuleFilenameHelpers.js +1 -1
  43. package/lib/ModuleGraph.js +29 -13
  44. package/lib/ModuleGraphConnection.js +2 -2
  45. package/lib/ModuleSourceTypeConstants.js +189 -0
  46. package/lib/ModuleTypeConstants.js +1 -4
  47. package/lib/ModuleWarning.js +1 -1
  48. package/lib/MultiCompiler.js +1 -1
  49. package/lib/NodeStuffPlugin.js +424 -116
  50. package/lib/NormalModule.js +23 -20
  51. package/lib/NormalModuleFactory.js +7 -10
  52. package/lib/Parser.js +1 -1
  53. package/lib/RawModule.js +7 -4
  54. package/lib/RuntimeGlobals.js +22 -4
  55. package/lib/RuntimeModule.js +1 -1
  56. package/lib/RuntimePlugin.js +27 -6
  57. package/lib/RuntimeTemplate.js +120 -57
  58. package/lib/SourceMapDevToolPlugin.js +26 -1
  59. package/lib/Template.js +17 -6
  60. package/lib/TemplatedPathPlugin.js +5 -6
  61. package/lib/WebpackError.js +0 -1
  62. package/lib/WebpackOptionsApply.js +67 -15
  63. package/lib/asset/AssetBytesGenerator.js +16 -12
  64. package/lib/asset/AssetGenerator.js +31 -26
  65. package/lib/asset/AssetSourceGenerator.js +16 -12
  66. package/lib/asset/RawDataUrlModule.js +6 -3
  67. package/lib/buildChunkGraph.js +4 -2
  68. package/lib/cache/PackFileCacheStrategy.js +6 -5
  69. package/lib/cli.js +2 -43
  70. package/lib/config/browserslistTargetHandler.js +24 -0
  71. package/lib/config/defaults.js +226 -61
  72. package/lib/config/normalization.js +4 -3
  73. package/lib/config/target.js +11 -0
  74. package/lib/container/ContainerEntryModule.js +6 -3
  75. package/lib/container/FallbackModule.js +6 -3
  76. package/lib/container/RemoteModule.js +1 -3
  77. package/lib/css/CssGenerator.js +304 -76
  78. package/lib/css/CssLoadingRuntimeModule.js +14 -4
  79. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  80. package/lib/css/CssModulesPlugin.js +72 -67
  81. package/lib/css/CssParser.js +1726 -732
  82. package/lib/css/walkCssTokens.js +128 -11
  83. package/lib/dependencies/CachedConstDependency.js +24 -10
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  85. package/lib/dependencies/CommonJsPlugin.js +12 -0
  86. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  88. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +389 -12
  90. package/lib/dependencies/CssIcssImportDependency.js +114 -51
  91. package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
  92. package/lib/dependencies/CssImportDependency.js +17 -6
  93. package/lib/dependencies/CssUrlDependency.js +3 -2
  94. package/lib/dependencies/DynamicExports.js +7 -7
  95. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  96. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  97. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  98. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  99. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  100. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  101. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
  102. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
  103. package/lib/dependencies/HarmonyExports.js +4 -4
  104. package/lib/dependencies/HarmonyImportDependency.js +28 -27
  105. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  106. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  107. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  108. package/lib/dependencies/ImportDependency.js +8 -2
  109. package/lib/dependencies/ImportEagerDependency.js +6 -3
  110. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  111. package/lib/dependencies/ImportMetaPlugin.js +154 -9
  112. package/lib/dependencies/ImportParserPlugin.js +21 -23
  113. package/lib/dependencies/ImportPhase.js +121 -0
  114. package/lib/dependencies/ImportWeakDependency.js +6 -3
  115. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  116. package/lib/dependencies/ModuleDependency.js +5 -1
  117. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  118. package/lib/dependencies/WorkerPlugin.js +2 -2
  119. package/lib/dependencies/getFunctionExpression.js +1 -1
  120. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  121. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  122. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  123. package/lib/hmr/LazyCompilationPlugin.js +5 -3
  124. package/lib/ids/IdHelpers.js +20 -8
  125. package/lib/index.js +6 -0
  126. package/lib/javascript/ChunkHelpers.js +16 -5
  127. package/lib/javascript/JavascriptGenerator.js +105 -104
  128. package/lib/javascript/JavascriptModulesPlugin.js +80 -37
  129. package/lib/javascript/JavascriptParser.js +161 -44
  130. package/lib/json/JsonGenerator.js +5 -4
  131. package/lib/json/JsonParser.js +9 -2
  132. package/lib/library/AbstractLibraryPlugin.js +1 -1
  133. package/lib/library/AmdLibraryPlugin.js +4 -1
  134. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  135. package/lib/library/ModuleLibraryPlugin.js +41 -23
  136. package/lib/library/SystemLibraryPlugin.js +8 -1
  137. package/lib/library/UmdLibraryPlugin.js +2 -2
  138. package/lib/logging/Logger.js +5 -4
  139. package/lib/logging/createConsoleLogger.js +2 -2
  140. package/lib/node/NodeTargetPlugin.js +9 -1
  141. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  142. package/lib/optimize/ConcatenatedModule.js +208 -167
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  144. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  145. package/lib/optimize/SplitChunksPlugin.js +60 -46
  146. package/lib/rules/RuleSetCompiler.js +1 -1
  147. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  148. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  149. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  150. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  151. package/lib/schemes/HttpUriPlugin.js +78 -7
  152. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  153. package/lib/serialization/ObjectMiddleware.js +0 -2
  154. package/lib/serialization/SingleItemMiddleware.js +1 -1
  155. package/lib/sharing/ConsumeSharedModule.js +1 -1
  156. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  157. package/lib/sharing/ProvideSharedModule.js +1 -1
  158. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  159. package/lib/sharing/utils.js +1 -1
  160. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  161. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  162. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  163. package/lib/util/StringXor.js +1 -1
  164. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  165. package/lib/util/binarySearchBounds.js +2 -2
  166. package/lib/util/comparators.js +54 -76
  167. package/lib/util/compileBooleanMatcher.js +78 -6
  168. package/lib/util/createHash.js +20 -199
  169. package/lib/util/deprecation.js +1 -1
  170. package/lib/util/deterministicGrouping.js +6 -3
  171. package/lib/util/fs.js +75 -75
  172. package/lib/util/hash/BatchedHash.js +10 -9
  173. package/lib/util/hash/BulkUpdateHash.js +138 -0
  174. package/lib/util/hash/DebugHash.js +75 -0
  175. package/lib/util/hash/hash-digest.js +216 -0
  176. package/lib/util/identifier.js +82 -17
  177. package/lib/util/internalSerializables.js +2 -6
  178. package/lib/util/runtime.js +3 -3
  179. package/lib/util/source.js +2 -2
  180. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  181. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  182. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
  183. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  184. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
  185. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  186. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  187. package/lib/webpack.js +85 -82
  188. package/module.d.ts +5 -0
  189. package/package.json +34 -28
  190. package/schemas/WebpackOptions.check.js +1 -1
  191. package/schemas/WebpackOptions.json +160 -101
  192. package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
  193. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  194. package/schemas/plugins/ManifestPlugin.json +98 -0
  195. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  196. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  197. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  198. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  199. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  200. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  201. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  202. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  203. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  204. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  205. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  206. package/types.d.ts +771 -436
  207. package/lib/ModuleSourceTypesConstants.js +0 -123
  208. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  209. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
  210. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  211. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  212. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  213. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  214. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  215. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  216. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  217. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  218. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  219. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  220. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -10,16 +10,18 @@
10
10
  * @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url
11
11
  * @property {((input: string, start: number, end: number) => number)=} comment
12
12
  * @property {((input: string, start: number, end: number) => number)=} string
13
+ * @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
14
+ * @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
13
15
  * @property {((input: string, start: number, end: number) => number)=} leftParenthesis
14
16
  * @property {((input: string, start: number, end: number) => number)=} rightParenthesis
17
+ * @property {((input: string, start: number, end: number) => number)=} leftSquareBracket
18
+ * @property {((input: string, start: number, end: number) => number)=} rightSquareBracket
15
19
  * @property {((input: string, start: number, end: number) => number)=} function
16
20
  * @property {((input: string, start: number, end: number) => number)=} colon
17
21
  * @property {((input: string, start: number, end: number) => number)=} atKeyword
18
22
  * @property {((input: string, start: number, end: number) => number)=} delim
19
23
  * @property {((input: string, start: number, end: number) => number)=} identifier
20
24
  * @property {((input: string, start: number, end: number, isId: boolean) => number)=} hash
21
- * @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
22
- * @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
23
25
  * @property {((input: string, start: number, end: number) => number)=} semicolon
24
26
  * @property {((input: string, start: number, end: number) => number)=} comma
25
27
  * @property {(() => boolean)=} needTerminate
@@ -717,14 +719,22 @@ const consumeRightParenthesis = (input, pos, callbacks) => {
717
719
  };
718
720
 
719
721
  /** @type {CharHandler} */
720
- const consumeLeftSquareBracket = (input, pos, _callbacks) =>
722
+ const consumeLeftSquareBracket = (input, pos, callbacks) => {
721
723
  // Return a <]-token>.
722
- pos;
724
+ if (callbacks.leftSquareBracket !== undefined) {
725
+ return callbacks.leftSquareBracket(input, pos - 1, pos);
726
+ }
727
+ return pos;
728
+ };
723
729
 
724
730
  /** @type {CharHandler} */
725
- const consumeRightSquareBracket = (input, pos, _callbacks) =>
731
+ const consumeRightSquareBracket = (input, pos, callbacks) => {
726
732
  // Return a <]-token>.
727
- pos;
733
+ if (callbacks.rightSquareBracket !== undefined) {
734
+ return callbacks.rightSquareBracket(input, pos - 1, pos);
735
+ }
736
+ return pos;
737
+ };
728
738
 
729
739
  /** @type {CharHandler} */
730
740
  const consumeLeftCurlyBracket = (input, pos, callbacks) => {
@@ -1197,6 +1207,106 @@ module.exports = (input, pos = 0, callbacks = {}) => {
1197
1207
  return pos;
1198
1208
  };
1199
1209
 
1210
+ /**
1211
+ * @param {string} input input css
1212
+ * @param {number} pos pos
1213
+ * @param {CssTokenCallbacks} callbacks callbacks
1214
+ * @param {CssTokenCallbacks=} additional additional callbacks
1215
+ * @param {{ onlyTopLevel?: boolean, declarationValue?: boolean, atRulePrelude?: boolean, functionValue?: boolean }=} options options
1216
+ * @returns {number} pos
1217
+ */
1218
+ const consumeUntil = (input, pos, callbacks, additional, options = {}) => {
1219
+ let needHandle = true;
1220
+ let needTerminate = false;
1221
+
1222
+ /** @type {CssTokenCallbacks} */
1223
+ const servicedCallbacks = {};
1224
+
1225
+ let balanced = 0;
1226
+
1227
+ if (options.onlyTopLevel) {
1228
+ servicedCallbacks.function = (input, start, end) => {
1229
+ balanced++;
1230
+ if (!options.functionValue) {
1231
+ needHandle = false;
1232
+ }
1233
+
1234
+ if (additional && additional.function !== undefined) {
1235
+ return additional.function(input, start, end);
1236
+ }
1237
+
1238
+ return end;
1239
+ };
1240
+
1241
+ servicedCallbacks.leftParenthesis = (_input, _start, end) => {
1242
+ balanced++;
1243
+ needHandle = false;
1244
+ return end;
1245
+ };
1246
+ servicedCallbacks.rightParenthesis = (_input, _start, end) => {
1247
+ balanced--;
1248
+ if (balanced === 0) {
1249
+ needHandle = true;
1250
+ }
1251
+ return end;
1252
+ };
1253
+ }
1254
+
1255
+ if (options.declarationValue) {
1256
+ servicedCallbacks.semicolon = (_input, _start, end) => {
1257
+ needTerminate = true;
1258
+ return end;
1259
+ };
1260
+
1261
+ servicedCallbacks.rightCurlyBracket = (_input, _start, end) => {
1262
+ needTerminate = true;
1263
+ return end;
1264
+ };
1265
+ } else if (options.functionValue) {
1266
+ servicedCallbacks.rightParenthesis = (_input, _start, end) => {
1267
+ balanced--;
1268
+ if (balanced === 0) {
1269
+ needTerminate = true;
1270
+ }
1271
+ return end;
1272
+ };
1273
+ } else if (options.atRulePrelude) {
1274
+ servicedCallbacks.leftCurlyBracket = (_input, _start, end) => {
1275
+ needTerminate = true;
1276
+ return end;
1277
+ };
1278
+ servicedCallbacks.semicolon = (_input, _start, end) => {
1279
+ needTerminate = true;
1280
+ return end;
1281
+ };
1282
+ }
1283
+
1284
+ while (pos < input.length) {
1285
+ // Consume comments.
1286
+ pos = consumeComments(
1287
+ input,
1288
+ pos,
1289
+ needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
1290
+ );
1291
+
1292
+ const start = pos;
1293
+
1294
+ // Consume the next input code point.
1295
+ pos++;
1296
+ pos = consumeAToken(
1297
+ input,
1298
+ pos,
1299
+ needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
1300
+ );
1301
+
1302
+ if (needTerminate) {
1303
+ return start;
1304
+ }
1305
+ }
1306
+
1307
+ return pos;
1308
+ };
1309
+
1200
1310
  /**
1201
1311
  * @param {string} input input
1202
1312
  * @param {number} pos position
@@ -1230,13 +1340,18 @@ const eatWhitespace = (input, pos) => {
1230
1340
  /**
1231
1341
  * @param {string} input input
1232
1342
  * @param {number} pos position
1233
- * @returns {number} position after whitespace and comments
1343
+ * @returns {[number, boolean]} position after whitespace and comments
1234
1344
  */
1235
1345
  const eatWhitespaceAndComments = (input, pos) => {
1346
+ let foundWhitespace = false;
1347
+
1236
1348
  for (;;) {
1237
1349
  const originalPos = pos;
1238
1350
  pos = consumeComments(input, pos, {});
1239
1351
  while (_isWhiteSpace(input.charCodeAt(pos))) {
1352
+ if (!foundWhitespace) {
1353
+ foundWhitespace = true;
1354
+ }
1240
1355
  pos++;
1241
1356
  }
1242
1357
  if (originalPos === pos) {
@@ -1244,7 +1359,7 @@ const eatWhitespaceAndComments = (input, pos) => {
1244
1359
  }
1245
1360
  }
1246
1361
 
1247
- return pos;
1362
+ return [pos, foundWhitespace];
1248
1363
  };
1249
1364
 
1250
1365
  /**
@@ -1298,7 +1413,7 @@ const skipCommentsAndEatIdentSequence = (input, pos) => {
1298
1413
  * @returns {[number, number] | undefined} positions of ident sequence
1299
1414
  */
1300
1415
  const eatString = (input, pos) => {
1301
- pos = eatWhitespaceAndComments(input, pos);
1416
+ pos = eatWhitespaceAndComments(input, pos)[0];
1302
1417
 
1303
1418
  const start = pos;
1304
1419
 
@@ -1531,7 +1646,7 @@ const eatImportTokens = (input, pos, cbs) => {
1531
1646
  * @returns {[number, number] | undefined} positions of ident sequence
1532
1647
  */
1533
1648
  const eatIdentSequence = (input, pos) => {
1534
- pos = eatWhitespaceAndComments(input, pos);
1649
+ pos = eatWhitespaceAndComments(input, pos)[0];
1535
1650
 
1536
1651
  const start = pos;
1537
1652
 
@@ -1556,7 +1671,7 @@ const eatIdentSequence = (input, pos) => {
1556
1671
  * @returns {[number, number, boolean] | undefined} positions of ident sequence or string
1557
1672
  */
1558
1673
  const eatIdentSequenceOrString = (input, pos) => {
1559
- pos = eatWhitespaceAndComments(input, pos);
1674
+ pos = eatWhitespaceAndComments(input, pos)[0];
1560
1675
 
1561
1676
  const start = pos;
1562
1677
 
@@ -1608,6 +1723,7 @@ const eatUntil = (chars) => {
1608
1723
  };
1609
1724
  };
1610
1725
 
1726
+ module.exports.consumeUntil = consumeUntil;
1611
1727
  module.exports.eatComments = eatComments;
1612
1728
  module.exports.eatIdentSequence = eatIdentSequence;
1613
1729
  module.exports.eatIdentSequenceOrString = eatIdentSequenceOrString;
@@ -1619,5 +1735,6 @@ module.exports.eatWhiteLine = eatWhiteLine;
1619
1735
  module.exports.eatWhitespace = eatWhitespace;
1620
1736
  module.exports.eatWhitespaceAndComments = eatWhitespaceAndComments;
1621
1737
  module.exports.isIdentStartCodePoint = isIdentStartCodePoint;
1738
+ module.exports.isWhiteSpace = _isWhiteSpace;
1622
1739
  module.exports.skipCommentsAndEatIdentSequence =
1623
1740
  skipCommentsAndEatIdentSequence;
@@ -22,15 +22,22 @@ const NullDependency = require("./NullDependency");
22
22
  class CachedConstDependency extends NullDependency {
23
23
  /**
24
24
  * @param {string} expression expression
25
- * @param {Range} range range
25
+ * @param {Range | null} range range
26
26
  * @param {string} identifier identifier
27
+ * @param {number=} place place where we inject the expression
27
28
  */
28
- constructor(expression, range, identifier) {
29
+ constructor(
30
+ expression,
31
+ range,
32
+ identifier,
33
+ place = CachedConstDependency.PLACE_MODULE
34
+ ) {
29
35
  super();
30
36
 
31
37
  this.expression = expression;
32
38
  this.range = range;
33
39
  this.identifier = identifier;
40
+ this.place = place;
34
41
  this._hashUpdate = undefined;
35
42
  }
36
43
 
@@ -38,7 +45,7 @@ class CachedConstDependency extends NullDependency {
38
45
  * @returns {string} hash update
39
46
  */
40
47
  _createHashUpdate() {
41
- return `${this.identifier}${this.range}${this.expression}`;
48
+ return `${this.place}${this.identifier}${this.range}${this.expression}`;
42
49
  }
43
50
 
44
51
  /**
@@ -63,6 +70,7 @@ class CachedConstDependency extends NullDependency {
63
70
  write(this.expression);
64
71
  write(this.range);
65
72
  write(this.identifier);
73
+ write(this.place);
66
74
 
67
75
  super.serialize(context);
68
76
  }
@@ -76,11 +84,15 @@ class CachedConstDependency extends NullDependency {
76
84
  this.expression = read();
77
85
  this.range = read();
78
86
  this.identifier = read();
87
+ this.place = read();
79
88
 
80
89
  super.deserialize(context);
81
90
  }
82
91
  }
83
92
 
93
+ CachedConstDependency.PLACE_MODULE = 10;
94
+ CachedConstDependency.PLACE_CHUNK = 20;
95
+
84
96
  makeSerializable(
85
97
  CachedConstDependency,
86
98
  "webpack/lib/dependencies/CachedConstDependency"
@@ -95,25 +107,27 @@ CachedConstDependency.Template = class CachedConstDependencyTemplate extends (
95
107
  * @param {DependencyTemplateContext} templateContext the context object
96
108
  * @returns {void}
97
109
  */
98
- apply(dependency, source, { initFragments }) {
110
+ apply(dependency, source, { initFragments, chunkInitFragments }) {
99
111
  const dep = /** @type {CachedConstDependency} */ (dependency);
100
112
 
101
- initFragments.push(
113
+ (dep.place === CachedConstDependency.PLACE_MODULE
114
+ ? initFragments
115
+ : chunkInitFragments
116
+ ).push(
102
117
  new InitFragment(
103
118
  `var ${dep.identifier} = ${dep.expression};\n`,
104
119
  InitFragment.STAGE_CONSTANTS,
105
- 0,
120
+ // For a chunk we inject expression after imports
121
+ dep.place === CachedConstDependency.PLACE_MODULE ? 0 : 10,
106
122
  `const ${dep.identifier}`
107
123
  )
108
124
  );
109
125
 
110
126
  if (typeof dep.range === "number") {
111
127
  source.insert(dep.range, dep.identifier);
112
-
113
- return;
128
+ } else if (dep.range !== null) {
129
+ source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
114
130
  }
115
-
116
- source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
117
131
  }
118
132
  };
119
133
 
@@ -126,15 +126,6 @@ class CommonJsImportsParserPlugin {
126
126
  });
127
127
 
128
128
  // #region Unsupported
129
- parser.hooks.expression
130
- .for("require.main")
131
- .tap(
132
- PLUGIN_NAME,
133
- expressionIsUnsupported(
134
- parser,
135
- "require.main is not supported by webpack."
136
- )
137
- );
138
129
  parser.hooks.call
139
130
  .for("require.main.require")
140
131
  .tap(
@@ -15,6 +15,7 @@ const SelfModuleFactory = require("../SelfModuleFactory");
15
15
  const Template = require("../Template");
16
16
  const {
17
17
  evaluateToIdentifier,
18
+ expressionIsUnsupported,
18
19
  toConstantDependency
19
20
  } = require("../javascript/JavascriptParserHelpers");
20
21
  const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
@@ -198,6 +199,17 @@ class CommonJsPlugin {
198
199
  [RuntimeGlobals.moduleCache, RuntimeGlobals.entryModuleId]
199
200
  )
200
201
  );
202
+
203
+ parser.hooks.expression
204
+ .for("require.extensions")
205
+ .tap(
206
+ PLUGIN_NAME,
207
+ expressionIsUnsupported(
208
+ parser,
209
+ "require.extensions is not supported by webpack. Use a loader instead."
210
+ )
211
+ );
212
+
201
213
  parser.hooks.expression
202
214
  .for(RuntimeGlobals.moduleLoaded)
203
215
  .tap(PLUGIN_NAME, (expr) => {
@@ -19,7 +19,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
19
19
  * @param {ContextDependencyOptions} options options for the context module
20
20
  * @param {Range} range location in source code
21
21
  * @param {Range | undefined} valueRange location of the require call
22
- * @param {boolean | string } inShorthand true or name
22
+ * @param {boolean | string} inShorthand true or name
23
23
  * @param {string=} context context
24
24
  */
25
25
  constructor(options, range, valueRange, inShorthand, context) {
@@ -42,14 +42,14 @@ const splitContextFromPrefix = (prefix) => {
42
42
  };
43
43
 
44
44
  /** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
45
- /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: any[]): ContextDependency }} ContextDependencyConstructor */
45
+ /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: EXPECTED_ANY[]): ContextDependency }} ContextDependencyConstructor */
46
46
 
47
47
  /**
48
48
  * @param {ContextDependencyConstructor} Dep the Dependency class
49
49
  * @param {Range} range source range
50
50
  * @param {BasicEvaluatedExpression} param context param
51
51
  * @param {Expression} expr expr
52
- * @param {Pick<JavascriptParserOptions, `${"expr"|"wrapped"}Context${"Critical"|"Recursive"|"RegExp"}` | "exprContextRequest">} options options for context creation
52
+ * @param {Pick<JavascriptParserOptions, `${"expr" | "wrapped"}Context${"Critical" | "Recursive" | "RegExp"}` | "exprContextRequest">} options options for context creation
53
53
  * @param {PartialContextDependencyOptions} contextOptions options for the ContextModule
54
54
  * @param {JavascriptParser} parser the parser
55
55
  * @param {...EXPECTED_ANY} depArgs depArgs
@@ -12,7 +12,9 @@ const ContextDependency = require("./ContextDependency");
12
12
  /** @typedef {import("../Dependency")} Dependency */
13
13
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
14
14
 
15
- class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template {
15
+ class ContextDependencyTemplateAsRequireCall
16
+ extends ContextDependency.Template
17
+ {
16
18
  /**
17
19
  * @param {Dependency} dependency the dependency for which the template should be applied
18
20
  * @param {ReplaceSource} source the current replace source which can be modified