webpack 5.59.0 → 5.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (209) hide show
  1. package/README.md +1 -7
  2. package/hot/lazy-compilation-node.js +3 -1
  3. package/hot/poll.js +1 -1
  4. package/hot/signal.js +1 -1
  5. package/lib/APIPlugin.js +33 -0
  6. package/lib/BannerPlugin.js +10 -4
  7. package/lib/Cache.js +1 -1
  8. package/lib/CacheFacade.js +4 -11
  9. package/lib/Chunk.js +6 -3
  10. package/lib/ChunkGraph.js +1 -2
  11. package/lib/ChunkGroup.js +1 -1
  12. package/lib/CleanPlugin.js +81 -20
  13. package/lib/Compilation.js +179 -91
  14. package/lib/Compiler.js +86 -17
  15. package/lib/ConstPlugin.js +2 -2
  16. package/lib/ContextModule.js +142 -51
  17. package/lib/ContextModuleFactory.js +65 -25
  18. package/lib/DelegatedModule.js +1 -1
  19. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  20. package/lib/Dependency.js +17 -0
  21. package/lib/DependencyTemplate.js +9 -0
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllModule.js +1 -1
  24. package/lib/EntryOptionPlugin.js +2 -0
  25. package/lib/ErrorHelpers.js +2 -2
  26. package/lib/EvalDevToolModulePlugin.js +16 -1
  27. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  28. package/lib/ExportsInfo.js +4 -4
  29. package/lib/ExternalModule.js +94 -54
  30. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  31. package/lib/FileSystemInfo.js +89 -44
  32. package/lib/Generator.js +3 -0
  33. package/lib/HookWebpackError.js +1 -1
  34. package/lib/HotModuleReplacementPlugin.js +3 -1
  35. package/lib/LoaderOptionsPlugin.js +1 -1
  36. package/lib/Module.js +27 -4
  37. package/lib/ModuleFilenameHelpers.js +8 -4
  38. package/lib/ModuleHashingError.js +29 -0
  39. package/lib/MultiCompiler.js +1 -1
  40. package/lib/MultiWatching.js +1 -1
  41. package/lib/NodeStuffPlugin.js +10 -0
  42. package/lib/NormalModule.js +41 -26
  43. package/lib/NormalModuleFactory.js +42 -37
  44. package/lib/ProgressPlugin.js +4 -5
  45. package/lib/RawModule.js +1 -1
  46. package/lib/RuntimeGlobals.js +29 -1
  47. package/lib/RuntimeModule.js +1 -1
  48. package/lib/RuntimePlugin.js +77 -1
  49. package/lib/RuntimeTemplate.js +114 -2
  50. package/lib/Template.js +2 -1
  51. package/lib/TemplatedPathPlugin.js +48 -23
  52. package/lib/WatchIgnorePlugin.js +19 -7
  53. package/lib/Watching.js +33 -19
  54. package/lib/WebpackOptionsApply.js +57 -11
  55. package/lib/asset/AssetGenerator.js +193 -63
  56. package/lib/asset/AssetModulesPlugin.js +3 -0
  57. package/lib/asset/RawDataUrlModule.js +148 -0
  58. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  59. package/lib/buildChunkGraph.js +36 -6
  60. package/lib/cache/PackFileCacheStrategy.js +7 -4
  61. package/lib/cache/ResolverCachePlugin.js +90 -29
  62. package/lib/cli.js +44 -3
  63. package/lib/config/browserslistTargetHandler.js +41 -6
  64. package/lib/config/defaults.js +115 -19
  65. package/lib/config/normalization.js +9 -0
  66. package/lib/config/target.js +10 -0
  67. package/lib/container/ContainerEntryModule.js +8 -5
  68. package/lib/container/FallbackModule.js +4 -4
  69. package/lib/container/RemoteModule.js +4 -2
  70. package/lib/css/CssExportsGenerator.js +139 -0
  71. package/lib/css/CssGenerator.js +109 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  73. package/lib/css/CssModulesPlugin.js +462 -0
  74. package/lib/css/CssParser.js +618 -0
  75. package/lib/css/walkCssTokens.js +659 -0
  76. package/lib/debug/ProfilingPlugin.js +24 -21
  77. package/lib/dependencies/AMDRequireDependency.js +6 -6
  78. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  79. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  80. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
  81. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  82. package/lib/dependencies/ContextDependency.js +1 -0
  83. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  84. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  85. package/lib/dependencies/ContextElementDependency.js +41 -3
  86. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  87. package/lib/dependencies/CssExportDependency.js +85 -0
  88. package/lib/dependencies/CssImportDependency.js +75 -0
  89. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  90. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  91. package/lib/dependencies/CssUrlDependency.js +132 -0
  92. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  93. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  94. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  95. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  96. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  97. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  98. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  99. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  100. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  102. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  103. package/lib/dependencies/ImportContextDependency.js +0 -2
  104. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  105. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  106. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  107. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  108. package/lib/dependencies/LoaderPlugin.js +4 -2
  109. package/lib/dependencies/RequireContextDependency.js +0 -16
  110. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  111. package/lib/dependencies/URLDependency.js +3 -8
  112. package/lib/dependencies/URLPlugin.js +1 -1
  113. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  114. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  115. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  116. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  117. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  118. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  119. package/lib/hmr/lazyCompilationBackend.js +51 -12
  120. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  121. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  122. package/lib/ids/IdHelpers.js +25 -11
  123. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  124. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  125. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  126. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  127. package/lib/index.js +13 -0
  128. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  129. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  130. package/lib/javascript/ChunkHelpers.js +33 -0
  131. package/lib/javascript/JavascriptGenerator.js +1 -0
  132. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  133. package/lib/javascript/JavascriptParser.js +82 -48
  134. package/lib/javascript/StartupHelpers.js +7 -30
  135. package/lib/library/AssignLibraryPlugin.js +39 -15
  136. package/lib/library/EnableLibraryPlugin.js +11 -0
  137. package/lib/library/UmdLibraryPlugin.js +5 -3
  138. package/lib/node/NodeTargetPlugin.js +3 -0
  139. package/lib/node/NodeWatchFileSystem.js +85 -31
  140. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  141. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  142. package/lib/optimize/ConcatenatedModule.js +21 -9
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  144. package/lib/optimize/SplitChunksPlugin.js +8 -1
  145. package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
  146. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  147. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  148. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  149. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  150. package/lib/schemes/HttpUriPlugin.js +77 -14
  151. package/lib/serialization/FileMiddleware.js +44 -9
  152. package/lib/sharing/ConsumeSharedModule.js +8 -2
  153. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  154. package/lib/sharing/ProvideSharedModule.js +4 -2
  155. package/lib/sharing/ShareRuntimeModule.js +1 -1
  156. package/lib/sharing/utils.js +1 -1
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  158. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  159. package/lib/util/ArrayHelpers.js +30 -0
  160. package/lib/util/AsyncQueue.js +1 -1
  161. package/lib/util/compileBooleanMatcher.js +1 -1
  162. package/lib/util/create-schema-validation.js +9 -2
  163. package/lib/util/createHash.js +12 -0
  164. package/lib/util/deprecation.js +10 -2
  165. package/lib/util/deterministicGrouping.js +1 -1
  166. package/lib/util/extractUrlAndGlobal.js +3 -0
  167. package/lib/util/fs.js +11 -0
  168. package/lib/util/hash/BatchedHash.js +7 -4
  169. package/lib/util/hash/md4.js +20 -0
  170. package/lib/util/hash/wasm-hash.js +163 -0
  171. package/lib/util/hash/xxhash64.js +5 -139
  172. package/lib/util/identifier.js +65 -44
  173. package/lib/util/internalSerializables.js +15 -0
  174. package/lib/util/nonNumericOnlyHash.js +22 -0
  175. package/lib/util/semver.js +17 -10
  176. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  177. package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
  178. package/lib/webpack.js +10 -3
  179. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  180. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  181. package/module.d.ts +215 -0
  182. package/package.json +23 -28
  183. package/schemas/WebpackOptions.check.js +1 -1
  184. package/schemas/WebpackOptions.json +254 -29
  185. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  186. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  187. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  188. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  189. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  190. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  191. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  192. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  194. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  195. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  197. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  198. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  199. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  200. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  201. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  202. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  203. package/schemas/plugins/css/CssParserOptions.json +3 -0
  204. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  209. package/types.d.ts +628 -179
@@ -50,6 +50,7 @@ const memoize = require("./util/memoize");
50
50
  /** @typedef {import("webpack-sources").Source} Source */
51
51
  /** @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext} NormalModuleLoaderContext */
52
52
  /** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
53
+ /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
53
54
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
54
55
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
55
56
  /** @typedef {import("./Compiler")} Compiler */
@@ -194,6 +195,25 @@ makeSerializable(
194
195
  * @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
195
196
  */
196
197
 
198
+ /**
199
+ * @typedef {Object} NormalModuleCreateData
200
+ * @property {string=} layer an optional layer in which the module is
201
+ * @property {string} type module type
202
+ * @property {string} request request string
203
+ * @property {string} userRequest request intended by user (without loaders from config)
204
+ * @property {string} rawRequest request without resolving
205
+ * @property {LoaderItem[]} loaders list of loaders
206
+ * @property {string} resource path + query of the real resource
207
+ * @property {Record<string, any>=} resourceResolveData resource resolve data
208
+ * @property {string} context context directory for resolving
209
+ * @property {string=} matchResource path + query of the matched resource (virtual)
210
+ * @property {Parser} parser the parser used
211
+ * @property {Record<string, any>=} parserOptions the options of the parser used
212
+ * @property {Generator} generator the generator used
213
+ * @property {Record<string, any>=} generatorOptions the options of the generator used
214
+ * @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
215
+ */
216
+
197
217
  /** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
198
218
  const compilationHooksMap = new WeakMap();
199
219
 
@@ -246,22 +266,7 @@ class NormalModule extends Module {
246
266
  }
247
267
 
248
268
  /**
249
- * @param {Object} options options object
250
- * @param {string=} options.layer an optional layer in which the module is
251
- * @param {string} options.type module type
252
- * @param {string} options.request request string
253
- * @param {string} options.userRequest request intended by user (without loaders from config)
254
- * @param {string} options.rawRequest request without resolving
255
- * @param {LoaderItem[]} options.loaders list of loaders
256
- * @param {string} options.resource path + query of the real resource
257
- * @param {Record<string, any>=} options.resourceResolveData resource resolve data
258
- * @param {string} options.context context directory for resolving
259
- * @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
260
- * @param {Parser} options.parser the parser used
261
- * @param {object} options.parserOptions the options of the parser used
262
- * @param {Generator} options.generator the generator used
263
- * @param {object} options.generatorOptions the options of the generator used
264
- * @param {Object} options.resolveOptions options used for resolving requests from this module
269
+ * @param {NormalModuleCreateData} options options object
265
270
  */
266
271
  constructor({
267
272
  layer,
@@ -310,7 +315,7 @@ class NormalModule extends Module {
310
315
  }
311
316
 
312
317
  // Info from Build
313
- /** @type {WebpackError=} */
318
+ /** @type {(WebpackError | null)=} */
314
319
  this.error = null;
315
320
  /** @private @type {Source=} */
316
321
  this._source = null;
@@ -355,11 +360,13 @@ class NormalModule extends Module {
355
360
  * @returns {string | null} an identifier for library inclusion
356
361
  */
357
362
  libIdent(options) {
358
- return contextify(
363
+ let ident = contextify(
359
364
  options.context,
360
365
  this.userRequest,
361
366
  options.associatedObjectForCache
362
367
  );
368
+ if (this.layer) ident = `(${this.layer})/${ident}`;
369
+ return ident;
363
370
  }
364
371
 
365
372
  /**
@@ -368,7 +375,7 @@ class NormalModule extends Module {
368
375
  nameForCondition() {
369
376
  const resource = this.matchResource || this.resource;
370
377
  const idx = resource.indexOf("?");
371
- if (idx >= 0) return resource.substr(0, idx);
378
+ if (idx >= 0) return resource.slice(0, idx);
372
379
  return resource;
373
380
  }
374
381
 
@@ -538,6 +545,9 @@ class NormalModule extends Module {
538
545
  return context === this.context
539
546
  ? getContextifyInContext()(request)
540
547
  : getContextify()(context, request);
548
+ },
549
+ createHash: type => {
550
+ return createHash(type || compilation.outputOptions.hashFunction);
541
551
  }
542
552
  };
543
553
  const loaderContext = {
@@ -548,7 +558,7 @@ class NormalModule extends Module {
548
558
  let { options } = loader;
549
559
 
550
560
  if (typeof options === "string") {
551
- if (options.substr(0, 1) === "{" && options.substr(-1) === "}") {
561
+ if (options.startsWith("{") && options.endsWith("}")) {
552
562
  try {
553
563
  options = parseJson(options);
554
564
  } catch (e) {
@@ -727,7 +737,7 @@ class NormalModule extends Module {
727
737
  * @param {ResolverWithOptions} resolver the resolver
728
738
  * @param {InputFileSystem} fs the file system
729
739
  * @param {NormalModuleCompilationHooks} hooks the hooks
730
- * @param {function(WebpackError=): void} callback callback function
740
+ * @param {function((WebpackError | null)=): void} callback callback function
731
741
  * @returns {void}
732
742
  */
733
743
  _doBuild(options, compilation, resolver, fs, hooks, callback) {
@@ -793,16 +803,19 @@ class NormalModule extends Module {
793
803
  this.buildInfo.fileDependencies = new LazySet();
794
804
  this.buildInfo.contextDependencies = new LazySet();
795
805
  this.buildInfo.missingDependencies = new LazySet();
796
- if (this.loaders.length > 0) {
797
- this.buildInfo.buildDependencies = new LazySet();
798
- }
799
806
  this.buildInfo.cacheable = true;
807
+
800
808
  try {
801
809
  hooks.beforeLoaders.call(this.loaders, this, loaderContext);
802
810
  } catch (err) {
803
811
  processResult(err);
804
812
  return;
805
813
  }
814
+
815
+ if (this.loaders.length > 0) {
816
+ this.buildInfo.buildDependencies = new LazySet();
817
+ }
818
+
806
819
  runLoaders(
807
820
  {
808
821
  resource: this.resource,
@@ -1162,7 +1175,8 @@ class NormalModule extends Module {
1162
1175
  moduleGraph,
1163
1176
  chunkGraph,
1164
1177
  runtime,
1165
- concatenationScope
1178
+ concatenationScope,
1179
+ codeGenerationResults
1166
1180
  }) {
1167
1181
  /** @type {Set<string>} */
1168
1182
  const runtimeRequirements = new Set();
@@ -1194,6 +1208,7 @@ class NormalModule extends Module {
1194
1208
  runtimeRequirements,
1195
1209
  runtime,
1196
1210
  concatenationScope,
1211
+ codeGenerationResults,
1197
1212
  getData,
1198
1213
  type
1199
1214
  });
@@ -1228,7 +1243,7 @@ class NormalModule extends Module {
1228
1243
 
1229
1244
  /**
1230
1245
  * @param {NeedBuildContext} context context info
1231
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1246
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1232
1247
  * @returns {void}
1233
1248
  */
1234
1249
  needBuild(context, callback) {
@@ -28,17 +28,25 @@ const LazySet = require("./util/LazySet");
28
28
  const { getScheme } = require("./util/URLAbsoluteSpecifier");
29
29
  const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge");
30
30
  const { join } = require("./util/fs");
31
- const { parseResource } = require("./util/identifier");
31
+ const {
32
+ parseResource,
33
+ parseResourceWithoutFragment
34
+ } = require("./util/identifier");
32
35
 
33
36
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
37
+ /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
34
38
  /** @typedef {import("./Generator")} Generator */
35
39
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
36
40
  /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
41
+ /** @typedef {import("./NormalModule").NormalModuleCreateData} NormalModuleCreateData */
37
42
  /** @typedef {import("./Parser")} Parser */
38
43
  /** @typedef {import("./ResolverFactory")} ResolverFactory */
39
44
  /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
40
45
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
41
46
 
47
+ /** @typedef {Pick<RuleSetRule, 'type'|'sideEffects'|'parser'|'generator'|'resolve'|'layer'>} ModuleSettings */
48
+ /** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
49
+
42
50
  /**
43
51
  * @typedef {Object} ResolveData
44
52
  * @property {ModuleFactoryCreateData["contextInfo"]} contextInfo
@@ -48,7 +56,7 @@ const { parseResource } = require("./util/identifier");
48
56
  * @property {Record<string, any> | undefined} assertions
49
57
  * @property {ModuleDependency[]} dependencies
50
58
  * @property {string} dependencyType
51
- * @property {Object} createData
59
+ * @property {CreateData} createData
52
60
  * @property {LazySet<string>} fileDependencies
53
61
  * @property {LazySet<string>} missingDependencies
54
62
  * @property {LazySet<string>} contextDependencies
@@ -66,6 +74,11 @@ const { parseResource } = require("./util/identifier");
66
74
 
67
75
  /** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
68
76
 
77
+ /** @typedef {Object} ParsedLoaderRequest
78
+ * @property {string} loader loader
79
+ * @property {string|undefined} options options
80
+ */
81
+
69
82
  const EMPTY_RESOLVE_OPTIONS = {};
70
83
  const EMPTY_PARSER_OPTIONS = {};
71
84
  const EMPTY_GENERATOR_OPTIONS = {};
@@ -97,27 +110,6 @@ const stringifyLoadersAndResource = (loaders, resource) => {
97
110
  return str + resource;
98
111
  };
99
112
 
100
- /**
101
- * @param {string} resultString resultString
102
- * @returns {{loader: string, options: string|undefined}} parsed loader request
103
- */
104
- const identToLoaderRequest = resultString => {
105
- const idx = resultString.indexOf("?");
106
- if (idx >= 0) {
107
- const loader = resultString.substr(0, idx);
108
- const options = resultString.substr(idx + 1);
109
- return {
110
- loader,
111
- options
112
- };
113
- } else {
114
- return {
115
- loader: resultString,
116
- options: undefined
117
- };
118
- }
119
- };
120
-
121
113
  const needCalls = (times, callback) => {
122
114
  return err => {
123
115
  if (--times === 0) {
@@ -212,7 +204,7 @@ class NormalModuleFactory extends ModuleFactory {
212
204
  }) {
213
205
  super();
214
206
  this.hooks = Object.freeze({
215
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
207
+ /** @type {AsyncSeriesBailHook<[ResolveData], Module | false | void>} */
216
208
  resolve: new AsyncSeriesBailHook(["resolveData"]),
217
209
  /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
218
210
  resolveForScheme: new HookMap(
@@ -222,15 +214,15 @@ class NormalModuleFactory extends ModuleFactory {
222
214
  resolveInScheme: new HookMap(
223
215
  () => new AsyncSeriesBailHook(["resourceData", "resolveData"])
224
216
  ),
225
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
217
+ /** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
226
218
  factorize: new AsyncSeriesBailHook(["resolveData"]),
227
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
219
+ /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
228
220
  beforeResolve: new AsyncSeriesBailHook(["resolveData"]),
229
- /** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
221
+ /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
230
222
  afterResolve: new AsyncSeriesBailHook(["resolveData"]),
231
- /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], TODO>} */
223
+ /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
232
224
  createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
233
- /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], TODO>} */
225
+ /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
234
226
  module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
235
227
  createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
236
228
  parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
@@ -264,6 +256,9 @@ class NormalModuleFactory extends ModuleFactory {
264
256
  const cacheParseResource = parseResource.bindCache(
265
257
  associatedObjectForCache
266
258
  );
259
+ const cachedParseResourceWithoutFragment =
260
+ parseResourceWithoutFragment.bindCache(associatedObjectForCache);
261
+ this._parseResourceWithoutFragment = cachedParseResourceWithoutFragment;
267
262
 
268
263
  this.hooks.factorize.tapAsync(
269
264
  {
@@ -311,7 +306,9 @@ class NormalModuleFactory extends ModuleFactory {
311
306
  return callback(new Error("Empty dependency (no request)"));
312
307
  }
313
308
 
314
- createdModule = new NormalModule(createData);
309
+ createdModule = new NormalModule(
310
+ /** @type {NormalModuleCreateData} */ (createData)
311
+ );
315
312
  }
316
313
 
317
314
  createdModule = this.hooks.module.call(
@@ -351,7 +348,7 @@ class NormalModuleFactory extends ModuleFactory {
351
348
  let matchResourceData = undefined;
352
349
  /** @type {string} */
353
350
  let unresolvedResource;
354
- /** @type {{loader: string, options: string|undefined}[]} */
351
+ /** @type {ParsedLoaderRequest[]} */
355
352
  let elements;
356
353
  let noPreAutoLoaders = false;
357
354
  let noAutoLoaders = false;
@@ -382,7 +379,7 @@ class NormalModuleFactory extends ModuleFactory {
382
379
  resource: matchResource,
383
380
  ...cacheParseResource(matchResource)
384
381
  };
385
- requestWithoutMatchResource = request.substr(
382
+ requestWithoutMatchResource = request.slice(
386
383
  matchResourceMatch[0].length
387
384
  );
388
385
  }
@@ -405,7 +402,13 @@ class NormalModuleFactory extends ModuleFactory {
405
402
  )
406
403
  .split(/!+/);
407
404
  unresolvedResource = rawElements.pop();
408
- elements = rawElements.map(identToLoaderRequest);
405
+ elements = rawElements.map(el => {
406
+ const { path, query } = cachedParseResourceWithoutFragment(el);
407
+ return {
408
+ loader: path,
409
+ options: query ? query.slice(1) : undefined
410
+ };
411
+ });
409
412
  scheme = getScheme(unresolvedResource);
410
413
  } else {
411
414
  unresolvedResource = requestWithoutMatchResource;
@@ -434,7 +437,7 @@ class NormalModuleFactory extends ModuleFactory {
434
437
  try {
435
438
  for (const item of loaders) {
436
439
  if (typeof item.options === "string" && item.options[0] === "?") {
437
- const ident = item.options.substr(1);
440
+ const ident = item.options.slice(1);
438
441
  if (ident === "[[missing ident]]") {
439
442
  throw new Error(
440
443
  "No ident is provided by referenced loader. " +
@@ -1017,12 +1020,14 @@ If changing the source code is not an option there is also a resolve options cal
1017
1020
  }
1018
1021
  if (err) return callback(err);
1019
1022
 
1020
- const parsedResult = identToLoaderRequest(result);
1023
+ const parsedResult = this._parseResourceWithoutFragment(result);
1021
1024
  const resolved = {
1022
- loader: parsedResult.loader,
1025
+ loader: parsedResult.path,
1023
1026
  options:
1024
1027
  item.options === undefined
1025
- ? parsedResult.options
1028
+ ? parsedResult.query
1029
+ ? parsedResult.query.slice(1)
1030
+ : undefined
1026
1031
  : item.options,
1027
1032
  ident: item.options === undefined ? undefined : item.ident
1028
1033
  };
@@ -96,7 +96,7 @@ const createDefaultHandler = (profile, logger) => {
96
96
  /**
97
97
  * @callback ReportProgress
98
98
  * @param {number} p
99
- * @param {...string[]} [args]
99
+ * @param {...string} [args]
100
100
  * @returns {void}
101
101
  */
102
102
 
@@ -531,15 +531,14 @@ class ProgressPlugin {
531
531
  }
532
532
  });
533
533
  interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
534
- compiler.hooks.initialize.intercept({
534
+ compiler.hooks.beforeRun.intercept({
535
535
  name: "ProgressPlugin",
536
536
  call() {
537
537
  handler(0, "");
538
538
  }
539
539
  });
540
- interceptHook(compiler.hooks.initialize, 0.01, "setup", "initialize");
541
- interceptHook(compiler.hooks.beforeRun, 0.02, "setup", "before run");
542
- interceptHook(compiler.hooks.run, 0.03, "setup", "run");
540
+ interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
541
+ interceptHook(compiler.hooks.run, 0.02, "setup", "run");
543
542
  interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
544
543
  interceptHook(
545
544
  compiler.hooks.normalModuleFactory,
package/lib/RawModule.js CHANGED
@@ -74,7 +74,7 @@ class RawModule extends Module {
74
74
 
75
75
  /**
76
76
  * @param {NeedBuildContext} context context info
77
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
77
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
78
78
  * @returns {void}
79
79
  */
80
80
  needBuild(context, callback) {
@@ -164,10 +164,17 @@ exports.scriptNonce = "__webpack_require__.nc";
164
164
  * function to load a script tag.
165
165
  * Arguments: (url: string, done: (event) => void), key?: string | number, chunkId?: string | number) => void
166
166
  * done function is called when loading has finished or timeout occurred.
167
- * It will attach to existing script tags with data-webpack == key or src == url.
167
+ * It will attach to existing script tags with data-webpack == uniqueName + ":" + key or src == url.
168
168
  */
169
169
  exports.loadScript = "__webpack_require__.l";
170
170
 
171
+ /**
172
+ * function to promote a string to a TrustedScript using webpack's Trusted
173
+ * Types policy
174
+ * Arguments: (script: string) => TrustedScript
175
+ */
176
+ exports.createScript = "__webpack_require__.ts";
177
+
171
178
  /**
172
179
  * function to promote a string to a TrustedScriptURL using webpack's Trusted
173
180
  * Types policy
@@ -175,6 +182,12 @@ exports.loadScript = "__webpack_require__.l";
175
182
  */
176
183
  exports.createScriptUrl = "__webpack_require__.tu";
177
184
 
185
+ /**
186
+ * function to return webpack's Trusted Types policy
187
+ * Arguments: () => TrustedTypePolicy
188
+ */
189
+ exports.getTrustedTypesPolicy = "__webpack_require__.tt";
190
+
178
191
  /**
179
192
  * the chunk name of the chunk with the runtime
180
193
  */
@@ -190,11 +203,26 @@ exports.runtimeId = "__webpack_require__.j";
190
203
  */
191
204
  exports.getChunkScriptFilename = "__webpack_require__.u";
192
205
 
206
+ /**
207
+ * the filename of the css part of the chunk
208
+ */
209
+ exports.getChunkCssFilename = "__webpack_require__.k";
210
+
211
+ /**
212
+ * a flag when a module/chunk/tree has css modules
213
+ */
214
+ exports.hasCssModules = "has css modules";
215
+
193
216
  /**
194
217
  * the filename of the script part of the hot update chunk
195
218
  */
196
219
  exports.getChunkUpdateScriptFilename = "__webpack_require__.hu";
197
220
 
221
+ /**
222
+ * the filename of the css part of the hot update chunk
223
+ */
224
+ exports.getChunkUpdateCssFilename = "__webpack_require__.hk";
225
+
198
226
  /**
199
227
  * startup signal from runtime
200
228
  * This will be called when the runtime chunk has been loaded.
@@ -78,7 +78,7 @@ class RuntimeModule extends Module {
78
78
 
79
79
  /**
80
80
  * @param {NeedBuildContext} context context info
81
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
81
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
82
82
  * @returns {void}
83
83
  */
84
84
  needBuild(context, callback) {
@@ -6,18 +6,22 @@
6
6
  "use strict";
7
7
 
8
8
  const RuntimeGlobals = require("./RuntimeGlobals");
9
+ const { getChunkFilenameTemplate } = require("./css/CssModulesPlugin");
9
10
  const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency");
10
11
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
11
12
  const AsyncModuleRuntimeModule = require("./runtime/AsyncModuleRuntimeModule");
12
13
  const AutoPublicPathRuntimeModule = require("./runtime/AutoPublicPathRuntimeModule");
14
+ const BaseUriRuntimeModule = require("./runtime/BaseUriRuntimeModule");
13
15
  const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
14
16
  const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
15
17
  const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
18
+ const CreateScriptRuntimeModule = require("./runtime/CreateScriptRuntimeModule");
16
19
  const CreateScriptUrlRuntimeModule = require("./runtime/CreateScriptUrlRuntimeModule");
17
20
  const DefinePropertyGettersRuntimeModule = require("./runtime/DefinePropertyGettersRuntimeModule");
18
21
  const EnsureChunkRuntimeModule = require("./runtime/EnsureChunkRuntimeModule");
19
22
  const GetChunkFilenameRuntimeModule = require("./runtime/GetChunkFilenameRuntimeModule");
20
23
  const GetMainFilenameRuntimeModule = require("./runtime/GetMainFilenameRuntimeModule");
24
+ const GetTrustedTypesPolicyRuntimeModule = require("./runtime/GetTrustedTypesPolicyRuntimeModule");
21
25
  const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule");
22
26
  const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModule");
23
27
  const LoadScriptRuntimeModule = require("./runtime/LoadScriptRuntimeModule");
@@ -39,7 +43,9 @@ const GLOBALS_ON_REQUIRE = [
39
43
  RuntimeGlobals.runtimeId,
40
44
  RuntimeGlobals.compatGetDefaultExport,
41
45
  RuntimeGlobals.createFakeNamespaceObject,
46
+ RuntimeGlobals.createScript,
42
47
  RuntimeGlobals.createScriptUrl,
48
+ RuntimeGlobals.getTrustedTypesPolicy,
43
49
  RuntimeGlobals.definePropertyGetters,
44
50
  RuntimeGlobals.ensureChunk,
45
51
  RuntimeGlobals.entryModuleId,
@@ -91,6 +97,15 @@ class RuntimePlugin {
91
97
  */
92
98
  apply(compiler) {
93
99
  compiler.hooks.compilation.tap("RuntimePlugin", compilation => {
100
+ const globalChunkLoading = compilation.outputOptions.chunkLoading;
101
+ const isChunkLoadingDisabledForChunk = chunk => {
102
+ const options = chunk.getEntryOptions();
103
+ const chunkLoading =
104
+ options && options.chunkLoading !== undefined
105
+ ? options.chunkLoading
106
+ : globalChunkLoading;
107
+ return chunkLoading === false;
108
+ };
94
109
  compilation.dependencyTemplates.set(
95
110
  RuntimeRequirementsDependency,
96
111
  new RuntimeRequirementsDependency.Template()
@@ -218,7 +233,15 @@ class RuntimePlugin {
218
233
  compilation.hooks.runtimeRequirementInTree
219
234
  .for(RuntimeGlobals.systemContext)
220
235
  .tap("RuntimePlugin", chunk => {
221
- if (compilation.outputOptions.library.type === "system") {
236
+ const { outputOptions } = compilation;
237
+ const { library: globalLibrary } = outputOptions;
238
+ const entryOptions = chunk.getEntryOptions();
239
+ const libraryType =
240
+ entryOptions && entryOptions.library !== undefined
241
+ ? entryOptions.library.type
242
+ : globalLibrary.type;
243
+
244
+ if (libraryType === "system") {
222
245
  compilation.addRuntimeModule(
223
246
  chunk,
224
247
  new SystemContextRuntimeModule()
@@ -253,6 +276,30 @@ class RuntimePlugin {
253
276
  );
254
277
  return true;
255
278
  });
279
+ compilation.hooks.runtimeRequirementInTree
280
+ .for(RuntimeGlobals.getChunkCssFilename)
281
+ .tap("RuntimePlugin", (chunk, set) => {
282
+ if (
283
+ typeof compilation.outputOptions.cssChunkFilename === "string" &&
284
+ /\[(full)?hash(:\d+)?\]/.test(
285
+ compilation.outputOptions.cssChunkFilename
286
+ )
287
+ ) {
288
+ set.add(RuntimeGlobals.getFullHash);
289
+ }
290
+ compilation.addRuntimeModule(
291
+ chunk,
292
+ new GetChunkFilenameRuntimeModule(
293
+ "css",
294
+ "css",
295
+ RuntimeGlobals.getChunkCssFilename,
296
+ chunk =>
297
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
298
+ set.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
299
+ )
300
+ );
301
+ return true;
302
+ });
256
303
  compilation.hooks.runtimeRequirementInTree
257
304
  .for(RuntimeGlobals.getChunkUpdateScriptFilename)
258
305
  .tap("RuntimePlugin", (chunk, set) => {
@@ -331,15 +378,36 @@ class RuntimePlugin {
331
378
  );
332
379
  return true;
333
380
  });
381
+ compilation.hooks.runtimeRequirementInTree
382
+ .for(RuntimeGlobals.createScript)
383
+ .tap("RuntimePlugin", (chunk, set) => {
384
+ if (compilation.outputOptions.trustedTypes) {
385
+ set.add(RuntimeGlobals.getTrustedTypesPolicy);
386
+ }
387
+ compilation.addRuntimeModule(chunk, new CreateScriptRuntimeModule());
388
+ return true;
389
+ });
334
390
  compilation.hooks.runtimeRequirementInTree
335
391
  .for(RuntimeGlobals.createScriptUrl)
336
392
  .tap("RuntimePlugin", (chunk, set) => {
393
+ if (compilation.outputOptions.trustedTypes) {
394
+ set.add(RuntimeGlobals.getTrustedTypesPolicy);
395
+ }
337
396
  compilation.addRuntimeModule(
338
397
  chunk,
339
398
  new CreateScriptUrlRuntimeModule()
340
399
  );
341
400
  return true;
342
401
  });
402
+ compilation.hooks.runtimeRequirementInTree
403
+ .for(RuntimeGlobals.getTrustedTypesPolicy)
404
+ .tap("RuntimePlugin", (chunk, set) => {
405
+ compilation.addRuntimeModule(
406
+ chunk,
407
+ new GetTrustedTypesPolicyRuntimeModule(set)
408
+ );
409
+ return true;
410
+ });
343
411
  compilation.hooks.runtimeRequirementInTree
344
412
  .for(RuntimeGlobals.relativeUrl)
345
413
  .tap("RuntimePlugin", (chunk, set) => {
@@ -355,6 +423,14 @@ class RuntimePlugin {
355
423
  );
356
424
  return true;
357
425
  });
426
+ compilation.hooks.runtimeRequirementInTree
427
+ .for(RuntimeGlobals.baseURI)
428
+ .tap("RuntimePlugin", chunk => {
429
+ if (isChunkLoadingDisabledForChunk(chunk)) {
430
+ compilation.addRuntimeModule(chunk, new BaseUriRuntimeModule());
431
+ return true;
432
+ }
433
+ });
358
434
  // TODO webpack 6: remove CompatRuntimeModule
359
435
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
360
436
  "RuntimePlugin",