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
@@ -5,34 +5,37 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_ESM
11
+ } = require("../ModuleTypeConstants");
8
12
  const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
9
13
  const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
10
14
  const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
15
+ const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
11
16
  const HarmonyEvaluatedImportSpecifierDependency = require("./HarmonyEvaluatedImportSpecifierDependency");
17
+ const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
12
18
  const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
13
19
  const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
14
20
  const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
15
21
  const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
22
+ const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
16
23
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
17
24
  const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
18
25
 
19
- const {
20
- JAVASCRIPT_MODULE_TYPE_AUTO,
21
- JAVASCRIPT_MODULE_TYPE_ESM
22
- } = require("../ModuleTypeConstants");
23
- const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
24
- const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
25
- const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
26
26
  const HarmonyTopLevelThisParserPlugin = require("./HarmonyTopLevelThisParserPlugin");
27
27
 
28
28
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
29
29
  /** @typedef {import("../Compiler")} Compiler */
30
30
  /** @typedef {import("../javascript/JavascriptParser")} Parser */
31
+ /**
32
+ * @typedef HarmonyModulesPluginOptions
33
+ * @property {boolean=} topLevelAwait
34
+ * @property {boolean=} deferImport
35
+ */
31
36
 
32
37
  const PLUGIN_NAME = "HarmonyModulesPlugin";
33
38
 
34
- /** @typedef {{ topLevelAwait?: boolean }} HarmonyModulesPluginOptions */
35
-
36
39
  class HarmonyModulesPlugin {
37
40
  /**
38
41
  * @param {HarmonyModulesPluginOptions} options options
@@ -127,12 +130,19 @@ class HarmonyModulesPlugin {
127
130
  */
128
131
  const handler = (parser, parserOptions) => {
129
132
  // TODO webpack 6: rename harmony to esm or module
130
- if (parserOptions.harmony !== undefined && !parserOptions.harmony)
133
+ if (parserOptions.harmony !== undefined && !parserOptions.harmony) {
131
134
  return;
135
+ }
132
136
 
133
137
  new HarmonyDetectionParserPlugin(this.options).apply(parser);
134
- new HarmonyImportDependencyParserPlugin(parserOptions).apply(parser);
135
- new HarmonyExportDependencyParserPlugin(parserOptions).apply(parser);
138
+ new HarmonyImportDependencyParserPlugin(
139
+ parserOptions,
140
+ this.options.deferImport
141
+ ).apply(parser);
142
+ new HarmonyExportDependencyParserPlugin(
143
+ parserOptions,
144
+ this.options.deferImport
145
+ ).apply(parser);
136
146
  new HarmonyTopLevelThisParserPlugin().apply(parser);
137
147
  };
138
148
 
@@ -146,4 +156,5 @@ class HarmonyModulesPlugin {
146
156
  );
147
157
  }
148
158
  }
159
+
149
160
  module.exports = HarmonyModulesPlugin;
@@ -186,6 +186,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
186
186
  })
187
187
  ) {
188
188
  exports = [];
189
+
189
190
  for (const i1 of items) {
190
191
  /** @type {string[]} */
191
192
  const export_ = [];
@@ -52,8 +52,9 @@ class ImportMetaContextPlugin {
52
52
  if (
53
53
  parserOptions.importMetaContext !== undefined &&
54
54
  !parserOptions.importMetaContext
55
- )
55
+ ) {
56
56
  return;
57
+ }
57
58
 
58
59
  new ImportMetaContextDependencyParserPlugin().apply(parser);
59
60
  };
@@ -15,9 +15,9 @@ const Template = require("../Template");
15
15
  const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
16
16
  const {
17
17
  evaluateToIdentifier,
18
- toConstantDependency,
18
+ evaluateToNumber,
19
19
  evaluateToString,
20
- evaluateToNumber
20
+ toConstantDependency
21
21
  } = require("../javascript/JavascriptParserHelpers");
22
22
  const memoize = require("../util/memoize");
23
23
  const propertyAccess = require("../util/propertyAccess");
@@ -24,6 +24,8 @@ const ImportWeakDependency = require("./ImportWeakDependency");
24
24
  /** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */
25
25
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
26
26
 
27
+ const PLUGIN_NAME = "ImportParserPlugin";
28
+
27
29
  class ImportParserPlugin {
28
30
  /**
29
31
  * @param {JavascriptParserOptions} options options
@@ -44,7 +46,7 @@ class ImportParserPlugin {
44
46
  */
45
47
  const exportsFromEnumerable = enumerable =>
46
48
  Array.from(enumerable, e => [e]);
47
- parser.hooks.importCall.tap("ImportParserPlugin", expr => {
49
+ parser.hooks.importCall.tap(PLUGIN_NAME, expr => {
48
50
  const param = parser.evaluateExpression(expr.source);
49
51
 
50
52
  let chunkName = null;
@@ -61,20 +63,26 @@ class ImportParserPlugin {
61
63
  dynamicImportPrefetch,
62
64
  dynamicImportFetchPriority
63
65
  } = this.options;
64
- if (dynamicImportPreload !== undefined && dynamicImportPreload !== false)
66
+ if (
67
+ dynamicImportPreload !== undefined &&
68
+ dynamicImportPreload !== false
69
+ ) {
65
70
  groupOptions.preloadOrder =
66
71
  dynamicImportPreload === true ? 0 : dynamicImportPreload;
72
+ }
67
73
  if (
68
74
  dynamicImportPrefetch !== undefined &&
69
75
  dynamicImportPrefetch !== false
70
- )
76
+ ) {
71
77
  groupOptions.prefetchOrder =
72
78
  dynamicImportPrefetch === true ? 0 : dynamicImportPrefetch;
79
+ }
73
80
  if (
74
81
  dynamicImportFetchPriority !== undefined &&
75
82
  dynamicImportFetchPriority !== false
76
- )
83
+ ) {
77
84
  groupOptions.fetchPriority = dynamicImportFetchPriority;
85
+ }
78
86
 
79
87
  const { options: importOptions, errors: commentErrors } =
80
88
  parser.parseCommentOptions(/** @type {Range} */ (expr.range));
@@ -91,6 +99,28 @@ class ImportParserPlugin {
91
99
  }
92
100
  }
93
101
 
102
+ let phase = expr.phase;
103
+ if (!phase && importOptions && importOptions.webpackDefer !== undefined) {
104
+ if (typeof importOptions.webpackDefer !== "boolean") {
105
+ parser.state.module.addWarning(
106
+ new UnsupportedFeatureWarning(
107
+ `\`webpackDefer\` expected a boolean, but received: ${importOptions.webpackDefer}.`,
108
+ /** @type {DependencyLocation} */ (expr.loc)
109
+ )
110
+ );
111
+ } else if (importOptions.webpackDefer) {
112
+ phase = "defer";
113
+ }
114
+ }
115
+ if (phase === "defer") {
116
+ parser.state.module.addWarning(
117
+ new UnsupportedFeatureWarning(
118
+ "import.defer() is not implemented yet.",
119
+ /** @type {DependencyLocation} */ (expr.loc)
120
+ )
121
+ );
122
+ }
123
+
94
124
  if (importOptions) {
95
125
  if (importOptions.webpackIgnore !== undefined) {
96
126
  if (typeof importOptions.webpackIgnore !== "boolean") {
@@ -254,6 +284,7 @@ class ImportParserPlugin {
254
284
  )
255
285
  );
256
286
  }
287
+
257
288
  exports = exportsFromEnumerable(
258
289
  [...referencedPropertiesInDestructuring].map(({ id }) => id)
259
290
  );
@@ -315,11 +346,11 @@ class ImportParserPlugin {
315
346
  include,
316
347
  exclude,
317
348
  mode,
318
- namespaceObject: /** @type {BuildMeta} */ (
319
- parser.state.module.buildMeta
320
- ).strictHarmonyModule
321
- ? "strict"
322
- : true,
349
+ namespaceObject:
350
+ /** @type {BuildMeta} */
351
+ (parser.state.module.buildMeta).strictHarmonyModule
352
+ ? "strict"
353
+ : true,
323
354
  typePrefix: "import()",
324
355
  category: "esm",
325
356
  referencedExports: exports,
@@ -74,8 +74,9 @@ class ImportPlugin {
74
74
  * @returns {void}
75
75
  */
76
76
  const handler = (parser, parserOptions) => {
77
- if (parserOptions.import !== undefined && !parserOptions.import)
77
+ if (parserOptions.import !== undefined && !parserOptions.import) {
78
78
  return;
79
+ }
79
80
 
80
81
  new ImportParserPlugin(parserOptions).apply(parser);
81
82
  };
@@ -93,4 +94,5 @@ class ImportPlugin {
93
94
  );
94
95
  }
95
96
  }
97
+
96
98
  module.exports = ImportPlugin;
@@ -281,4 +281,5 @@ class LoaderPlugin {
281
281
  });
282
282
  }
283
283
  }
284
+
284
285
  module.exports = LoaderPlugin;
@@ -61,11 +61,13 @@ class ModuleDependency extends Dependency {
61
61
  * @returns {Module} ignored module
62
62
  */
63
63
  createIgnoredModule(context) {
64
- return new RawModule(
64
+ const module = new RawModule(
65
65
  "/* (ignored) */",
66
66
  `ignored|${context}|${this.request}`,
67
67
  `${this.request} (ignored)`
68
68
  );
69
+ module.factoryMeta = { sideEffectFree: true };
70
+ return module;
69
71
  }
70
72
 
71
73
  /**
@@ -35,4 +35,5 @@ class ModuleDependencyTemplateAsRequireId extends ModuleDependency.Template {
35
35
  source.replace(dep.range[0], dep.range[1] - 1, content);
36
36
  }
37
37
  }
38
+
38
39
  module.exports = ModuleDependencyTemplateAsRequireId;
@@ -57,8 +57,9 @@ class RequireContextPlugin {
57
57
  if (
58
58
  parserOptions.requireContext !== undefined &&
59
59
  !parserOptions.requireContext
60
- )
60
+ ) {
61
61
  return;
62
+ }
62
63
 
63
64
  new RequireContextDependencyParserPlugin().apply(parser);
64
65
  };
@@ -161,4 +162,5 @@ class RequireContextPlugin {
161
162
  );
162
163
  }
163
164
  }
165
+
164
166
  module.exports = RequireContextPlugin;
@@ -5,11 +5,6 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const RequireEnsureDependency = require("./RequireEnsureDependency");
9
- const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
10
-
11
- const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
12
-
13
8
  const {
14
9
  JAVASCRIPT_MODULE_TYPE_AUTO,
15
10
  JAVASCRIPT_MODULE_TYPE_DYNAMIC
@@ -18,6 +13,9 @@ const {
18
13
  evaluateToString,
19
14
  toConstantDependency
20
15
  } = require("../javascript/JavascriptParserHelpers");
16
+ const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
17
+ const RequireEnsureDependency = require("./RequireEnsureDependency");
18
+ const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
21
19
 
22
20
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
23
21
  /** @typedef {import("../Compiler")} Compiler */
@@ -58,8 +56,9 @@ class RequireEnsurePlugin {
58
56
  if (
59
57
  parserOptions.requireEnsure !== undefined &&
60
58
  !parserOptions.requireEnsure
61
- )
59
+ ) {
62
60
  return;
61
+ }
63
62
 
64
63
  new RequireEnsureDependenciesBlockParserPlugin().apply(parser);
65
64
  parser.hooks.evaluateTypeof
@@ -83,4 +82,5 @@ class RequireEnsurePlugin {
83
82
  );
84
83
  }
85
84
  }
85
+
86
86
  module.exports = RequireEnsurePlugin;
@@ -17,6 +17,8 @@ const RequireIncludeDependency = require("./RequireIncludeDependency");
17
17
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
18
18
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
19
 
20
+ const PLUGIN_NAME = "RequireIncludeDependencyParserPlugin";
21
+
20
22
  module.exports = class RequireIncludeDependencyParserPlugin {
21
23
  /**
22
24
  * @param {boolean} warn true: warn about deprecation, false: don't warn
@@ -31,32 +33,31 @@ module.exports = class RequireIncludeDependencyParserPlugin {
31
33
  */
32
34
  apply(parser) {
33
35
  const { warn } = this;
34
- parser.hooks.call
35
- .for("require.include")
36
- .tap("RequireIncludeDependencyParserPlugin", expr => {
37
- if (expr.arguments.length !== 1) return;
38
- const param = parser.evaluateExpression(expr.arguments[0]);
39
- if (!param.isString()) return;
36
+ parser.hooks.call.for("require.include").tap(PLUGIN_NAME, expr => {
37
+ if (expr.arguments.length !== 1) return;
38
+ const param = parser.evaluateExpression(expr.arguments[0]);
39
+ if (!param.isString()) return;
40
40
 
41
- if (warn) {
42
- parser.state.module.addWarning(
43
- new RequireIncludeDeprecationWarning(
44
- /** @type {DependencyLocation} */ (expr.loc)
45
- )
46
- );
47
- }
48
-
49
- const dep = new RequireIncludeDependency(
50
- /** @type {string} */ (param.string),
51
- /** @type {Range} */ (expr.range)
41
+ if (warn) {
42
+ parser.state.module.addWarning(
43
+ new RequireIncludeDeprecationWarning(
44
+ /** @type {DependencyLocation} */
45
+ (expr.loc)
46
+ )
52
47
  );
53
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
54
- parser.state.current.addDependency(dep);
55
- return true;
56
- });
48
+ }
49
+
50
+ const dep = new RequireIncludeDependency(
51
+ /** @type {string} */ (param.string),
52
+ /** @type {Range} */ (expr.range)
53
+ );
54
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
55
+ parser.state.current.addDependency(dep);
56
+ return true;
57
+ });
57
58
  parser.hooks.evaluateTypeof
58
59
  .for("require.include")
59
- .tap("RequireIncludePlugin", expr => {
60
+ .tap(PLUGIN_NAME, expr => {
60
61
  if (warn) {
61
62
  parser.state.module.addWarning(
62
63
  new RequireIncludeDeprecationWarning(
@@ -66,18 +67,16 @@ module.exports = class RequireIncludeDependencyParserPlugin {
66
67
  }
67
68
  return evaluateToString("function")(expr);
68
69
  });
69
- parser.hooks.typeof
70
- .for("require.include")
71
- .tap("RequireIncludePlugin", expr => {
72
- if (warn) {
73
- parser.state.module.addWarning(
74
- new RequireIncludeDeprecationWarning(
75
- /** @type {DependencyLocation} */ (expr.loc)
76
- )
77
- );
78
- }
79
- return toConstantDependency(parser, JSON.stringify("function"))(expr);
80
- });
70
+ parser.hooks.typeof.for("require.include").tap(PLUGIN_NAME, expr => {
71
+ if (warn) {
72
+ parser.state.module.addWarning(
73
+ new RequireIncludeDeprecationWarning(
74
+ /** @type {DependencyLocation} */ (expr.loc)
75
+ )
76
+ );
77
+ }
78
+ return toConstantDependency(parser, JSON.stringify("function"))(expr);
79
+ });
81
80
  }
82
81
  };
83
82
 
@@ -59,4 +59,5 @@ class RequireIncludePlugin {
59
59
  );
60
60
  }
61
61
  }
62
+
62
63
  module.exports = RequireIncludePlugin;
@@ -36,7 +36,7 @@ class RuntimeRequirementsDependency extends NullDependency {
36
36
  */
37
37
  updateHash(hash, context) {
38
38
  if (this._hashUpdate === undefined) {
39
- this._hashUpdate = `${Array.from(this.runtimeRequirements).join()}`;
39
+ this._hashUpdate = `${[...this.runtimeRequirements].join()}`;
40
40
  }
41
41
  hash.update(this._hashUpdate);
42
42
  }
@@ -46,7 +46,7 @@ class SystemPlugin {
46
46
 
47
47
  compilation.hooks.runtimeRequirementInTree
48
48
  .for(RuntimeGlobals.system)
49
- .tap(PLUGIN_NAME, (chunk, set) => {
49
+ .tap(PLUGIN_NAME, (chunk, _set) => {
50
50
  compilation.addRuntimeModule(chunk, new SystemRuntimeModule());
51
51
  });
52
52
 
@@ -0,0 +1,65 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Haijie Xie @hai-x
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const ContextDependency = require("./ContextDependency");
10
+ const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
11
+
12
+ /** @typedef {import("../ContextModule").ContextOptions} ContextOptions */
13
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
+
17
+ /** @typedef {ContextOptions & { request: string }} ContextDependencyOptions */
18
+
19
+ class URLContextDependency extends ContextDependency {
20
+ /**
21
+ * @param {ContextDependencyOptions} options options
22
+ * @param {Range} range range
23
+ * @param {Range} valueRange value range
24
+ */
25
+ constructor(options, range, valueRange) {
26
+ super(options);
27
+ this.range = range;
28
+ this.valueRange = valueRange;
29
+ }
30
+
31
+ get type() {
32
+ return "new URL() context";
33
+ }
34
+
35
+ get category() {
36
+ return "url";
37
+ }
38
+
39
+ /**
40
+ * @param {ObjectSerializerContext} context context
41
+ */
42
+ serialize(context) {
43
+ const { write } = context;
44
+ write(this.valueRange);
45
+ super.serialize(context);
46
+ }
47
+
48
+ /**
49
+ * @param {ObjectDeserializerContext} context context
50
+ */
51
+ deserialize(context) {
52
+ const { read } = context;
53
+ this.valueRange = read();
54
+ super.deserialize(context);
55
+ }
56
+ }
57
+
58
+ makeSerializable(
59
+ URLContextDependency,
60
+ "webpack/lib/dependencies/URLContextDependency"
61
+ );
62
+
63
+ URLContextDependency.Template = ContextDependencyTemplateAsRequireCall;
64
+
65
+ module.exports = URLContextDependency;