webpack 5.99.9 → 5.100.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +11 -4
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +5 -2
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +34 -20
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RawModule.js +14 -0
  70. package/lib/RecordIdsPlugin.js +3 -3
  71. package/lib/RuntimeGlobals.js +175 -155
  72. package/lib/RuntimeModule.js +1 -0
  73. package/lib/RuntimePlugin.js +33 -7
  74. package/lib/RuntimeTemplate.js +111 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  76. package/lib/SourceMapDevToolPlugin.js +19 -17
  77. package/lib/Template.js +2 -2
  78. package/lib/TemplatedPathPlugin.js +1 -1
  79. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  80. package/lib/WatchIgnorePlugin.js +4 -3
  81. package/lib/WebpackIsIncludedPlugin.js +2 -1
  82. package/lib/WebpackOptionsApply.js +115 -27
  83. package/lib/asset/AssetGenerator.js +15 -11
  84. package/lib/asset/AssetModulesPlugin.js +19 -17
  85. package/lib/asset/AssetSourceGenerator.js +4 -4
  86. package/lib/asset/RawDataUrlModule.js +4 -2
  87. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  88. package/lib/buildChunkGraph.js +6 -3
  89. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  90. package/lib/cache/IdleFileCachePlugin.js +7 -4
  91. package/lib/cache/MemoryCachePlugin.js +1 -0
  92. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  93. package/lib/cache/PackFileCacheStrategy.js +26 -20
  94. package/lib/cache/ResolverCachePlugin.js +16 -8
  95. package/lib/cli.js +15 -10
  96. package/lib/config/browserslistTargetHandler.js +3 -3
  97. package/lib/config/defaults.js +25 -17
  98. package/lib/config/normalization.js +2 -1
  99. package/lib/config/target.js +6 -5
  100. package/lib/container/ContainerPlugin.js +1 -1
  101. package/lib/container/ContainerReferencePlugin.js +1 -1
  102. package/lib/container/FallbackModule.js +2 -1
  103. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  104. package/lib/container/ModuleFederationPlugin.js +2 -2
  105. package/lib/container/RemoteModule.js +1 -1
  106. package/lib/css/CssGenerator.js +9 -6
  107. package/lib/css/CssModulesPlugin.js +44 -31
  108. package/lib/css/CssParser.js +6 -4
  109. package/lib/css/walkCssTokens.js +33 -37
  110. package/lib/debug/ProfilingPlugin.js +6 -6
  111. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  112. package/lib/dependencies/AMDPlugin.js +12 -8
  113. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  114. package/lib/dependencies/CachedConstDependency.js +1 -5
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  116. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  117. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  118. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  119. package/lib/dependencies/CommonJsPlugin.js +15 -16
  120. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  121. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  123. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  124. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  125. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  126. package/lib/dependencies/DynamicExports.js +9 -9
  127. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  128. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  129. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  130. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  131. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  132. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  133. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  134. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  135. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  136. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  137. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  138. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  139. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  140. package/lib/dependencies/ImportParserPlugin.js +40 -9
  141. package/lib/dependencies/ImportPlugin.js +3 -1
  142. package/lib/dependencies/LoaderPlugin.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +3 -1
  144. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  145. package/lib/dependencies/RequireContextPlugin.js +3 -1
  146. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  147. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  148. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  149. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  150. package/lib/dependencies/SystemPlugin.js +1 -1
  151. package/lib/dependencies/URLContextDependency.js +65 -0
  152. package/lib/dependencies/URLPlugin.js +17 -157
  153. package/lib/dependencies/WorkerPlugin.js +23 -10
  154. package/lib/dependencies/processExportInfo.js +2 -1
  155. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  156. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  157. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  158. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  159. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  160. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  161. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  162. package/lib/hmr/lazyCompilationBackend.js +4 -2
  163. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  164. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  165. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  166. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  167. package/lib/ids/IdHelpers.js +21 -17
  168. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  169. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  170. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  171. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  172. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  173. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  174. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  175. package/lib/index.js +13 -3
  176. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  177. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  178. package/lib/javascript/ChunkHelpers.js +1 -0
  179. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  180. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  181. package/lib/javascript/JavascriptGenerator.js +14 -2
  182. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  183. package/lib/javascript/JavascriptParser.js +117 -76
  184. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  185. package/lib/javascript/StartupHelpers.js +17 -17
  186. package/lib/json/JsonGenerator.js +4 -2
  187. package/lib/json/JsonModulesPlugin.js +2 -2
  188. package/lib/json/JsonParser.js +1 -1
  189. package/lib/library/AbstractLibraryPlugin.js +6 -2
  190. package/lib/library/AssignLibraryPlugin.js +21 -6
  191. package/lib/library/EnableLibraryPlugin.js +23 -3
  192. package/lib/library/UmdLibraryPlugin.js +15 -6
  193. package/lib/logging/createConsoleLogger.js +3 -3
  194. package/lib/logging/runtime.js +9 -9
  195. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  196. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  197. package/lib/node/nodeConsole.js +4 -2
  198. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  199. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  200. package/lib/optimize/ConcatenatedModule.js +227 -57
  201. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  202. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  203. package/lib/optimize/InnerGraph.js +115 -112
  204. package/lib/optimize/InnerGraphPlugin.js +2 -2
  205. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  206. package/lib/optimize/MangleExportsPlugin.js +4 -3
  207. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  208. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  209. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  210. package/lib/optimize/RealContentHashPlugin.js +26 -20
  211. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  212. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  213. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  214. package/lib/optimize/SplitChunksPlugin.js +16 -13
  215. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  216. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  217. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  218. package/lib/rules/RuleSetCompiler.js +19 -5
  219. package/lib/rules/UseEffectRulePlugin.js +17 -9
  220. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  221. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  222. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  223. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  224. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  225. package/lib/schemes/FileUriPlugin.js +1 -1
  226. package/lib/schemes/HttpUriPlugin.js +27 -19
  227. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  228. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  229. package/lib/serialization/BinaryMiddleware.js +5 -4
  230. package/lib/serialization/FileMiddleware.js +7 -4
  231. package/lib/serialization/ObjectMiddleware.js +14 -8
  232. package/lib/serialization/Serializer.js +5 -3
  233. package/lib/serialization/SerializerMiddleware.js +2 -0
  234. package/lib/sharing/ConsumeSharedModule.js +1 -1
  235. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  236. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  237. package/lib/sharing/ProvideSharedModule.js +1 -1
  238. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  239. package/lib/sharing/SharePlugin.js +2 -1
  240. package/lib/sharing/ShareRuntimeModule.js +3 -5
  241. package/lib/sharing/utils.js +34 -34
  242. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  243. package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
  244. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  245. package/lib/stats/StatsFactory.js +6 -3
  246. package/lib/stats/StatsPrinter.js +6 -7
  247. package/lib/url/URLParserPlugin.js +266 -0
  248. package/lib/util/ArrayQueue.js +1 -1
  249. package/lib/util/AsyncQueue.js +1 -1
  250. package/lib/util/Hash.js +2 -0
  251. package/lib/util/IterableHelpers.js +1 -1
  252. package/lib/util/LazyBucketSortedSet.js +2 -1
  253. package/lib/util/LazySet.js +11 -6
  254. package/lib/util/ParallelismFactorCalculator.js +1 -1
  255. package/lib/util/SetHelpers.js +3 -3
  256. package/lib/util/SortableSet.js +2 -2
  257. package/lib/util/StackedCacheMap.js +3 -1
  258. package/lib/util/StackedMap.js +2 -2
  259. package/lib/util/StringXor.js +1 -0
  260. package/lib/util/TupleSet.js +1 -0
  261. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  262. package/lib/util/cleverMerge.js +95 -58
  263. package/lib/util/comparators.js +154 -127
  264. package/lib/util/compileBooleanMatcher.js +8 -3
  265. package/lib/util/concatenate.js +8 -7
  266. package/lib/util/conventions.js +72 -73
  267. package/lib/util/create-schema-validation.js +2 -1
  268. package/lib/util/createHash.js +10 -4
  269. package/lib/util/deprecation.js +69 -66
  270. package/lib/util/deterministicGrouping.js +4 -2
  271. package/lib/util/extractUrlAndGlobal.js +1 -1
  272. package/lib/util/findGraphRoots.js +2 -2
  273. package/lib/util/fs.js +30 -23
  274. package/lib/util/hash/md4.js +2 -2
  275. package/lib/util/hash/wasm-hash.js +4 -2
  276. package/lib/util/identifier.js +13 -12
  277. package/lib/util/internalSerializables.js +2 -0
  278. package/lib/util/magicComment.js +5 -5
  279. package/lib/util/processAsyncTree.js +1 -1
  280. package/lib/util/propertyAccess.js +1 -1
  281. package/lib/util/propertyName.js +1 -1
  282. package/lib/util/registerExternalSerializer.js +1 -2
  283. package/lib/util/removeBOM.js +1 -1
  284. package/lib/util/runtime.js +29 -21
  285. package/lib/util/semver.js +1 -1
  286. package/lib/util/serialization.js +3 -0
  287. package/lib/util/source.js +3 -2
  288. package/lib/validateSchema.js +1 -0
  289. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  290. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  291. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  292. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  293. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  294. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  295. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  296. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  297. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  298. package/lib/webpack.js +4 -5
  299. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  300. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  301. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  302. package/package.json +119 -113
  303. package/schemas/WebpackOptions.check.js +1 -1
  304. package/schemas/WebpackOptions.json +17 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  306. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  307. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  308. package/types.d.ts +1243 -409
@@ -344,14 +344,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
344
344
  const processedFiles = cmf.hooks.contextModuleFiles.call(
345
345
  /** @type {string[]} */ (files).map(file => file.normalize("NFC"))
346
346
  );
347
- if (!processedFiles || processedFiles.length === 0)
347
+ if (!processedFiles || processedFiles.length === 0) {
348
348
  return callback(null, []);
349
+ }
349
350
  asyncLib.map(
350
351
  processedFiles.filter(p => p.indexOf(".") !== 0),
351
352
  (segment, callback) => {
352
353
  const subResource = join(fs, directory, segment);
353
354
 
354
- if (!exclude || !subResource.match(exclude)) {
355
+ if (!exclude || !exclude.test(subResource)) {
355
356
  fs.stat(subResource, (err, _stat) => {
356
357
  if (err) {
357
358
  if (err.code === "ENOENT") {
@@ -369,7 +370,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
369
370
  addSubDirectory(ctx, subResource, callback);
370
371
  } else if (
371
372
  stat.isFile() &&
372
- (!include || subResource.match(include))
373
+ (!include || include.test(subResource))
373
374
  ) {
374
375
  /** @type {{ context: string, request: string }} */
375
376
  const obj = {
@@ -131,7 +131,8 @@ class ContextReplacementPlugin {
131
131
  result.resource = newContentResource;
132
132
  } else {
133
133
  result.resource = join(
134
- /** @type {InputFileSystem} */ (compiler.inputFileSystem),
134
+ /** @type {InputFileSystem} */
135
+ (compiler.inputFileSystem),
135
136
  result.resource,
136
137
  newContentResource
137
138
  );
@@ -159,7 +160,8 @@ class ContextReplacementPlugin {
159
160
  ) {
160
161
  // When the function changed it to an relative path
161
162
  result.resource = join(
162
- /** @type {InputFileSystem} */ (compiler.inputFileSystem),
163
+ /** @type {InputFileSystem} */
164
+ (compiler.inputFileSystem),
163
165
  origResource,
164
166
  result.resource
165
167
  );
package/lib/CssModule.js CHANGED
@@ -18,9 +18,9 @@ const makeSerializable = require("./util/makeSerializable");
18
18
  /** @typedef {string | undefined} Supports */
19
19
  /** @typedef {string | undefined} Media */
20
20
  /** @typedef {[CssLayer, Supports, Media]} InheritanceItem */
21
- /** @typedef {Array<InheritanceItem>} Inheritance */
21
+ /** @typedef {InheritanceItem[]} Inheritance */
22
22
 
23
- /** @typedef {NormalModuleCreateData & { cssLayer: CssLayer, supports: Supports, media: Media, inheritance: Inheritance }} CSSModuleCreateData */
23
+ /** @typedef {NormalModuleCreateData & { cssLayer: CssLayer, supports: Supports, media: Media, inheritance?: Inheritance }} CSSModuleCreateData */
24
24
 
25
25
  class CssModule extends NormalModule {
26
26
  /**
@@ -7,8 +7,8 @@
7
7
 
8
8
  const {
9
9
  JAVASCRIPT_MODULE_TYPE_AUTO,
10
- JAVASCRIPT_MODULE_TYPE_ESM,
11
- JAVASCRIPT_MODULE_TYPE_DYNAMIC
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
11
+ JAVASCRIPT_MODULE_TYPE_ESM
12
12
  } = require("./ModuleTypeConstants");
13
13
  const RuntimeGlobals = require("./RuntimeGlobals");
14
14
  const WebpackError = require("./WebpackError");
@@ -356,6 +356,16 @@ class DefinePlugin {
356
356
  */
357
357
  apply(compiler) {
358
358
  const definitions = this.definitions;
359
+
360
+ /**
361
+ * @type {Map<string, Set<string>>}
362
+ */
363
+ const finalByNestedKey = new Map();
364
+ /**
365
+ * @type {Map<string, Set<string>>}
366
+ */
367
+ const nestedByFinalKey = new Map();
368
+
359
369
  compiler.hooks.compilation.tap(
360
370
  PLUGIN_NAME,
361
371
  (compilation, { normalModuleFactory }) => {
@@ -381,6 +391,7 @@ class DefinePlugin {
381
391
  * @returns {void}
382
392
  */
383
393
  const handler = parser => {
394
+ const hooked = new Set();
384
395
  const mainValue =
385
396
  /** @type {ValueCacheVersion} */
386
397
  (compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
@@ -388,8 +399,9 @@ class DefinePlugin {
388
399
  const buildInfo = /** @type {BuildInfo} */ (
389
400
  parser.state.module.buildInfo
390
401
  );
391
- if (!buildInfo.valueDependencies)
402
+ if (!buildInfo.valueDependencies) {
392
403
  buildInfo.valueDependencies = new Map();
404
+ }
393
405
  buildInfo.valueDependencies.set(VALUE_DEP_MAIN, mainValue);
394
406
  });
395
407
 
@@ -469,6 +481,61 @@ class DefinePlugin {
469
481
  return true;
470
482
  });
471
483
  }
484
+ if (prefix === "") {
485
+ const final = splittedKey[splittedKey.length - 1];
486
+ const nestedSet = nestedByFinalKey.get(final);
487
+ if (!nestedSet || nestedSet.size <= 0) return;
488
+ for (const nested of /** @type {Set<string>} */ (nestedSet)) {
489
+ if (nested && !hooked.has(nested)) {
490
+ // only detect the same nested key once
491
+ hooked.add(nested);
492
+ parser.hooks.expression.for(nested).tap(
493
+ {
494
+ name: PLUGIN_NAME,
495
+ // why 100? Ensures it runs after object define
496
+ stage: 100
497
+ },
498
+ expr => {
499
+ const destructed =
500
+ parser.destructuringAssignmentPropertiesFor(expr);
501
+ if (destructed === undefined) {
502
+ return;
503
+ }
504
+ /** @type {Record<string, CodeValue>} */
505
+ const obj = {};
506
+ const finalSet = finalByNestedKey.get(nested);
507
+ for (const { id } of destructed) {
508
+ const fullKey = `${nested}.${id}`;
509
+ if (
510
+ !finalSet ||
511
+ !finalSet.has(id) ||
512
+ !definitions[fullKey]
513
+ ) {
514
+ return;
515
+ }
516
+ obj[id] = definitions[fullKey];
517
+ }
518
+ let strCode = stringifyObj(
519
+ obj,
520
+ parser,
521
+ compilation.valueCacheVersions,
522
+ key,
523
+ runtimeTemplate,
524
+ logger,
525
+ !parser.isAsiPosition(
526
+ /** @type {Range} */ (expr.range)[0]
527
+ ),
528
+ getObjKeys(destructed)
529
+ );
530
+ if (parser.scope.inShorthand) {
531
+ strCode = `${parser.scope.inShorthand}:${strCode}`;
532
+ }
533
+ return toConstantDependency(parser, strCode)(expr);
534
+ }
535
+ );
536
+ }
537
+ }
538
+ }
472
539
  };
473
540
 
474
541
  /**
@@ -707,6 +774,46 @@ class DefinePlugin {
707
774
  }
708
775
  };
709
776
 
777
+ /**
778
+ * @param {Record<string, CodeValue>} definitions Definitions map
779
+ * @returns {void}
780
+ */
781
+ const walkDefinitionsForKeys = definitions => {
782
+ /**
783
+ * @param {Map<string, Set<string>>} map Map
784
+ * @param {string} key key
785
+ * @param {string} value v
786
+ * @returns {void}
787
+ */
788
+ const addToMap = (map, key, value) => {
789
+ if (map.has(key)) {
790
+ /** @type {Set<string>} */
791
+ (map.get(key)).add(value);
792
+ } else {
793
+ map.set(key, new Set([value]));
794
+ }
795
+ };
796
+ for (const key of Object.keys(definitions)) {
797
+ const code = definitions[key];
798
+ if (
799
+ !code ||
800
+ typeof code === "object" ||
801
+ TYPEOF_OPERATOR_REGEXP.test(key)
802
+ ) {
803
+ continue;
804
+ }
805
+ const idx = key.lastIndexOf(".");
806
+ if (idx <= 0 || idx >= key.length - 1) {
807
+ continue;
808
+ }
809
+ const nested = key.slice(0, idx);
810
+ const final = key.slice(idx + 1);
811
+ addToMap(finalByNestedKey, nested, final);
812
+ addToMap(nestedByFinalKey, final, nested);
813
+ }
814
+ };
815
+
816
+ walkDefinitionsForKeys(definitions);
710
817
  walkDefinitionsForValues(definitions, "");
711
818
 
712
819
  compilation.valueCacheVersions.set(
@@ -717,4 +824,5 @@ class DefinePlugin {
717
824
  );
718
825
  }
719
826
  }
827
+
720
828
  module.exports = DefinePlugin;
@@ -25,6 +25,8 @@ const DelegatedModule = require("./DelegatedModule");
25
25
  * @property {AssociatedObjectForCache=} associatedObjectForCache object for caching
26
26
  */
27
27
 
28
+ const PLUGIN_NAME = "DelegatedModuleFactoryPlugin";
29
+
28
30
  class DelegatedModuleFactoryPlugin {
29
31
  /**
30
32
  * @param {Options} options options
@@ -43,7 +45,7 @@ class DelegatedModuleFactoryPlugin {
43
45
  const scope = this.options.scope;
44
46
  if (scope) {
45
47
  normalModuleFactory.hooks.factorize.tapAsync(
46
- "DelegatedModuleFactoryPlugin",
48
+ PLUGIN_NAME,
47
49
  (data, callback) => {
48
50
  const [dependency] = data.dependencies;
49
51
  const { request } = dependency;
@@ -90,25 +92,23 @@ class DelegatedModuleFactoryPlugin {
90
92
  }
91
93
  );
92
94
  } else {
93
- normalModuleFactory.hooks.module.tap(
94
- "DelegatedModuleFactoryPlugin",
95
- module => {
96
- const request = module.libIdent(this.options);
97
- if (request && request in this.options.content) {
98
- const resolved = this.options.content[request];
99
- return new DelegatedModule(
100
- this.options.source,
101
- resolved,
102
- /** @type {DelegatedModuleType} */
103
- (this.options.type),
104
- request,
105
- module
106
- );
107
- }
108
- return module;
95
+ normalModuleFactory.hooks.module.tap(PLUGIN_NAME, module => {
96
+ const request = module.libIdent(this.options);
97
+ if (request && request in this.options.content) {
98
+ const resolved = this.options.content[request];
99
+ return new DelegatedModule(
100
+ this.options.source,
101
+ resolved,
102
+ /** @type {DelegatedModuleType} */
103
+ (this.options.type),
104
+ request,
105
+ module
106
+ );
109
107
  }
110
- );
108
+ return module;
109
+ });
111
110
  }
112
111
  }
113
112
  }
113
+
114
114
  module.exports = DelegatedModuleFactoryPlugin;
package/lib/Dependency.js CHANGED
@@ -85,9 +85,11 @@ const memoize = require("./util/memoize");
85
85
 
86
86
  const TRANSITIVE = Symbol("transitive");
87
87
 
88
- const getIgnoredModule = memoize(
89
- () => new RawModule("/* (ignored) */", "ignored", "(ignored)")
90
- );
88
+ const getIgnoredModule = memoize(() => {
89
+ const module = new RawModule("/* (ignored) */", "ignored", "(ignored)");
90
+ module.factoryMeta = { sideEffectFree: true };
91
+ return module;
92
+ });
91
93
 
92
94
  class Dependency {
93
95
  constructor() {
@@ -101,7 +103,10 @@ class Dependency {
101
103
  /** @type {boolean} */
102
104
  this.weak = false;
103
105
  // TODO check if this can be moved into ModuleDependency
104
- /** @type {boolean} */
106
+ /** @type {boolean | undefined} */
107
+ this.defer = false;
108
+ // TODO check if this can be moved into ModuleDependency
109
+ /** @type {boolean | undefined} */
105
110
  this.optional = false;
106
111
  this._locSL = 0;
107
112
  this._locSC = 0;
@@ -309,6 +314,7 @@ class Dependency {
309
314
  write(this._locEC);
310
315
  write(this._locI);
311
316
  write(this._locN);
317
+ write(this.defer);
312
318
  }
313
319
 
314
320
  /**
@@ -323,6 +329,7 @@ class Dependency {
323
329
  this._locEC = read();
324
330
  this._locI = read();
325
331
  this._locN = read();
332
+ this.defer = read();
326
333
  }
327
334
  }
328
335
 
@@ -62,6 +62,7 @@ class DependencyTemplate {
62
62
  */
63
63
  apply(dependency, source, templateContext) {
64
64
  const AbstractMethodError = require("./AbstractMethodError");
65
+
65
66
  throw new AbstractMethodError();
66
67
  }
67
68
  }
@@ -10,8 +10,10 @@ const DllEntryDependency = require("./dependencies/DllEntryDependency");
10
10
  const EntryDependency = require("./dependencies/EntryDependency");
11
11
 
12
12
  /** @typedef {import("./Compiler")} Compiler */
13
+ /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
14
+
13
15
  /** @typedef {string[]} Entries */
14
- /** @typedef {{ name: string, filename: TODO }} Options */
16
+ /** @typedef {EntryOptions & { name: string }} Options */
15
17
 
16
18
  const PLUGIN_NAME = "DllEntryPlugin";
17
19
 
package/lib/DllPlugin.js CHANGED
@@ -16,7 +16,7 @@ const createSchemaValidation = require("./util/create-schema-validation");
16
16
  /** @typedef {import("./DllEntryPlugin").Options} Options */
17
17
 
18
18
  const validate = createSchemaValidation(
19
- require("../schemas/plugins/DllPlugin.check.js"),
19
+ require("../schemas/plugins/DllPlugin.check"),
20
20
  () => require("../schemas/plugins/DllPlugin.json"),
21
21
  {
22
22
  name: "Dll Plugin",
@@ -48,10 +48,11 @@ class DllPlugin {
48
48
  if (typeof entry !== "function") {
49
49
  for (const name of Object.keys(entry)) {
50
50
  /** @type {Options} */
51
- const options = { name, filename: entry.filename };
51
+ const options = { name };
52
52
  new DllEntryPlugin(
53
53
  context,
54
- /** @type {Entries} */ (entry[name].import),
54
+ /** @type {Entries} */
55
+ (entry[name].import),
55
56
  options
56
57
  ).apply(compiler);
57
58
  }
@@ -22,7 +22,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
22
22
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
23
23
 
24
24
  const validate = createSchemaValidation(
25
- require("../schemas/plugins/DllReferencePlugin.check.js"),
25
+ require("../schemas/plugins/DllReferencePlugin.check"),
26
26
  () => require("../schemas/plugins/DllReferencePlugin.json"),
27
27
  {
28
28
  name: "Dll Reference Plugin",
@@ -78,7 +78,7 @@ class DllReferencePlugin {
78
78
  // or malformed manifest files don't kill the process.
79
79
  try {
80
80
  data.data = parseJson(
81
- /** @type {Buffer} */ (result).toString("utf-8")
81
+ /** @type {Buffer} */ (result).toString("utf8")
82
82
  );
83
83
  } catch (parseErr) {
84
84
  // Store the error in the params so that it can
@@ -80,7 +80,7 @@ class DynamicEntryPlugin {
80
80
  }
81
81
  return Promise.all(promises);
82
82
  })
83
- .then(x => {})
83
+ .then(() => {})
84
84
  );
85
85
  }
86
86
  }
@@ -33,9 +33,11 @@ class EntryOptionPlugin {
33
33
  static applyEntryOption(compiler, context, entry) {
34
34
  if (typeof entry === "function") {
35
35
  const DynamicEntryPlugin = require("./DynamicEntryPlugin");
36
+
36
37
  new DynamicEntryPlugin(context, entry).apply(compiler);
37
38
  } else {
38
39
  const EntryPlugin = require("./EntryPlugin");
40
+
39
41
  for (const name of Object.keys(entry)) {
40
42
  const desc = entry[name];
41
43
  const options = EntryOptionPlugin.entryDescriptionToOptions(
@@ -81,14 +83,17 @@ class EntryOptionPlugin {
81
83
  }
82
84
  if (desc.chunkLoading) {
83
85
  const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
86
+
84
87
  EnableChunkLoadingPlugin.checkEnabled(compiler, desc.chunkLoading);
85
88
  }
86
89
  if (desc.wasmLoading) {
87
90
  const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin");
91
+
88
92
  EnableWasmLoadingPlugin.checkEnabled(compiler, desc.wasmLoading);
89
93
  }
90
94
  if (desc.library) {
91
95
  const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
96
+
92
97
  EnableLibraryPlugin.checkEnabled(compiler, desc.library.type);
93
98
  }
94
99
  return options;
@@ -91,10 +91,10 @@ const cleanUpWebpackOptions = (stack, message) => {
91
91
  return stack;
92
92
  };
93
93
 
94
+ module.exports.cleanUp = cleanUp;
95
+ module.exports.cleanUpWebpackOptions = cleanUpWebpackOptions;
94
96
  module.exports.cutOffByFlag = cutOffByFlag;
95
97
  module.exports.cutOffLoaderExecution = cutOffLoaderExecution;
96
- module.exports.cutOffWebpackOptions = cutOffWebpackOptions;
97
- module.exports.cutOffMultilineMessage = cutOffMultilineMessage;
98
98
  module.exports.cutOffMessage = cutOffMessage;
99
- module.exports.cleanUp = cleanUp;
100
- module.exports.cleanUpWebpackOptions = cleanUpWebpackOptions;
99
+ module.exports.cutOffMultilineMessage = cutOffMultilineMessage;
100
+ module.exports.cutOffWebpackOptions = cutOffWebpackOptions;
@@ -95,9 +95,9 @@ class EvalDevToolModulePlugin {
95
95
  `eval(${
96
96
  compilation.outputOptions.trustedTypes
97
97
  ? `${RuntimeGlobals.createScript}(${JSON.stringify(
98
- content + footer
98
+ `{${content + footer}\n}`
99
99
  )})`
100
- : JSON.stringify(content + footer)
100
+ : JSON.stringify(`{${content + footer}\n}`)
101
101
  });`
102
102
  );
103
103
  cache.set(source, result);
@@ -119,7 +119,7 @@ class EvalDevToolModulePlugin {
119
119
  if (compilation.outputOptions.trustedTypes) {
120
120
  compilation.hooks.additionalModuleRuntimeRequirements.tap(
121
121
  PLUGIN_NAME,
122
- (module, set, context) => {
122
+ (module, set, _context) => {
123
123
  set.add(RuntimeGlobals.createScript);
124
124
  }
125
125
  );
@@ -15,12 +15,12 @@ const ConcatenatedModule = require("./optimize/ConcatenatedModule");
15
15
  const generateDebugId = require("./util/generateDebugId");
16
16
  const { makePathsAbsolute } = require("./util/identifier");
17
17
 
18
+ /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
18
19
  /** @typedef {import("webpack-sources").Source} Source */
19
20
  /** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */
20
21
  /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
21
22
  /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
22
23
  /** @typedef {import("./Compiler")} Compiler */
23
- /** @typedef {import("./NormalModule").SourceMap} SourceMap */
24
24
 
25
25
  /** @type {WeakMap<Source, Source>} */
26
26
  const cache = new WeakMap();
@@ -117,15 +117,15 @@ class EvalSourceMapDevToolPlugin {
117
117
  const namespace = compilation.getPath(this.namespace, {
118
118
  chunk
119
119
  });
120
- /** @type {SourceMap} */
120
+ /** @type {RawSourceMap} */
121
121
  let sourceMap;
122
122
  let content;
123
123
  if (source.sourceAndMap) {
124
124
  const sourceAndMap = source.sourceAndMap(options);
125
- sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
125
+ sourceMap = /** @type {RawSourceMap} */ (sourceAndMap.map);
126
126
  content = sourceAndMap.source;
127
127
  } else {
128
- sourceMap = /** @type {SourceMap} */ (source.map(options));
128
+ sourceMap = /** @type {RawSourceMap} */ (source.map(options));
129
129
  content = source.source();
130
130
  }
131
131
  if (!sourceMap) {
@@ -191,16 +191,16 @@ class EvalSourceMapDevToolPlugin {
191
191
  `eval(${
192
192
  compilation.outputOptions.trustedTypes
193
193
  ? `${RuntimeGlobals.createScript}(${JSON.stringify(
194
- content + footer
194
+ `{${content + footer}\n}`
195
195
  )})`
196
- : JSON.stringify(content + footer)
196
+ : JSON.stringify(`{${content + footer}\n}`)
197
197
  });`
198
198
  )
199
199
  );
200
200
  }
201
201
  );
202
202
  hooks.inlineInRuntimeBailout.tap(
203
- "EvalDevToolModulePlugin",
203
+ PLUGIN_NAME,
204
204
  () => "the eval-source-map devtool is used."
205
205
  );
206
206
  hooks.render.tap(