webpack 5.59.0 → 5.76.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 (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const NormalModule = require("./NormalModule");
8
9
  const createHash = require("./util/createHash");
9
10
  const memoize = require("./util/memoize");
10
11
 
@@ -46,7 +47,7 @@ const getAfter = (strFn, token) => {
46
47
  return () => {
47
48
  const str = strFn();
48
49
  const idx = str.indexOf(token);
49
- return idx < 0 ? "" : str.substr(idx);
50
+ return idx < 0 ? "" : str.slice(idx);
50
51
  };
51
52
  };
52
53
 
@@ -54,7 +55,7 @@ const getBefore = (strFn, token) => {
54
55
  return () => {
55
56
  const str = strFn();
56
57
  const idx = str.lastIndexOf(token);
57
- return idx < 0 ? "" : str.substr(0, idx);
58
+ return idx < 0 ? "" : str.slice(0, idx);
58
59
  };
59
60
  };
60
61
 
@@ -63,7 +64,7 @@ const getHash = (strFn, hashFunction) => {
63
64
  const hash = createHash(hashFunction);
64
65
  hash.update(strFn());
65
66
  const digest = /** @type {string} */ (hash.digest("hex"));
66
- return digest.substr(0, 4);
67
+ return digest.slice(0, 4);
67
68
  };
68
69
  };
69
70
 
@@ -138,7 +139,10 @@ ModuleFilenameHelpers.createFilename = (
138
139
  );
139
140
  identifier = memoize(() => requestShortener.shorten(module.identifier()));
140
141
  moduleId = () => chunkGraph.getModuleId(module);
141
- absoluteResourcePath = () => module.identifier().split("!").pop();
142
+ absoluteResourcePath = () =>
143
+ module instanceof NormalModule
144
+ ? module.resource
145
+ : module.identifier().split("!").pop();
142
146
  hash = getHash(identifier, hashFunction);
143
147
  }
144
148
  const resource = memoize(() => shortIdentifier().split("!").pop());
@@ -0,0 +1,29 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const WebpackError = require("./WebpackError");
9
+
10
+ /** @typedef {import("./Module")} Module */
11
+
12
+ class ModuleHashingError extends WebpackError {
13
+ /**
14
+ * Create a new ModuleHashingError
15
+ * @param {Module} module related module
16
+ * @param {Error} error Original error
17
+ */
18
+ constructor(module, error) {
19
+ super();
20
+
21
+ this.name = "ModuleHashingError";
22
+ this.error = error;
23
+ this.message = error.message;
24
+ this.details = error.stack;
25
+ this.module = module;
26
+ }
27
+ }
28
+
29
+ module.exports = ModuleHashingError;
@@ -27,7 +27,7 @@ const ArrayQueue = require("./util/ArrayQueue");
27
27
  /**
28
28
  * @template T
29
29
  * @callback Callback
30
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
31
31
  * @param {T=} result
32
32
  */
33
33
 
@@ -13,7 +13,7 @@ const asyncLib = require("neo-async");
13
13
  /**
14
14
  * @template T
15
15
  * @callback Callback
16
- * @param {Error=} err
16
+ * @param {(Error | null)=} err
17
17
  * @param {T=} result
18
18
  */
19
19
 
@@ -64,11 +64,21 @@ class NodeStuffPlugin {
64
64
  new NodeStuffInWebError(
65
65
  dep.loc,
66
66
  "global",
67
- "The global namespace object is Node.js feature and doesn't present in browser."
67
+ "The global namespace object is a Node.js feature and isn't available in browsers."
68
68
  )
69
69
  );
70
70
  }
71
71
  });
72
+ parser.hooks.rename.for("global").tap("NodeStuffPlugin", expr => {
73
+ const dep = new ConstDependency(
74
+ RuntimeGlobals.global,
75
+ expr.range,
76
+ [RuntimeGlobals.global]
77
+ );
78
+ dep.loc = expr.loc;
79
+ parser.state.module.addPresentationalDependency(dep);
80
+ return false;
81
+ });
72
82
  }
73
83
 
74
84
  const setModuleConstant = (expressionName, fn, warning) => {
@@ -107,7 +117,7 @@ class NodeStuffPlugin {
107
117
  setConstant(
108
118
  "__filename",
109
119
  "/index.js",
110
- "The __filename is Node.js feature and doesn't present in browser."
120
+ "__filename is a Node.js feature and isn't available in browsers."
111
121
  );
112
122
  break;
113
123
  case true:
@@ -134,7 +144,7 @@ class NodeStuffPlugin {
134
144
  setConstant(
135
145
  "__dirname",
136
146
  "/",
137
- "The __dirname is Node.js feature and doesn't present in browser."
147
+ "__dirname is a Node.js feature and isn't available in browsers."
138
148
  );
139
149
  break;
140
150
  case true:
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const parseJson = require("json-parse-better-errors");
8
+ const parseJson = require("json-parse-even-better-errors");
9
9
  const { getContext, runLoaders } = require("loader-runner");
10
10
  const querystring = require("querystring");
11
11
  const { HookMap, SyncHook, AsyncSeriesBailHook } = require("tapable");
@@ -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;
@@ -325,6 +330,8 @@ class NormalModule extends Module {
325
330
  this._isEvaluatingSideEffects = false;
326
331
  /** @type {WeakSet<ModuleGraph> | undefined} */
327
332
  this._addedSideEffectsBailout = undefined;
333
+ /** @type {Map<string, any>} */
334
+ this._codeGeneratorData = new Map();
328
335
  }
329
336
 
330
337
  /**
@@ -355,11 +362,13 @@ class NormalModule extends Module {
355
362
  * @returns {string | null} an identifier for library inclusion
356
363
  */
357
364
  libIdent(options) {
358
- return contextify(
365
+ let ident = contextify(
359
366
  options.context,
360
367
  this.userRequest,
361
368
  options.associatedObjectForCache
362
369
  );
370
+ if (this.layer) ident = `(${this.layer})/${ident}`;
371
+ return ident;
363
372
  }
364
373
 
365
374
  /**
@@ -368,7 +377,7 @@ class NormalModule extends Module {
368
377
  nameForCondition() {
369
378
  const resource = this.matchResource || this.resource;
370
379
  const idx = resource.indexOf("?");
371
- if (idx >= 0) return resource.substr(0, idx);
380
+ if (idx >= 0) return resource.slice(0, idx);
372
381
  return resource;
373
382
  }
374
383
 
@@ -538,6 +547,9 @@ class NormalModule extends Module {
538
547
  return context === this.context
539
548
  ? getContextifyInContext()(request)
540
549
  : getContextify()(context, request);
550
+ },
551
+ createHash: type => {
552
+ return createHash(type || compilation.outputOptions.hashFunction);
541
553
  }
542
554
  };
543
555
  const loaderContext = {
@@ -548,7 +560,7 @@ class NormalModule extends Module {
548
560
  let { options } = loader;
549
561
 
550
562
  if (typeof options === "string") {
551
- if (options.substr(0, 1) === "{" && options.substr(-1) === "}") {
563
+ if (options.startsWith("{") && options.endsWith("}")) {
552
564
  try {
553
565
  options = parseJson(options);
554
566
  } catch (e) {
@@ -727,7 +739,7 @@ class NormalModule extends Module {
727
739
  * @param {ResolverWithOptions} resolver the resolver
728
740
  * @param {InputFileSystem} fs the file system
729
741
  * @param {NormalModuleCompilationHooks} hooks the hooks
730
- * @param {function(WebpackError=): void} callback callback function
742
+ * @param {function((WebpackError | null)=): void} callback callback function
731
743
  * @returns {void}
732
744
  */
733
745
  _doBuild(options, compilation, resolver, fs, hooks, callback) {
@@ -793,16 +805,19 @@ class NormalModule extends Module {
793
805
  this.buildInfo.fileDependencies = new LazySet();
794
806
  this.buildInfo.contextDependencies = new LazySet();
795
807
  this.buildInfo.missingDependencies = new LazySet();
796
- if (this.loaders.length > 0) {
797
- this.buildInfo.buildDependencies = new LazySet();
798
- }
799
808
  this.buildInfo.cacheable = true;
809
+
800
810
  try {
801
811
  hooks.beforeLoaders.call(this.loaders, this, loaderContext);
802
812
  } catch (err) {
803
813
  processResult(err);
804
814
  return;
805
815
  }
816
+
817
+ if (this.loaders.length > 0) {
818
+ this.buildInfo.buildDependencies = new LazySet();
819
+ }
820
+
806
821
  runLoaders(
807
822
  {
808
823
  resource: this.resource,
@@ -1162,7 +1177,9 @@ class NormalModule extends Module {
1162
1177
  moduleGraph,
1163
1178
  chunkGraph,
1164
1179
  runtime,
1165
- concatenationScope
1180
+ concatenationScope,
1181
+ codeGenerationResults,
1182
+ sourceTypes
1166
1183
  }) {
1167
1184
  /** @type {Set<string>} */
1168
1185
  const runtimeRequirements = new Set();
@@ -1173,15 +1190,13 @@ class NormalModule extends Module {
1173
1190
  runtimeRequirements.add(RuntimeGlobals.thisAsExports);
1174
1191
  }
1175
1192
 
1176
- /** @type {Map<string, any>} */
1177
- let data;
1193
+ /** @type {function(): Map<string, any>} */
1178
1194
  const getData = () => {
1179
- if (data === undefined) data = new Map();
1180
- return data;
1195
+ return this._codeGeneratorData;
1181
1196
  };
1182
1197
 
1183
1198
  const sources = new Map();
1184
- for (const type of this.generator.getTypes(this)) {
1199
+ for (const type of sourceTypes || chunkGraph.getModuleSourceTypes(this)) {
1185
1200
  const source = this.error
1186
1201
  ? new RawSource(
1187
1202
  "throw new Error(" + JSON.stringify(this.error.message) + ");"
@@ -1194,6 +1209,7 @@ class NormalModule extends Module {
1194
1209
  runtimeRequirements,
1195
1210
  runtime,
1196
1211
  concatenationScope,
1212
+ codeGenerationResults,
1197
1213
  getData,
1198
1214
  type
1199
1215
  });
@@ -1207,7 +1223,7 @@ class NormalModule extends Module {
1207
1223
  const resultEntry = {
1208
1224
  sources,
1209
1225
  runtimeRequirements,
1210
- data
1226
+ data: this._codeGeneratorData
1211
1227
  };
1212
1228
  return resultEntry;
1213
1229
  }
@@ -1228,7 +1244,7 @@ class NormalModule extends Module {
1228
1244
 
1229
1245
  /**
1230
1246
  * @param {NeedBuildContext} context context info
1231
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1247
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1232
1248
  * @returns {void}
1233
1249
  */
1234
1250
  needBuild(context, callback) {
@@ -1355,6 +1371,7 @@ class NormalModule extends Module {
1355
1371
  write(this.error);
1356
1372
  write(this._lastSuccessfulBuildMeta);
1357
1373
  write(this._forceBuild);
1374
+ write(this._codeGeneratorData);
1358
1375
  super.serialize(context);
1359
1376
  }
1360
1377
 
@@ -1387,6 +1404,7 @@ class NormalModule extends Module {
1387
1404
  this.error = read();
1388
1405
  this._lastSuccessfulBuildMeta = read();
1389
1406
  this._forceBuild = read();
1407
+ this._codeGeneratorData = read();
1390
1408
  super.deserialize(context);
1391
1409
  }
1392
1410
  }
@@ -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) {