webpack 5.85.0 → 5.88.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (249) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/BannerPlugin.js +2 -1
  5. package/lib/CaseSensitiveModulesWarning.js +3 -1
  6. package/lib/Chunk.js +35 -17
  7. package/lib/ChunkGraph.js +4 -4
  8. package/lib/ChunkGroup.js +20 -9
  9. package/lib/CompatibilityPlugin.js +50 -30
  10. package/lib/Compilation.js +2 -1
  11. package/lib/Compiler.js +10 -9
  12. package/lib/ConcatenationScope.js +2 -2
  13. package/lib/ConditionalInitFragment.js +11 -1
  14. package/lib/ConstPlugin.js +73 -32
  15. package/lib/ContextModule.js +8 -3
  16. package/lib/ContextModuleFactory.js +1 -0
  17. package/lib/ContextReplacementPlugin.js +13 -0
  18. package/lib/DelegatedModule.js +15 -3
  19. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  20. package/lib/DependenciesBlock.js +1 -1
  21. package/lib/Dependency.js +11 -5
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllEntryPlugin.js +11 -1
  24. package/lib/DllModule.js +6 -0
  25. package/lib/DllReferencePlugin.js +13 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ErrorHelpers.js +1 -0
  28. package/lib/EvalSourceMapDevToolPlugin.js +6 -1
  29. package/lib/ExportsInfo.js +22 -4
  30. package/lib/ExportsInfoApiPlugin.js +14 -5
  31. package/lib/ExternalModule.js +20 -8
  32. package/lib/FileSystemInfo.js +52 -24
  33. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  34. package/lib/FlagDependencyUsagePlugin.js +3 -1
  35. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  36. package/lib/Generator.js +7 -0
  37. package/lib/HotModuleReplacementPlugin.js +8 -0
  38. package/lib/InitFragment.js +28 -5
  39. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  40. package/lib/LibManifestPlugin.js +20 -4
  41. package/lib/Module.js +14 -3
  42. package/lib/ModuleDependencyError.js +4 -2
  43. package/lib/ModuleDependencyWarning.js +4 -2
  44. package/lib/ModuleGraph.js +31 -24
  45. package/lib/ModuleGraphConnection.js +19 -6
  46. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  47. package/lib/ModuleNotFoundError.js +5 -2
  48. package/lib/ModuleProfile.js +1 -0
  49. package/lib/ModuleRestoreError.js +2 -0
  50. package/lib/ModuleStoreError.js +2 -1
  51. package/lib/ModuleTypeConstants.js +7 -0
  52. package/lib/MultiWatching.js +4 -0
  53. package/lib/NodeStuffPlugin.js +32 -6
  54. package/lib/ProgressPlugin.js +71 -15
  55. package/lib/ProvidePlugin.js +13 -4
  56. package/lib/RawModule.js +3 -1
  57. package/lib/RequireJsStuffPlugin.js +7 -0
  58. package/lib/RuntimeGlobals.js +5 -0
  59. package/lib/RuntimeModule.js +3 -3
  60. package/lib/RuntimePlugin.js +6 -3
  61. package/lib/RuntimeTemplate.js +22 -4
  62. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  63. package/lib/SourceMapDevToolPlugin.js +7 -2
  64. package/lib/UseStrictPlugin.js +10 -3
  65. package/lib/Watching.js +62 -25
  66. package/lib/WebpackError.js +6 -5
  67. package/lib/WebpackIsIncludedPlugin.js +6 -4
  68. package/lib/WebpackOptionsApply.js +4 -2
  69. package/lib/WebpackOptionsDefaulter.js +10 -3
  70. package/lib/asset/AssetGenerator.js +2 -1
  71. package/lib/asset/AssetParser.js +11 -6
  72. package/lib/asset/AssetSourceParser.js +8 -3
  73. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  74. package/lib/buildChunkGraph.js +37 -21
  75. package/lib/cache/IdleFileCachePlugin.js +2 -1
  76. package/lib/cache/PackFileCacheStrategy.js +53 -22
  77. package/lib/config/browserslistTargetHandler.js +7 -7
  78. package/lib/config/defaults.js +43 -26
  79. package/lib/container/RemoteRuntimeModule.js +1 -1
  80. package/lib/css/CssExportsGenerator.js +9 -0
  81. package/lib/css/CssGenerator.js +1 -1
  82. package/lib/css/CssLoadingRuntimeModule.js +43 -19
  83. package/lib/css/CssModulesPlugin.js +42 -14
  84. package/lib/css/CssParser.js +22 -0
  85. package/lib/dependencies/AMDDefineDependency.js +34 -4
  86. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  87. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  88. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  89. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  90. package/lib/dependencies/CommonJsPlugin.js +13 -8
  91. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  92. package/lib/dependencies/ConstDependency.js +2 -2
  93. package/lib/dependencies/ContextDependency.js +7 -2
  94. package/lib/dependencies/CssImportDependency.js +1 -1
  95. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  96. package/lib/dependencies/CssUrlDependency.js +3 -3
  97. package/lib/dependencies/DllEntryDependency.js +5 -0
  98. package/lib/dependencies/DynamicExports.js +10 -6
  99. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  100. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  101. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  102. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  103. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  104. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  105. package/lib/dependencies/HarmonyExports.js +9 -5
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
  109. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  110. package/lib/dependencies/ImportDependency.js +5 -3
  111. package/lib/dependencies/ImportEagerDependency.js +5 -3
  112. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  113. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  114. package/lib/dependencies/ImportParserPlugin.js +62 -25
  115. package/lib/dependencies/ImportWeakDependency.js +5 -3
  116. package/lib/dependencies/JsonExportsDependency.js +1 -1
  117. package/lib/dependencies/ModuleDependency.js +1 -1
  118. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  119. package/lib/dependencies/ProvidedDependency.js +4 -1
  120. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  121. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  122. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  123. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  124. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  125. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  126. package/lib/dependencies/SystemPlugin.js +17 -5
  127. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  128. package/lib/dependencies/URLDependency.js +2 -2
  129. package/lib/dependencies/URLPlugin.js +9 -4
  130. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  131. package/lib/dependencies/WorkerPlugin.js +59 -22
  132. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  134. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  135. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  136. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  137. package/lib/javascript/BasicEvaluatedExpression.js +28 -19
  138. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  139. package/lib/javascript/JavascriptModulesPlugin.js +25 -5
  140. package/lib/javascript/JavascriptParser.js +157 -85
  141. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  142. package/lib/json/JsonData.js +2 -2
  143. package/lib/json/JsonParser.js +25 -12
  144. package/lib/library/AmdLibraryPlugin.js +2 -2
  145. package/lib/library/AssignLibraryPlugin.js +13 -1
  146. package/lib/library/EnableLibraryPlugin.js +4 -0
  147. package/lib/library/SystemLibraryPlugin.js +1 -1
  148. package/lib/library/UmdLibraryPlugin.js +20 -2
  149. package/lib/logging/runtime.js +1 -1
  150. package/lib/logging/truncateArgs.js +4 -0
  151. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  152. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  153. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  154. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  155. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  156. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  157. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  158. package/lib/optimize/InnerGraph.js +5 -5
  159. package/lib/optimize/InnerGraphPlugin.js +2 -1
  160. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  161. package/lib/optimize/MangleExportsPlugin.js +1 -1
  162. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  163. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  164. package/lib/optimize/RealContentHashPlugin.js +80 -30
  165. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  166. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  167. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  168. package/lib/optimize/SplitChunksPlugin.js +71 -31
  169. package/lib/performance/SizeLimitsPlugin.js +7 -4
  170. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  171. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  172. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  173. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  174. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  175. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  176. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  177. package/lib/rules/RuleSetCompiler.js +3 -3
  178. package/lib/rules/UseEffectRulePlugin.js +6 -4
  179. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  180. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  181. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  182. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  183. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  184. package/lib/runtime/CompatRuntimeModule.js +7 -2
  185. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  186. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  187. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  188. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  189. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  190. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  191. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  192. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  193. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  194. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  195. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  196. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  197. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  198. package/lib/runtime/NonceRuntimeModule.js +1 -1
  199. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  200. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  201. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  202. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  203. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  204. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  205. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  206. package/lib/serialization/BinaryMiddleware.js +143 -1
  207. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  208. package/lib/serialization/ObjectMiddleware.js +9 -3
  209. package/lib/serialization/types.js +1 -1
  210. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  211. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  212. package/lib/sharing/ProvideSharedDependency.js +11 -0
  213. package/lib/sharing/ProvideSharedModule.js +4 -0
  214. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  215. package/lib/sharing/ShareRuntimeModule.js +12 -5
  216. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  217. package/lib/sharing/utils.js +32 -5
  218. package/lib/util/AsyncQueue.js +4 -2
  219. package/lib/util/ParallelismFactorCalculator.js +10 -0
  220. package/lib/util/Semaphore.js +1 -1
  221. package/lib/util/StackedCacheMap.js +1 -1
  222. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  223. package/lib/util/createHash.js +30 -9
  224. package/lib/util/deprecation.js +10 -3
  225. package/lib/util/deterministicGrouping.js +50 -11
  226. package/lib/util/findGraphRoots.js +4 -2
  227. package/lib/util/memoize.js +3 -3
  228. package/lib/util/processAsyncTree.js +7 -1
  229. package/lib/util/registerExternalSerializer.js +1 -1
  230. package/lib/util/runtime.js +84 -21
  231. package/lib/util/semver.js +1 -0
  232. package/lib/util/smartGrouping.js +1 -1
  233. package/lib/validateSchema.js +6 -2
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  235. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  236. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  237. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  239. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  240. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  241. package/lib/webpack.js +11 -2
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  243. package/module.d.ts +1 -0
  244. package/package.json +5 -4
  245. package/schemas/WebpackOptions.check.js +1 -1
  246. package/schemas/WebpackOptions.json +52 -6
  247. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  248. package/schemas/plugins/css/CssParserOptions.json +1 -1
  249. package/types.d.ts +606 -292
package/README.md CHANGED
@@ -232,6 +232,7 @@ or are automatically applied via regex from your webpack configuration.
232
232
  | <a href="https://github.com/webpack-contrib/polymer-webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a> | ![polymer-npm] | ![polymer-size] | Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules |
233
233
  | <a href="https://github.com/TheLarkInn/angular2-template-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/angular-icon-1.svg"></a> | ![angular-npm] | ![angular-size] | Loads and compiles Angular 2 Components |
234
234
  | <a href="https://github.com/riot/webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/riot.svg"></a> | ![riot-npm] | ![riot-size] | Riot official webpack loader |
235
+ | <a href="https://github.com/sveltejs/svelte-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/svelte-1.svg"></a> | ![svelte-npm] | ![svelte-size] | Official Svelte loader |
235
236
 
236
237
  [vue-npm]: https://img.shields.io/npm/v/vue-loader.svg
237
238
  [vue-size]: https://packagephobia.com/badge?p=vue-loader
@@ -241,6 +242,8 @@ or are automatically applied via regex from your webpack configuration.
241
242
  [angular-size]: https://packagephobia.com/badge?p=angular2-template-loader
242
243
  [riot-npm]: https://img.shields.io/npm/v/riot-tag-loader.svg
243
244
  [riot-size]: https://packagephobia.com/badge?p=riot-tag-loader
245
+ [svelte-npm]: https://img.shields.io/npm/v/svelte-loader.svg
246
+ [svelte-size]: https://packagephobia.com/badge?p=svelte-loader
244
247
 
245
248
  ### Performance
246
249
 
@@ -714,5 +717,5 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
714
717
  [builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
715
718
  [licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
716
719
  [licenses]: https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack.svg?type=shield
717
- [cover]: https://img.shields.io/coveralls/webpack/webpack.svg
718
- [cover-url]: https://coveralls.io/r/webpack/webpack/
720
+ [cover]: https://codecov.io/gh/webpack/webpack/branch/master/graph/badge.svg?token=mDP3mQJNnn
721
+ [cover-url]: https://codecov.io/gh/webpack/webpack
package/lib/APIPlugin.js CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const InitFragment = require("./InitFragment");
8
9
  const {
9
10
  JAVASCRIPT_MODULE_TYPE_AUTO,
10
11
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
@@ -14,6 +15,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
14
15
  const WebpackError = require("./WebpackError");
15
16
  const ConstDependency = require("./dependencies/ConstDependency");
16
17
  const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
18
+ const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
17
19
  const {
18
20
  toConstantDependency,
19
21
  evaluateToString
@@ -24,103 +26,121 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
24
26
  /** @typedef {import("./Compiler")} Compiler */
25
27
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
26
28
 
27
- /* eslint-disable camelcase */
28
- const REPLACEMENTS = {
29
- __webpack_require__: {
30
- expr: RuntimeGlobals.require,
31
- req: [RuntimeGlobals.require],
32
- type: "function",
33
- assign: false
34
- },
35
- __webpack_public_path__: {
36
- expr: RuntimeGlobals.publicPath,
37
- req: [RuntimeGlobals.publicPath],
38
- type: "string",
39
- assign: true
40
- },
41
- __webpack_base_uri__: {
42
- expr: RuntimeGlobals.baseURI,
43
- req: [RuntimeGlobals.baseURI],
44
- type: "string",
45
- assign: true
46
- },
47
- __webpack_modules__: {
48
- expr: RuntimeGlobals.moduleFactories,
49
- req: [RuntimeGlobals.moduleFactories],
50
- type: "object",
51
- assign: false
52
- },
53
- __webpack_chunk_load__: {
54
- expr: RuntimeGlobals.ensureChunk,
55
- req: [RuntimeGlobals.ensureChunk],
56
- type: "function",
57
- assign: true
58
- },
59
- __non_webpack_require__: {
60
- expr: "require",
61
- req: null,
62
- type: undefined, // type is not known, depends on environment
63
- assign: true
64
- },
65
- __webpack_nonce__: {
66
- expr: RuntimeGlobals.scriptNonce,
67
- req: [RuntimeGlobals.scriptNonce],
68
- type: "string",
69
- assign: true
70
- },
71
- __webpack_hash__: {
72
- expr: `${RuntimeGlobals.getFullHash}()`,
73
- req: [RuntimeGlobals.getFullHash],
74
- type: "string",
75
- assign: false
76
- },
77
- __webpack_chunkname__: {
78
- expr: RuntimeGlobals.chunkName,
79
- req: [RuntimeGlobals.chunkName],
80
- type: "string",
81
- assign: false
82
- },
83
- __webpack_get_script_filename__: {
84
- expr: RuntimeGlobals.getChunkScriptFilename,
85
- req: [RuntimeGlobals.getChunkScriptFilename],
86
- type: "function",
87
- assign: true
88
- },
89
- __webpack_runtime_id__: {
90
- expr: RuntimeGlobals.runtimeId,
91
- req: [RuntimeGlobals.runtimeId],
92
- assign: false
93
- },
94
- "require.onError": {
95
- expr: RuntimeGlobals.uncaughtErrorHandler,
96
- req: [RuntimeGlobals.uncaughtErrorHandler],
97
- type: undefined, // type is not known, could be function or undefined
98
- assign: true // is never a pattern
99
- },
100
- __system_context__: {
101
- expr: RuntimeGlobals.systemContext,
102
- req: [RuntimeGlobals.systemContext],
103
- type: "object",
104
- assign: false
105
- },
106
- __webpack_share_scopes__: {
107
- expr: RuntimeGlobals.shareScopeMap,
108
- req: [RuntimeGlobals.shareScopeMap],
109
- type: "object",
110
- assign: false
111
- },
112
- __webpack_init_sharing__: {
113
- expr: RuntimeGlobals.initializeSharing,
114
- req: [RuntimeGlobals.initializeSharing],
115
- type: "function",
116
- assign: true
117
- }
118
- };
119
- /* eslint-enable camelcase */
29
+ /**
30
+ * @param {boolean} module true if ES module
31
+ * @param {string} importMetaName `import.meta` name
32
+ * @returns {Record<string, {expr: string, req: string[] | null, type?: string, assign: boolean}>} replacements
33
+ */
34
+ function getReplacements(module, importMetaName) {
35
+ return {
36
+ __webpack_require__: {
37
+ expr: RuntimeGlobals.require,
38
+ req: [RuntimeGlobals.require],
39
+ type: "function",
40
+ assign: false
41
+ },
42
+ __webpack_public_path__: {
43
+ expr: RuntimeGlobals.publicPath,
44
+ req: [RuntimeGlobals.publicPath],
45
+ type: "string",
46
+ assign: true
47
+ },
48
+ __webpack_base_uri__: {
49
+ expr: RuntimeGlobals.baseURI,
50
+ req: [RuntimeGlobals.baseURI],
51
+ type: "string",
52
+ assign: true
53
+ },
54
+ __webpack_modules__: {
55
+ expr: RuntimeGlobals.moduleFactories,
56
+ req: [RuntimeGlobals.moduleFactories],
57
+ type: "object",
58
+ assign: false
59
+ },
60
+ __webpack_chunk_load__: {
61
+ expr: RuntimeGlobals.ensureChunk,
62
+ req: [RuntimeGlobals.ensureChunk],
63
+ type: "function",
64
+ assign: true
65
+ },
66
+ __non_webpack_require__: {
67
+ expr: module
68
+ ? `__WEBPACK_EXTERNAL_createRequire(${importMetaName}.url)`
69
+ : "require",
70
+ req: null,
71
+ type: undefined, // type is not known, depends on environment
72
+ assign: true
73
+ },
74
+ __webpack_nonce__: {
75
+ expr: RuntimeGlobals.scriptNonce,
76
+ req: [RuntimeGlobals.scriptNonce],
77
+ type: "string",
78
+ assign: true
79
+ },
80
+ __webpack_hash__: {
81
+ expr: `${RuntimeGlobals.getFullHash}()`,
82
+ req: [RuntimeGlobals.getFullHash],
83
+ type: "string",
84
+ assign: false
85
+ },
86
+ __webpack_chunkname__: {
87
+ expr: RuntimeGlobals.chunkName,
88
+ req: [RuntimeGlobals.chunkName],
89
+ type: "string",
90
+ assign: false
91
+ },
92
+ __webpack_get_script_filename__: {
93
+ expr: RuntimeGlobals.getChunkScriptFilename,
94
+ req: [RuntimeGlobals.getChunkScriptFilename],
95
+ type: "function",
96
+ assign: true
97
+ },
98
+ __webpack_runtime_id__: {
99
+ expr: RuntimeGlobals.runtimeId,
100
+ req: [RuntimeGlobals.runtimeId],
101
+ assign: false
102
+ },
103
+ "require.onError": {
104
+ expr: RuntimeGlobals.uncaughtErrorHandler,
105
+ req: [RuntimeGlobals.uncaughtErrorHandler],
106
+ type: undefined, // type is not known, could be function or undefined
107
+ assign: true // is never a pattern
108
+ },
109
+ __system_context__: {
110
+ expr: RuntimeGlobals.systemContext,
111
+ req: [RuntimeGlobals.systemContext],
112
+ type: "object",
113
+ assign: false
114
+ },
115
+ __webpack_share_scopes__: {
116
+ expr: RuntimeGlobals.shareScopeMap,
117
+ req: [RuntimeGlobals.shareScopeMap],
118
+ type: "object",
119
+ assign: false
120
+ },
121
+ __webpack_init_sharing__: {
122
+ expr: RuntimeGlobals.initializeSharing,
123
+ req: [RuntimeGlobals.initializeSharing],
124
+ type: "function",
125
+ assign: true
126
+ }
127
+ };
128
+ }
120
129
 
121
130
  const PLUGIN_NAME = "APIPlugin";
122
131
 
132
+ /**
133
+ * @typedef {Object} APIPluginOptions
134
+ * @property {boolean} [module] the output filename
135
+ */
136
+
123
137
  class APIPlugin {
138
+ /**
139
+ * @param {APIPluginOptions} [options] options
140
+ */
141
+ constructor(options = {}) {
142
+ this.options = options;
143
+ }
124
144
  /**
125
145
  * Apply the plugin
126
146
  * @param {Compiler} compiler the compiler instance
@@ -130,6 +150,12 @@ class APIPlugin {
130
150
  compiler.hooks.compilation.tap(
131
151
  PLUGIN_NAME,
132
152
  (compilation, { normalModuleFactory }) => {
153
+ const { importMetaName } = compilation.outputOptions;
154
+ const REPLACEMENTS = getReplacements(
155
+ this.options.module,
156
+ importMetaName
157
+ );
158
+
133
159
  compilation.dependencyTemplates.set(
134
160
  ConstDependency,
135
161
  new ConstDependency.Template()
@@ -152,18 +178,43 @@ class APIPlugin {
152
178
  return true;
153
179
  });
154
180
 
181
+ const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
182
+
183
+ hooks.renderModuleContent.tap(
184
+ PLUGIN_NAME,
185
+ (source, module, renderContext) => {
186
+ if (module.buildInfo.needCreateRequire) {
187
+ const chunkInitFragments = [
188
+ new InitFragment(
189
+ 'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
190
+ InitFragment.STAGE_HARMONY_IMPORTS,
191
+ 0,
192
+ "external module node-commonjs"
193
+ )
194
+ ];
195
+
196
+ renderContext.chunkInitFragments.push(...chunkInitFragments);
197
+ }
198
+
199
+ return source;
200
+ }
201
+ );
202
+
155
203
  /**
156
204
  * @param {JavascriptParser} parser the parser
157
205
  */
158
206
  const handler = parser => {
159
207
  Object.keys(REPLACEMENTS).forEach(key => {
160
208
  const info = REPLACEMENTS[key];
161
- parser.hooks.expression
162
- .for(key)
163
- .tap(
164
- PLUGIN_NAME,
165
- toConstantDependency(parser, info.expr, info.req)
166
- );
209
+ parser.hooks.expression.for(key).tap(PLUGIN_NAME, expression => {
210
+ const dep = toConstantDependency(parser, info.expr, info.req);
211
+
212
+ if (key === "__non_webpack_require__" && this.options.module) {
213
+ parser.state.module.buildInfo.needCreateRequire = true;
214
+ }
215
+
216
+ return dep(expression);
217
+ });
167
218
  if (info.assign === false) {
168
219
  parser.hooks.assign.for(key).tap(PLUGIN_NAME, expr => {
169
220
  const err = new WebpackError(`${key} must not be assigned`);
@@ -21,9 +21,9 @@ const makeSerializable = require("./util/makeSerializable");
21
21
 
22
22
  class AsyncDependenciesBlock extends DependenciesBlock {
23
23
  /**
24
- * @param {ChunkGroupOptions & { entryOptions?: EntryOptions }} groupOptions options for the group
25
- * @param {DependencyLocation=} loc the line of code
26
- * @param {string=} request the request
24
+ * @param {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | null} groupOptions options for the group
25
+ * @param {(DependencyLocation | null)=} loc the line of code
26
+ * @param {(string | null)=} request the request
27
27
  */
28
28
  constructor(groupOptions, loc, request) {
29
29
  super();
@@ -11,6 +11,7 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
11
11
  const Template = require("./Template");
12
12
  const createSchemaValidation = require("./util/create-schema-validation");
13
13
 
14
+ /** @typedef {import("../declarations/plugins/BannerPlugin").BannerFunction} BannerFunction */
14
15
  /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
15
16
  /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
16
17
  /** @typedef {import("./Compiler")} Compiler */
@@ -60,7 +61,7 @@ class BannerPlugin {
60
61
  const getBanner = bannerOption;
61
62
  this.banner = this.options.raw
62
63
  ? getBanner
63
- : data => wrapComment(getBanner(data));
64
+ : /** @type {BannerFunction} */ data => wrapComment(getBanner(data));
64
65
  } else {
65
66
  const banner = this.options.raw
66
67
  ? bannerOption
@@ -42,7 +42,9 @@ const createModulesListMessage = (modules, moduleGraph) => {
42
42
 
43
43
  if (validReasons.length > 0) {
44
44
  message += `\n Used by ${validReasons.length} module(s), i. e.`;
45
- message += `\n ${validReasons[0].identifier()}`;
45
+ message += `\n ${
46
+ /** @type {Module[]} */ (validReasons)[0].identifier()
47
+ }`;
46
48
  }
47
49
  return message;
48
50
  })
package/lib/Chunk.js CHANGED
@@ -23,6 +23,7 @@ const { mergeRuntime } = require("./util/runtime");
23
23
  /** @typedef {import("./ChunkGraph").ChunkSizeOptions} ChunkSizeOptions */
24
24
  /** @typedef {import("./ChunkGraph").ModuleFilterPredicate} ModuleFilterPredicate */
25
25
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
26
+ /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
26
27
  /** @typedef {import("./Compilation")} Compilation */
27
28
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
28
29
  /** @typedef {import("./Compilation").PathData} PathData */
@@ -32,6 +33,8 @@ const { mergeRuntime } = require("./util/runtime");
32
33
  /** @typedef {import("./util/Hash")} Hash */
33
34
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
34
35
 
36
+ /** @typedef {number | string} ChunkId */
37
+
35
38
  const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
36
39
 
37
40
  /**
@@ -66,21 +69,21 @@ class Chunk {
66
69
  * @param {boolean} backCompat enable backward-compatibility
67
70
  */
68
71
  constructor(name, backCompat = true) {
69
- /** @type {number | string | null} */
72
+ /** @type {ChunkId | null} */
70
73
  this.id = null;
71
- /** @type {(number|string)[] | null} */
74
+ /** @type {ChunkId[] | null} */
72
75
  this.ids = null;
73
76
  /** @type {number} */
74
77
  this.debugId = debugId++;
75
- /** @type {string} */
78
+ /** @type {string | undefined} */
76
79
  this.name = name;
77
80
  /** @type {SortableSet<string>} */
78
81
  this.idNameHints = new SortableSet();
79
82
  /** @type {boolean} */
80
83
  this.preventIntegration = false;
81
- /** @type {(string | function(PathData, AssetInfo=): string)?} */
84
+ /** @type {(string | function(PathData, AssetInfo=): string) | undefined} */
82
85
  this.filenameTemplate = undefined;
83
- /** @type {(string | function(PathData, AssetInfo=): string)?} */
86
+ /** @type {(string | function(PathData, AssetInfo=): string) | undefined} */
84
87
  this.cssFilenameTemplate = undefined;
85
88
  /** @private @type {SortableSet<ChunkGroup>} */
86
89
  this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
@@ -350,7 +353,7 @@ class Chunk {
350
353
  const chunkModuleHashMap = Object.create(null);
351
354
 
352
355
  for (const asyncChunk of this.getAllAsyncChunks()) {
353
- /** @type {(string|number)[]} */
356
+ /** @type {ChunkId[] | undefined} */
354
357
  let array;
355
358
  for (const module of chunkGraph.getOrderedChunkModulesIterable(
356
359
  asyncChunk,
@@ -359,7 +362,7 @@ class Chunk {
359
362
  if (filterFn(module)) {
360
363
  if (array === undefined) {
361
364
  array = [];
362
- chunkModuleIdMap[asyncChunk.id] = array;
365
+ chunkModuleIdMap[/** @type {ChunkId} */ (asyncChunk.id)] = array;
363
366
  }
364
367
  const moduleId = chunkGraph.getModuleId(module);
365
368
  array.push(moduleId);
@@ -405,15 +408,18 @@ class Chunk {
405
408
  const chunkNameMap = Object.create(null);
406
409
 
407
410
  for (const chunk of this.getAllAsyncChunks()) {
408
- chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
411
+ const id = /** @type {ChunkId} */ (chunk.id);
412
+ chunkHashMap[id] =
413
+ /** @type {string} */
414
+ (realHash ? chunk.hash : chunk.renderedHash);
409
415
  for (const key of Object.keys(chunk.contentHash)) {
410
416
  if (!chunkContentHashMap[key]) {
411
417
  chunkContentHashMap[key] = Object.create(null);
412
418
  }
413
- chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
419
+ chunkContentHashMap[key][id] = chunk.contentHash[key];
414
420
  }
415
421
  if (chunk.name) {
416
- chunkNameMap[chunk.id] = chunk.name;
422
+ chunkNameMap[id] = chunk.name;
417
423
  }
418
424
  }
419
425
 
@@ -553,7 +559,11 @@ class Chunk {
553
559
  const entryModules =
554
560
  chunkGraph.getChunkEntryModulesWithChunkGroupIterable(this);
555
561
  for (const [m, chunkGroup] of entryModules) {
556
- hash.update(`entry${chunkGraph.getModuleId(m)}${chunkGroup.id}`);
562
+ hash.update(
563
+ `entry${chunkGraph.getModuleId(m)}${
564
+ /** @type {ChunkGroup} */ (chunkGroup).id
565
+ }`
566
+ );
557
567
  }
558
568
  }
559
569
 
@@ -697,7 +707,13 @@ class Chunk {
697
707
  lists.set(name, list);
698
708
  }
699
709
  list.push({
700
- order: childGroup.options[key],
710
+ order:
711
+ /** @type {number} */
712
+ (
713
+ childGroup.options[
714
+ /** @type {keyof ChunkGroupOptions} */ (key)
715
+ ]
716
+ ),
701
717
  group: childGroup
702
718
  });
703
719
  }
@@ -718,7 +734,7 @@ class Chunk {
718
734
  for (const item of list) {
719
735
  for (const chunk of item.group.chunks) {
720
736
  if (filterFn && !filterFn(chunk, chunkGraph)) continue;
721
- chunkIdSet.add(chunk.id);
737
+ chunkIdSet.add(/** @type {ChunkId} */ (chunk.id));
722
738
  }
723
739
  }
724
740
  if (chunkIdSet.size > 0) {
@@ -731,13 +747,14 @@ class Chunk {
731
747
  /**
732
748
  * @param {ChunkGraph} chunkGraph the chunk graph
733
749
  * @param {string} type option name
734
- * @returns {{ onChunks: Chunk[], chunks: Set<Chunk> }[]} referenced chunks for a specific type
750
+ * @returns {{ onChunks: Chunk[], chunks: Set<Chunk> }[] | undefined} referenced chunks for a specific type
735
751
  */
736
752
  getChildrenOfTypeInOrder(chunkGraph, type) {
737
753
  const list = [];
738
754
  for (const group of this.groupsIterable) {
739
755
  for (const childGroup of group.childrenIterable) {
740
- const order = childGroup.options[type];
756
+ const order =
757
+ childGroup.options[/** @type {keyof ChunkGroupOptions} */ (type)];
741
758
  if (order === undefined) continue;
742
759
  list.push({
743
760
  order,
@@ -748,7 +765,8 @@ class Chunk {
748
765
  }
749
766
  if (list.length === 0) return undefined;
750
767
  list.sort((a, b) => {
751
- const cmp = b.order - a.order;
768
+ const cmp =
769
+ /** @type {number} */ (b.order) - /** @type {number} */ (a.order);
752
770
  if (cmp !== 0) return cmp;
753
771
  return a.group.compareTo(chunkGraph, b.group);
754
772
  });
@@ -792,7 +810,7 @@ class Chunk {
792
810
  if (chunkMap === undefined) {
793
811
  chunkMaps[key] = chunkMap = Object.create(null);
794
812
  }
795
- chunkMap[chunk.id] = data[key];
813
+ chunkMap[/** @type {ChunkId} */ (chunk.id)] = data[key];
796
814
  }
797
815
  };
798
816
 
package/lib/ChunkGraph.js CHANGED
@@ -188,7 +188,7 @@ class ChunkGraphModule {
188
188
  this.entryInChunks = undefined;
189
189
  /** @type {Set<Chunk> | undefined} */
190
190
  this.runtimeInChunks = undefined;
191
- /** @type {RuntimeSpecMap<ModuleHashInfo>} */
191
+ /** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
192
192
  this.hashes = undefined;
193
193
  /** @type {string | number} */
194
194
  this.id = null;
@@ -1388,7 +1388,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1388
1388
  */
1389
1389
  hasModuleHashes(module, runtime) {
1390
1390
  const cgm = this._getChunkGraphModule(module);
1391
- const hashes = cgm.hashes;
1391
+ const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
1392
1392
  return hashes && hashes.has(runtime);
1393
1393
  }
1394
1394
 
@@ -1399,7 +1399,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1399
1399
  */
1400
1400
  getModuleHash(module, runtime) {
1401
1401
  const cgm = this._getChunkGraphModule(module);
1402
- const hashes = cgm.hashes;
1402
+ const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
1403
1403
  return this._getModuleHashInfo(module, hashes, runtime).hash;
1404
1404
  }
1405
1405
 
@@ -1410,7 +1410,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1410
1410
  */
1411
1411
  getRenderedModuleHash(module, runtime) {
1412
1412
  const cgm = this._getChunkGraphModule(module);
1413
- const hashes = cgm.hashes;
1413
+ const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
1414
1414
  return this._getModuleHashInfo(module, hashes, runtime).renderedHash;
1415
1415
  }
1416
1416
 
package/lib/ChunkGroup.js CHANGED
@@ -28,6 +28,7 @@ const {
28
28
  * @typedef {Object} RawChunkGroupOptions
29
29
  * @property {number=} preloadOrder
30
30
  * @property {number=} prefetchOrder
31
+ * @property {("low" | "high" | "auto")=} fetchPriority
31
32
  */
32
33
 
33
34
  /** @typedef {RawChunkGroupOptions & { name?: string }} ChunkGroupOptions */
@@ -97,7 +98,7 @@ class ChunkGroup {
97
98
  /** Indices in bottom-up order */
98
99
  /** @private @type {Map<Module, number>} */
99
100
  this._modulePostOrderIndices = new Map();
100
- /** @type {number} */
101
+ /** @type {number | undefined} */
101
102
  this.index = undefined;
102
103
  }
103
104
 
@@ -108,9 +109,15 @@ class ChunkGroup {
108
109
  */
109
110
  addOptions(options) {
110
111
  for (const key of Object.keys(options)) {
111
- if (this.options[key] === undefined) {
112
- this.options[key] = options[key];
113
- } else if (this.options[key] !== options[key]) {
112
+ if (
113
+ this.options[/** @type {keyof ChunkGroupOptions} */ (key)] === undefined
114
+ ) {
115
+ this.options[key] =
116
+ options[/** @type {keyof ChunkGroupOptions} */ (key)];
117
+ } else if (
118
+ this.options[/** @type {keyof ChunkGroupOptions} */ (key)] !==
119
+ options[/** @type {keyof ChunkGroupOptions} */ (key)]
120
+ ) {
114
121
  if (key.endsWith("Order")) {
115
122
  this.options[key] = Math.max(this.options[key], options[key]);
116
123
  } else {
@@ -124,7 +131,7 @@ class ChunkGroup {
124
131
 
125
132
  /**
126
133
  * returns the name of current ChunkGroup
127
- * @returns {string|undefined} returns the ChunkGroup name
134
+ * @returns {string | undefined} returns the ChunkGroup name
128
135
  */
129
136
  get name() {
130
137
  return this.options.name;
@@ -132,7 +139,7 @@ class ChunkGroup {
132
139
 
133
140
  /**
134
141
  * sets a new name for current ChunkGroup
135
- * @param {string} value the new name for ChunkGroup
142
+ * @param {string | undefined} value the new name for ChunkGroup
136
143
  * @returns {void}
137
144
  */
138
145
  set name(value) {
@@ -496,7 +503,11 @@ class ChunkGroup {
496
503
  lists.set(name, (list = []));
497
504
  }
498
505
  list.push({
499
- order: childGroup.options[key],
506
+ order:
507
+ /** @type {number} */
508
+ (
509
+ childGroup.options[/** @type {keyof ChunkGroupOptions} */ (key)]
510
+ ),
500
511
  group: childGroup
501
512
  });
502
513
  }
@@ -528,7 +539,7 @@ class ChunkGroup {
528
539
  /**
529
540
  * Gets the top-down index of a module in this ChunkGroup
530
541
  * @param {Module} module the module
531
- * @returns {number} index
542
+ * @returns {number | undefined} index
532
543
  */
533
544
  getModulePreOrderIndex(module) {
534
545
  return this._modulePreOrderIndices.get(module);
@@ -547,7 +558,7 @@ class ChunkGroup {
547
558
  /**
548
559
  * Gets the bottom-up index of a module in this ChunkGroup
549
560
  * @param {Module} module the module
550
- * @returns {number} index
561
+ * @returns {number | undefined} index
551
562
  */
552
563
  getModulePostOrderIndex(module) {
553
564
  return this._modulePostOrderIndices.get(module);