webpack 5.106.2 → 5.107.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 +2 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/Cache.js +3 -6
  4. package/lib/CompatibilityPlugin.js +8 -7
  5. package/lib/Compilation.js +34 -26
  6. package/lib/Compiler.js +4 -13
  7. package/lib/ContextModule.js +2 -2
  8. package/lib/DefinePlugin.js +2 -2
  9. package/lib/Dependency.js +22 -1
  10. package/lib/DependencyTemplate.js +2 -1
  11. package/lib/EnvironmentPlugin.js +1 -1
  12. package/lib/EvalSourceMapDevToolPlugin.js +8 -9
  13. package/lib/ExternalModule.js +76 -15
  14. package/lib/ExternalModuleFactoryPlugin.js +5 -0
  15. package/lib/FileSystemInfo.js +187 -72
  16. package/lib/Generator.js +3 -3
  17. package/lib/HotModuleReplacementPlugin.js +26 -8
  18. package/lib/IgnorePlugin.js +2 -1
  19. package/lib/Module.js +19 -18
  20. package/lib/ModuleFactory.js +1 -1
  21. package/lib/ModuleSourceTypeConstants.js +31 -1
  22. package/lib/ModuleTypeConstants.js +12 -3
  23. package/lib/MultiCompiler.js +2 -2
  24. package/lib/NodeStuffPlugin.js +1 -1
  25. package/lib/NormalModule.js +13 -31
  26. package/lib/NormalModuleFactory.js +10 -2
  27. package/lib/Parser.js +1 -1
  28. package/lib/ProgressPlugin.js +129 -56
  29. package/lib/RuntimeGlobals.js +5 -5
  30. package/lib/RuntimeModule.js +9 -7
  31. package/lib/RuntimePlugin.js +11 -0
  32. package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
  33. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  34. package/lib/WarnNoModeSetPlugin.js +16 -1
  35. package/lib/Watching.js +2 -3
  36. package/lib/WebpackError.js +3 -77
  37. package/lib/WebpackIsIncludedPlugin.js +1 -1
  38. package/lib/WebpackOptionsApply.js +13 -1
  39. package/lib/asset/AssetBytesGenerator.js +6 -2
  40. package/lib/asset/AssetGenerator.js +22 -8
  41. package/lib/asset/AssetModulesPlugin.js +3 -1
  42. package/lib/asset/AssetSourceGenerator.js +6 -2
  43. package/lib/buildChunkGraph.js +4 -6
  44. package/lib/cache/PackFileCacheStrategy.js +4 -4
  45. package/lib/cli.js +3 -1
  46. package/lib/config/defaults.js +197 -10
  47. package/lib/config/normalization.js +3 -1
  48. package/lib/css/CssGenerator.js +320 -105
  49. package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
  50. package/lib/css/CssLoadingRuntimeModule.js +22 -4
  51. package/lib/{CssModule.js → css/CssModule.js} +15 -15
  52. package/lib/css/CssModulesPlugin.js +166 -86
  53. package/lib/css/CssParser.js +566 -269
  54. package/lib/css/walkCssTokens.js +148 -2
  55. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
  56. package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
  57. package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
  58. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  59. package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
  60. package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -3
  61. package/lib/dependencies/CommonJsRequireDependency.js +67 -4
  62. package/lib/dependencies/ContextDependency.js +1 -1
  63. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  64. package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
  65. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  66. package/lib/dependencies/CssIcssExportDependency.js +332 -67
  67. package/lib/dependencies/CssIcssImportDependency.js +49 -7
  68. package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
  69. package/lib/dependencies/CssImportDependency.js +8 -0
  70. package/lib/dependencies/CssUrlDependency.js +25 -0
  71. package/lib/dependencies/HarmonyDetectionParserPlugin.js +1 -1
  72. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
  73. package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
  74. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
  75. package/lib/dependencies/HarmonyImportDependency.js +10 -2
  76. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
  77. package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
  78. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
  79. package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
  80. package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
  81. package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
  82. package/lib/dependencies/HtmlSourceDependency.js +127 -0
  83. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  84. package/lib/dependencies/ImportParserPlugin.js +2 -2
  85. package/lib/dependencies/ImportPhase.js +1 -1
  86. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
  87. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
  88. package/lib/dependencies/SystemPlugin.js +1 -1
  89. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  90. package/lib/dependencies/WorkerPlugin.js +2 -2
  91. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
  92. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
  93. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
  94. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
  95. package/lib/{DllModule.js → dll/DllModule.js} +24 -24
  96. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
  97. package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
  98. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
  99. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
  100. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
  101. package/lib/errors/BuildCycleError.js +1 -1
  102. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  103. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  104. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
  105. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
  106. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
  107. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
  108. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
  109. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
  110. package/lib/errors/JSONParseError.js +114 -0
  111. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
  112. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
  113. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
  114. package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
  115. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
  116. package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +2 -2
  117. package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
  118. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
  119. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
  120. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
  121. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
  122. package/lib/errors/NonErrorEmittedError.js +28 -0
  123. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
  124. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
  125. package/lib/errors/WebpackError.js +84 -0
  126. package/lib/html/HtmlGenerator.js +379 -0
  127. package/lib/html/HtmlModulesPlugin.js +433 -0
  128. package/lib/html/HtmlParser.js +1489 -0
  129. package/lib/html/walkHtmlTokens.js +2733 -0
  130. package/lib/ids/IdHelpers.js +2 -1
  131. package/lib/index.js +34 -15
  132. package/lib/javascript/JavascriptModulesPlugin.js +89 -8
  133. package/lib/javascript/JavascriptParser.js +197 -16
  134. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  135. package/lib/json/JsonParser.js +7 -16
  136. package/lib/library/AbstractLibraryPlugin.js +1 -1
  137. package/lib/library/EnableLibraryPlugin.js +1 -1
  138. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
  139. package/lib/library/ModuleLibraryPlugin.js +74 -0
  140. package/lib/node/NodeEnvironmentPlugin.js +4 -2
  141. package/lib/node/nodeConsole.js +113 -64
  142. package/lib/optimize/ConcatenatedModule.js +51 -6
  143. package/lib/optimize/InnerGraph.js +1 -1
  144. package/lib/optimize/InnerGraphPlugin.js +11 -1
  145. package/lib/optimize/MinMaxSizeWarning.js +4 -4
  146. package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
  147. package/lib/optimize/RealContentHashPlugin.js +89 -26
  148. package/lib/optimize/SideEffectsFlagPlugin.js +111 -3
  149. package/lib/optimize/SplitChunksPlugin.js +1 -1
  150. package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
  151. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  152. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  153. package/lib/performance/SizeLimitsPlugin.js +1 -1
  154. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
  155. package/lib/rules/UseEffectRulePlugin.js +4 -3
  156. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
  157. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
  158. package/lib/schemes/DataUriPlugin.js +13 -1
  159. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  160. package/lib/serialization/SerializerMiddleware.js +2 -2
  161. package/lib/sharing/ConsumeSharedPlugin.js +2 -2
  162. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  163. package/lib/sharing/ProvideSharedModule.js +1 -1
  164. package/lib/sharing/ProvideSharedPlugin.js +1 -1
  165. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  166. package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
  167. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  168. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  169. package/lib/stats/StatsFactory.js +1 -1
  170. package/lib/typescript/TypeScriptPlugin.js +210 -0
  171. package/lib/url/URLParserPlugin.js +2 -2
  172. package/lib/util/AsyncQueue.js +2 -2
  173. package/lib/util/Hash.js +2 -2
  174. package/lib/util/LocConverter.js +53 -0
  175. package/lib/util/SortableSet.js +1 -1
  176. package/lib/util/cleverMerge.js +2 -2
  177. package/lib/util/comparators.js +3 -3
  178. package/lib/util/concatenate.js +3 -3
  179. package/lib/util/conventions.js +42 -1
  180. package/lib/util/createMappings.js +118 -0
  181. package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
  182. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
  183. package/lib/util/fs.js +8 -8
  184. package/lib/util/hash/md4.js +1 -1
  185. package/lib/util/hash/xxhash64.js +1 -1
  186. package/lib/util/identifier.js +48 -0
  187. package/lib/util/internalSerializables.js +35 -19
  188. package/lib/util/magicComment.js +10 -7
  189. package/lib/util/parseJson.js +2 -73
  190. package/lib/util/source.js +21 -0
  191. package/lib/util/topologicalSort.js +69 -0
  192. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
  193. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  194. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
  195. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
  196. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
  197. package/lib/webpack.js +3 -1
  198. package/package.json +22 -20
  199. package/schemas/WebpackOptions.check.js +1 -1
  200. package/schemas/WebpackOptions.json +118 -3
  201. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  202. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  203. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  204. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  205. package/schemas/plugins/ProgressPlugin.json +22 -0
  206. package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
  207. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  208. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  209. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  210. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  211. package/types.d.ts +810 -101
  212. package/lib/CaseSensitiveModulesWarning.js +0 -80
  213. package/lib/GraphHelpers.js +0 -49
  214. package/lib/NoModeWarning.js +0 -23
  215. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
  216. /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
  217. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  218. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  219. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  220. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
package/README.md CHANGED
@@ -302,12 +302,12 @@ For information about the governance of the webpack project, see [GOVERNANCE.md]
302
302
 
303
303
  - [alexander-akait](https://github.com/alexander-akait) -
304
304
  **Alexander Akait** <<sheo13666q@gmail.com>> (he/him)
305
+ - [avivkeller](https://github.com/avivkeller) -
306
+ **Aviv Keller** <<me@aviv.sh>> (he/him)
305
307
  - [evenstensberg](https://github.com/evenstensberg) -
306
308
  **Even Stensberg** <<evenstensberg@gmail.com>> (he/him)
307
309
  - [ovflowd](https://github.com/ovflowd) -
308
310
  **Claudio Wunder** <<cwunder@gnome.org>> (he/they)
309
- - [snitin315](https://github.com/snitin315) -
310
- **Nitin Kumar** <<snitin315@gmail.com>> (he/him)
311
311
  - [thelarkinn](https://github.com/thelarkinn) -
312
312
  **Sean Larkin** <<selarkin@microsoft.com>> (he/him)
313
313
 
package/lib/APIPlugin.js CHANGED
@@ -14,10 +14,10 @@ const {
14
14
  JAVASCRIPT_MODULE_TYPE_ESM
15
15
  } = require("./ModuleTypeConstants");
16
16
  const RuntimeGlobals = require("./RuntimeGlobals");
17
- const WebpackError = require("./WebpackError");
18
17
  const ConstDependency = require("./dependencies/ConstDependency");
19
18
  const ModuleInitFragmentDependency = require("./dependencies/ModuleInitFragmentDependency");
20
19
  const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency");
20
+ const WebpackError = require("./errors/WebpackError");
21
21
  const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
22
22
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
23
23
  const {
package/lib/Cache.js CHANGED
@@ -9,9 +9,7 @@ const { AsyncParallelHook, AsyncSeriesBailHook, SyncHook } = require("tapable");
9
9
  const {
10
10
  makeWebpackError,
11
11
  makeWebpackErrorCallback
12
- } = require("./HookWebpackError");
13
-
14
- /** @typedef {import("./WebpackError")} WebpackError */
12
+ } = require("./errors/HookWebpackError");
15
13
 
16
14
  /**
17
15
  * Cache validation token whose string representation identifies the build
@@ -21,11 +19,10 @@ const {
21
19
  */
22
20
 
23
21
  /**
24
- * Completion callback used by cache operations that either fail with a
25
- * `WebpackError` or resolve with a typed result.
22
+ * Completion callback used by cache operations that either fail with a `Error` or resolve with a typed result.
26
23
  * @template T
27
24
  * @callback CallbackCache
28
- * @param {WebpackError | null} err
25
+ * @param {Error | null} err
29
26
  * @param {T=} result
30
27
  * @returns {void}
31
28
  */
@@ -186,13 +186,14 @@ class CompatibilityPlugin {
186
186
  (declarator.id.name === RuntimeGlobals.exports ||
187
187
  declarator.id.name === RuntimeGlobals.require)
188
188
  ) {
189
- const { name, declaration } =
190
- /** @type {CompatibilitySettings} */ (
191
- parser.getTagData(
192
- declarator.id.name,
193
- nestedWebpackIdentifierTag
194
- )
195
- );
189
+ const tagData = /** @type {CompatibilitySettings | undefined} */ (
190
+ parser.getTagData(
191
+ declarator.id.name,
192
+ nestedWebpackIdentifierTag
193
+ )
194
+ );
195
+ if (!tagData) return;
196
+ const { name, declaration } = tagData;
196
197
  if (!declaration.updated) {
197
198
  const dep = new ConstDependency(name, declaration.range);
198
199
  dep.loc = declaration.loc;
@@ -21,42 +21,37 @@ const { MultiItemCache } = require("./CacheFacade");
21
21
  const Chunk = require("./Chunk");
22
22
  const ChunkGraph = require("./ChunkGraph");
23
23
  const ChunkGroup = require("./ChunkGroup");
24
- const ChunkRenderError = require("./ChunkRenderError");
25
24
  const ChunkTemplate = require("./ChunkTemplate");
26
- const CodeGenerationError = require("./CodeGenerationError");
27
25
  const CodeGenerationResults = require("./CodeGenerationResults");
28
26
  const Dependency = require("./Dependency");
29
27
  const DependencyTemplates = require("./DependencyTemplates");
30
28
  const Entrypoint = require("./Entrypoint");
31
29
  const ErrorHelpers = require("./ErrorHelpers");
32
30
  const FileSystemInfo = require("./FileSystemInfo");
33
- const {
34
- connectChunkGroupAndChunk,
35
- connectChunkGroupParentAndChild,
36
- connectEntrypointAndDependOn
37
- } = require("./GraphHelpers");
38
- const {
39
- makeWebpackError,
40
- tryRunOrWebpackError
41
- } = require("./HookWebpackError");
42
31
  const MainTemplate = require("./MainTemplate");
43
32
  const Module = require("./Module");
44
- const ModuleDependencyError = require("./ModuleDependencyError");
45
- const ModuleDependencyWarning = require("./ModuleDependencyWarning");
46
33
  const ModuleGraph = require("./ModuleGraph");
47
- const ModuleHashingError = require("./ModuleHashingError");
48
- const ModuleNotFoundError = require("./ModuleNotFoundError");
49
34
  const ModuleProfile = require("./ModuleProfile");
50
- const ModuleRestoreError = require("./ModuleRestoreError");
51
- const ModuleStoreError = require("./ModuleStoreError");
52
35
  const ModuleTemplate = require("./ModuleTemplate");
53
36
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
54
37
  const RuntimeGlobals = require("./RuntimeGlobals");
55
38
  const RuntimeTemplate = require("./RuntimeTemplate");
56
39
  const Stats = require("./Stats");
57
- const WebpackError = require("./WebpackError");
58
40
  const buildChunkGraph = require("./buildChunkGraph");
59
41
  const BuildCycleError = require("./errors/BuildCycleError");
42
+ const ChunkRenderError = require("./errors/ChunkRenderError");
43
+ const CodeGenerationError = require("./errors/CodeGenerationError");
44
+ const {
45
+ makeWebpackError,
46
+ tryRunOrWebpackError
47
+ } = require("./errors/HookWebpackError");
48
+ const ModuleDependencyError = require("./errors/ModuleDependencyError");
49
+ const ModuleDependencyWarning = require("./errors/ModuleDependencyWarning");
50
+ const ModuleHashingError = require("./errors/ModuleHashingError");
51
+ const ModuleNotFoundError = require("./errors/ModuleNotFoundError");
52
+ const ModuleRestoreError = require("./errors/ModuleRestoreError");
53
+ const ModuleStoreError = require("./errors/ModuleStoreError");
54
+ const WebpackError = require("./errors/WebpackError");
60
55
  const { LogType, Logger } = require("./logging/Logger");
61
56
  const StatsFactory = require("./stats/StatsFactory");
62
57
  const StatsPrinter = require("./stats/StatsPrinter");
@@ -3214,7 +3209,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3214
3209
  let hasProblems = this.reportDependencyErrorsAndWarnings(module, [
3215
3210
  module
3216
3211
  ]);
3217
- const errors = module.getErrors();
3212
+ const errors = /** @type {WebpackError[]} */ (module.getErrors());
3218
3213
  if (errors !== undefined) {
3219
3214
  for (const error of errors) {
3220
3215
  if (!error.module) {
@@ -3224,7 +3219,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3224
3219
  hasProblems = true;
3225
3220
  }
3226
3221
  }
3227
- const warnings = module.getWarnings();
3222
+ const warnings = /** @type {WebpackError[]} */ (module.getWarnings());
3228
3223
  if (warnings !== undefined) {
3229
3224
  for (const warning of warnings) {
3230
3225
  if (!warning.module) {
@@ -3312,7 +3307,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3312
3307
  this.namedChunkGroups.set(name, entrypoint);
3313
3308
  this.entrypoints.set(name, entrypoint);
3314
3309
  this.chunkGroups.push(entrypoint);
3315
- connectChunkGroupAndChunk(entrypoint, chunk);
3310
+
3311
+ if (entrypoint.pushChunk(chunk)) {
3312
+ chunk.addGroup(entrypoint);
3313
+ }
3316
3314
 
3317
3315
  /** @type {Set<Module>} */
3318
3316
  const entryModules = new Set();
@@ -3403,8 +3401,12 @@ Remove the 'runtime' option from the entrypoint.`);
3403
3401
  entry.setRuntimeChunk(entryChunk);
3404
3402
  continue outer;
3405
3403
  }
3406
- connectEntrypointAndDependOn(entry, dependency);
3407
- connectChunkGroupParentAndChild(dependency, entry);
3404
+
3405
+ entry.addDependOn(dependency);
3406
+
3407
+ if (dependency.addChild(entry)) {
3408
+ entry.addParent(dependency);
3409
+ }
3408
3410
  }
3409
3411
  } else if (runtime) {
3410
3412
  const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
@@ -4156,7 +4158,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4156
4158
  }
4157
4159
  const chunk = this.addChunk(name);
4158
4160
 
4159
- connectChunkGroupAndChunk(chunkGroup, chunk);
4161
+ if (chunkGroup.pushChunk(chunk)) {
4162
+ chunk.addGroup(chunkGroup);
4163
+ }
4160
4164
 
4161
4165
  this.chunkGroups.push(chunkGroup);
4162
4166
  if (name) {
@@ -4200,7 +4204,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4200
4204
  }
4201
4205
  this.chunkGroups.push(entrypoint);
4202
4206
  this.asyncEntrypoints.push(entrypoint);
4203
- connectChunkGroupAndChunk(entrypoint, chunk);
4207
+ if (entrypoint.pushChunk(chunk)) {
4208
+ chunk.addGroup(entrypoint);
4209
+ }
4204
4210
  if (module) {
4205
4211
  entrypoint.addOrigin(module, loc, request);
4206
4212
  }
@@ -5493,7 +5499,9 @@ This prevents using hashes of each other and should be avoided.`);
5493
5499
  ...options.entryOptions
5494
5500
  });
5495
5501
  chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
5496
- connectChunkGroupAndChunk(entrypoint, chunk);
5502
+ if (entrypoint.pushChunk(chunk)) {
5503
+ chunk.addGroup(entrypoint);
5504
+ }
5497
5505
  entrypoint.setRuntimeChunk(chunk);
5498
5506
  entrypoint.setEntrypointChunk(chunk);
5499
5507
 
package/lib/Compiler.js CHANGED
@@ -17,7 +17,6 @@ const Cache = require("./Cache");
17
17
  const CacheFacade = require("./CacheFacade");
18
18
  const ChunkGraph = require("./ChunkGraph");
19
19
  const Compilation = require("./Compilation");
20
- const ConcurrentCompilationError = require("./ConcurrentCompilationError");
21
20
  const ContextModuleFactory = require("./ContextModuleFactory");
22
21
  const ModuleGraph = require("./ModuleGraph");
23
22
  const NormalModuleFactory = require("./NormalModuleFactory");
@@ -25,7 +24,8 @@ const RequestShortener = require("./RequestShortener");
25
24
  const ResolverFactory = require("./ResolverFactory");
26
25
  const Stats = require("./Stats");
27
26
  const Watching = require("./Watching");
28
- const WebpackError = require("./WebpackError");
27
+ const ConcurrentCompilationError = require("./errors/ConcurrentCompilationError");
28
+ const WebpackError = require("./errors/WebpackError");
29
29
  const { Logger } = require("./logging/Logger");
30
30
  const { dirname, join, mkdirp } = require("./util/fs");
31
31
  const { makePathsRelative } = require("./util/identifier");
@@ -1477,12 +1477,7 @@ ${other}`);
1477
1477
  // // If we have precompiled schema let's use it
1478
1478
  if (check) {
1479
1479
  if (!check(value)) {
1480
- getValidate()(
1481
- getSchema(),
1482
- /** @type {EXPECTED_OBJECT | EXPECTED_OBJECT[]} */
1483
- (value),
1484
- options
1485
- );
1480
+ getValidate()(getSchema(), value, options);
1486
1481
  require("util").deprecate(
1487
1482
  () => {},
1488
1483
  "webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
@@ -1493,11 +1488,7 @@ ${other}`);
1493
1488
  }
1494
1489
 
1495
1490
  // Otherwise let's standard validation
1496
- getValidate()(
1497
- getSchema(),
1498
- /** @type {EXPECTED_OBJECT | EXPECTED_OBJECT[]} */ (value),
1499
- options
1500
- );
1491
+ getValidate()(getSchema(), value, options);
1501
1492
  }
1502
1493
  }
1503
1494
 
@@ -7,7 +7,6 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
10
- const { makeWebpackError } = require("./HookWebpackError");
11
10
  const Module = require("./Module");
12
11
  const {
13
12
  JAVASCRIPT_TYPE,
@@ -16,11 +15,12 @@ const {
16
15
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
17
16
  const RuntimeGlobals = require("./RuntimeGlobals");
18
17
  const Template = require("./Template");
19
- const WebpackError = require("./WebpackError");
20
18
  const {
21
19
  getOutgoingAsyncModules
22
20
  } = require("./async-modules/AsyncModuleHelpers");
23
21
  const { ImportPhase, ImportPhaseUtils } = require("./dependencies/ImportPhase");
22
+ const { makeWebpackError } = require("./errors/HookWebpackError");
23
+ const WebpackError = require("./errors/WebpackError");
24
24
  const {
25
25
  compareLocations,
26
26
  compareModulesById,
@@ -12,8 +12,8 @@ const {
12
12
  JAVASCRIPT_MODULE_TYPE_ESM
13
13
  } = require("./ModuleTypeConstants");
14
14
  const RuntimeGlobals = require("./RuntimeGlobals");
15
- const WebpackError = require("./WebpackError");
16
15
  const ConstDependency = require("./dependencies/ConstDependency");
16
+ const WebpackError = require("./errors/WebpackError");
17
17
  const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
18
18
  const { VariableInfo } = require("./javascript/JavascriptParser");
19
19
  const {
@@ -319,7 +319,7 @@ const toCacheVersion = (code) => {
319
319
  const items = Object.keys(code).map((key) => ({
320
320
  key,
321
321
  value: toCacheVersion(
322
- /** @type {Record<string, EXPECTED_ANY>} */
322
+ /** @type {Record<string, CodeValue>} */
323
323
  (code)[key]
324
324
  )
325
325
  }));
package/lib/Dependency.js CHANGED
@@ -14,7 +14,7 @@ const memoize = require("./util/memoize");
14
14
  /** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
15
15
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
16
16
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
17
- /** @typedef {import("./WebpackError")} WebpackError */
17
+ /** @typedef {import("./errors/WebpackError")} WebpackError */
18
18
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
19
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
20
  /** @typedef {import("./util/Hash")} Hash */
@@ -325,6 +325,14 @@ class Dependency {
325
325
  return getIgnoredModule();
326
326
  }
327
327
 
328
+ /**
329
+ * Returns true if this dependency can be concatenated
330
+ * @returns {boolean} true if this dependency can be concatenated
331
+ */
332
+ canConcatenate() {
333
+ return false;
334
+ }
335
+
328
336
  /**
329
337
  * Serializes this instance into the provided serializer context.
330
338
  * @param {ObjectSerializerContext} context context
@@ -394,6 +402,19 @@ Object.defineProperty(Dependency.prototype, "module", {
394
402
  Dependency.isLowPriorityDependency = (dependency) =>
395
403
  /** @type {ModuleDependency} */ (dependency).sourceOrder === Infinity;
396
404
 
405
+ // TODO in webpack 6, call canConcatenate() directly on the dependency instance instead of using this static method.
406
+ /**
407
+ * Returns true if the dependency can be concatenated (scope hoisting).
408
+ * @param {Dependency} dependency dep
409
+ * @returns {boolean} true if this dependency supports concatenation
410
+ */
411
+ Dependency.canConcatenate = (dependency) => {
412
+ if (typeof dependency.canConcatenate === "function") {
413
+ return dependency.canConcatenate();
414
+ }
415
+ return false;
416
+ };
417
+
397
418
  // TODO remove in webpack 6
398
419
  Object.defineProperty(Dependency.prototype, "disconnect", {
399
420
  /**
@@ -52,6 +52,7 @@
52
52
  * @typedef {object} CssData
53
53
  * @property {boolean} esModule whether export __esModule
54
54
  * @property {Map<string, string>} exports the css exports
55
+ * @property {Map<string, { line: number, column: number }>=} exportLocs source position (line is 1-based, column is 0-based) of each export's defining identifier in the original CSS, used to emit fine-grained JS-to-CSS source mappings
55
56
  */
56
57
 
57
58
  /** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
@@ -67,7 +68,7 @@ class DependencyTemplate {
67
68
  * @returns {void}
68
69
  */
69
70
  apply(dependency, source, templateContext) {
70
- const AbstractMethodError = require("./AbstractMethodError");
71
+ const AbstractMethodError = require("./errors/AbstractMethodError");
71
72
 
72
73
  throw new AbstractMethodError();
73
74
  }
@@ -6,7 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const DefinePlugin = require("./DefinePlugin");
9
- const WebpackError = require("./WebpackError");
9
+ const WebpackError = require("./errors/WebpackError");
10
10
 
11
11
  /** @typedef {import("./Compiler")} Compiler */
12
12
  /** @typedef {import("./DefinePlugin").CodeValue} CodeValue */
@@ -103,17 +103,12 @@ class EvalSourceMapDevToolPlugin {
103
103
  };
104
104
 
105
105
  if (m instanceof NormalModule) {
106
- const module = /** @type {NormalModule} */ (m);
107
- if (!matchModule(module.resource)) {
106
+ if (!matchModule(m.resource)) {
108
107
  return result(source);
109
108
  }
110
109
  } else if (m instanceof ConcatenatedModule) {
111
- const concatModule = /** @type {ConcatenatedModule} */ (m);
112
- if (concatModule.rootModule instanceof NormalModule) {
113
- const module = /** @type {NormalModule} */ (
114
- concatModule.rootModule
115
- );
116
- if (!matchModule(module.resource)) {
110
+ if (m.rootModule instanceof NormalModule) {
111
+ if (!matchModule(m.rootModule.resource)) {
117
112
  return result(source);
118
113
  }
119
114
  } else {
@@ -146,9 +141,13 @@ class EvalSourceMapDevToolPlugin {
146
141
  sourceMap = { ...sourceMap };
147
142
  const context = compiler.context;
148
143
  const root = compiler.root;
144
+ const cachedAbsolutify = makePathsAbsolute.bindContextCache(
145
+ context,
146
+ root
147
+ );
149
148
  const modules = sourceMap.sources.map((source) => {
150
149
  if (!source.startsWith("webpack://")) return source;
151
- source = makePathsAbsolute(context, source.slice(10), root);
150
+ source = cachedAbsolutify(source.slice(10));
152
151
  const module = compilation.findModule(source);
153
152
  return module || source;
154
153
  });
@@ -8,7 +8,6 @@
8
8
  const { SyncBailHook } = require("tapable");
9
9
  const { OriginalSource, RawSource } = require("webpack-sources");
10
10
  const ConcatenationScope = require("./ConcatenationScope");
11
- const EnvironmentNotSupportAsyncWarning = require("./EnvironmentNotSupportAsyncWarning");
12
11
  const { UsageState } = require("./ExportsInfo");
13
12
  const InitFragment = require("./InitFragment");
14
13
  const Module = require("./Module");
@@ -22,7 +21,9 @@ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
22
21
  const RuntimeGlobals = require("./RuntimeGlobals");
23
22
  const Template = require("./Template");
24
23
  const { DEFAULTS } = require("./config/defaults");
24
+ const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
25
25
  const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
26
+ const EnvironmentNotSupportAsyncWarning = require("./errors/EnvironmentNotSupportAsyncWarning");
26
27
  const createHash = require("./util/createHash");
27
28
  const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
28
29
  const makeSerializable = require("./util/makeSerializable");
@@ -62,13 +63,14 @@ const { register } = require("./util/serialization");
62
63
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
63
64
  /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
64
65
  /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
66
+ /** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
65
67
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
66
68
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
67
69
  /** @typedef {import("./util/Hash")} Hash */
68
70
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
69
71
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
70
72
 
71
- /** @typedef {{ attributes?: ImportAttributes, externalType: "import" | "module" | undefined }} ImportDependencyMeta */
73
+ /** @typedef {{ attributes?: ImportAttributes, phase?: ImportPhaseType, externalType: "import" | "module" | undefined }} ImportDependencyMeta */
72
74
  /** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
73
75
  /** @typedef {{ sourceType: "css-url" }} AssetDependencyMeta */
74
76
 
@@ -202,15 +204,25 @@ const getSourceForImportExternal = (
202
204
  runtimeTemplate,
203
205
  dependencyMeta
204
206
  ) => {
205
- const importName = runtimeTemplate.outputOptions.importFunctionName;
207
+ const baseImportName = runtimeTemplate.outputOptions.importFunctionName;
206
208
  if (
207
209
  !runtimeTemplate.supportsDynamicImport() &&
208
- (importName === "import" || importName === "module-import")
210
+ (baseImportName === "import" || baseImportName === "module-import")
209
211
  ) {
210
212
  throw new Error(
211
213
  "The target environment doesn't support 'import()' so it's not possible to use external type 'import'"
212
214
  );
213
215
  }
216
+ const phase = dependencyMeta && dependencyMeta.phase;
217
+ // `import.defer(…)` and `import.source(…)` are only valid forms of the
218
+ // native `import(…)` function, so we only emit the phase suffix when the
219
+ // importFunctionName is the default `"import"`.
220
+ const importName =
221
+ baseImportName === "import" && ImportPhaseUtils.isDefer(phase)
222
+ ? "import.defer"
223
+ : baseImportName === "import" && ImportPhaseUtils.isSource(phase)
224
+ ? "import.source"
225
+ : baseImportName;
214
226
  const attributes =
215
227
  dependencyMeta && dependencyMeta.attributes
216
228
  ? dependencyMeta.attributes._isLegacyAssert
@@ -293,7 +305,9 @@ class ModuleExternalInitFragment extends InitFragment {
293
305
  "",
294
306
  InitFragment.STAGE_HARMONY_IMPORTS,
295
307
  0,
296
- `external module import ${ident} ${imported === true ? imported : imported.join(" ")}`
308
+ `external module import ${ident} ${
309
+ imported === true ? imported : imported.join(" ")
310
+ }`
297
311
  );
298
312
  this._ident = ident;
299
313
  this._request = request;
@@ -332,23 +346,34 @@ class ModuleExternalInitFragment extends InitFragment {
332
346
  } = this;
333
347
  const attributes =
334
348
  dependencyMeta && dependencyMeta.attributes
335
- ? dependencyMeta.attributes._isLegacyAssert &&
336
- dependencyMeta.attributes._isLegacyAssert
349
+ ? dependencyMeta.attributes._isLegacyAssert
337
350
  ? ` assert ${JSON.stringify(
338
351
  dependencyMeta.attributes,
339
352
  importAssertionReplacer
340
353
  )}`
341
354
  : ` with ${JSON.stringify(dependencyMeta.attributes)}`
342
355
  : "";
356
+ const phase = dependencyMeta && dependencyMeta.phase;
343
357
  let content = "";
344
358
  if (imported === true) {
345
359
  // namespace
346
- content = `import * as ${identifier} from ${JSON.stringify(request)}${
347
- attributes
348
- };\n`;
360
+ const phaseKeyword = ImportPhaseUtils.isDefer(phase) ? "defer " : "";
361
+ content = `import ${phaseKeyword}* as ${identifier} from ${JSON.stringify(
362
+ request
363
+ )}${attributes};\n`;
349
364
  } else if (imported.length === 0) {
350
365
  // just import, no use
351
366
  content = `import ${JSON.stringify(request)}${attributes};\n`;
367
+ } else if (
368
+ ImportPhaseUtils.isSource(phase) &&
369
+ imported.length === 1 &&
370
+ imported[0][0] === "default"
371
+ ) {
372
+ // `import source x from "…"` — the source-phase form binds the source
373
+ // object directly to a single identifier (no namespace, no destructuring).
374
+ content = `import source ${imported[0][1]} from ${JSON.stringify(
375
+ request
376
+ )}${attributes};\n`;
352
377
  } else {
353
378
  content = `import { ${imported
354
379
  .map(([name, finalName]) => {
@@ -469,6 +494,7 @@ const getSourceForModuleExternal = (
469
494
  dependencyMeta,
470
495
  concatenationScope
471
496
  ) => {
497
+ const phase = dependencyMeta && dependencyMeta.phase;
472
498
  /** @type {Imported} */
473
499
  let imported = true;
474
500
  if (concatenationScope) {
@@ -497,6 +523,14 @@ const getSourceForModuleExternal = (
497
523
  imported = true;
498
524
  }
499
525
 
526
+ // `import defer …` is only valid as `import defer * as ns from "…"`, so
527
+ // keep the namespace form even if usage analysis would otherwise narrow
528
+ // the import down to specific names. Defer + concatenation is semantically
529
+ // at odds (lazy vs. eager), so we preserve the user-written shape here.
530
+ if (ImportPhaseUtils.isDefer(phase)) {
531
+ imported = true;
532
+ }
533
+
500
534
  const initFragment = new ModuleExternalInitFragment(
501
535
  moduleAndSpecifiers[0],
502
536
  imported,
@@ -751,7 +785,21 @@ class ExternalModule extends Module {
751
785
  * @returns {string} a unique identifier of the module
752
786
  */
753
787
  identifier() {
754
- return `external ${this._resolveExternalType(this.externalType)} ${JSON.stringify(this.request)}`;
788
+ let id = `external ${this._resolveExternalType(
789
+ this.externalType
790
+ )} ${JSON.stringify(this.request)}`;
791
+ const meta = /** @type {ImportDependencyMeta | undefined} */ (
792
+ this.dependencyMeta
793
+ );
794
+ if (meta) {
795
+ if (meta.phase) {
796
+ id += `|phase=${ImportPhaseUtils.stringify(meta.phase)}`;
797
+ }
798
+ if (meta.attributes) {
799
+ id += `|attributes=${JSON.stringify(meta.attributes)}`;
800
+ }
801
+ }
802
+ return id;
755
803
  }
756
804
 
757
805
  /**
@@ -1126,7 +1174,9 @@ class ExternalModule extends Module {
1126
1174
  scope.registerRawExport(specifier, finalName);
1127
1175
  }
1128
1176
  } else if (concatenationScope) {
1129
- sourceString = `${runtimeTemplate.renderConst()} ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
1177
+ sourceString = `${runtimeTemplate.renderConst()} ${
1178
+ ConcatenationScope.NAMESPACE_OBJECT_EXPORT
1179
+ } = ${sourceString};`;
1130
1180
  concatenationScope.registerNamespaceExport(
1131
1181
  ConcatenationScope.NAMESPACE_OBJECT_EXPORT
1132
1182
  );
@@ -1194,10 +1244,21 @@ class ExternalModule extends Module {
1194
1244
  updateHash(hash, context) {
1195
1245
  const { chunkGraph } = context;
1196
1246
  hash.update(
1197
- `${this._resolveExternalType(this.externalType)}${JSON.stringify(this.request)}${this.isOptional(
1198
- chunkGraph.moduleGraph
1199
- )}`
1247
+ `${this._resolveExternalType(this.externalType)}${JSON.stringify(
1248
+ this.request
1249
+ )}${this.isOptional(chunkGraph.moduleGraph)}`
1250
+ );
1251
+ const meta = /** @type {ImportDependencyMeta | undefined} */ (
1252
+ this.dependencyMeta
1200
1253
  );
1254
+ if (meta) {
1255
+ if (meta.phase) {
1256
+ hash.update(`|phase=${ImportPhaseUtils.stringify(meta.phase)}`);
1257
+ }
1258
+ if (meta.attributes) {
1259
+ hash.update(`|attributes=${JSON.stringify(meta.attributes)}`);
1260
+ }
1261
+ }
1201
1262
  super.updateHash(hash, context);
1202
1263
  }
1203
1264
 
@@ -193,6 +193,11 @@ class ExternalModuleFactoryPlugin {
193
193
 
194
194
  dependencyMeta = {
195
195
  attributes: dependency.attributes,
196
+ phase:
197
+ dependency instanceof HarmonyImportDependency ||
198
+ dependency instanceof ImportDependency
199
+ ? dependency.phase
200
+ : undefined,
196
201
  externalType
197
202
  };
198
203
  } else if (dependency instanceof CssImportDependency) {