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
@@ -17,7 +17,7 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
17
17
  /** @typedef {import("../Parser").ParserState} ParserState */
18
18
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
19
19
 
20
- const JS_COMPAT_TYPES = new Set(["i32", "f32", "f64"]);
20
+ const JS_COMPAT_TYPES = new Set(["i32", "i64", "f32", "f64"]);
21
21
 
22
22
  /**
23
23
  * @param {t.Signature} signature the func signature
@@ -51,6 +51,20 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
51
51
  this._runtimeRequirements = runtimeRequirements;
52
52
  }
53
53
 
54
+ /**
55
+ * @private
56
+ * @param {Chunk} chunk chunk
57
+ * @returns {string} generated code
58
+ */
59
+ _generateBaseUri(chunk) {
60
+ const options = chunk.getEntryOptions();
61
+ if (options && options.baseUri) {
62
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
63
+ } else {
64
+ return `${RuntimeGlobals.baseURI} = document.baseURI || self.location.href;`;
65
+ }
66
+ }
67
+
54
68
  /**
55
69
  * @returns {string} runtime code
56
70
  */
@@ -59,13 +73,13 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
59
73
  const {
60
74
  runtimeTemplate,
61
75
  outputOptions: {
62
- globalObject,
63
76
  chunkLoadingGlobal,
64
77
  hotUpdateGlobal,
65
78
  crossOriginLoading,
66
79
  scriptType
67
80
  }
68
81
  } = compilation;
82
+ const globalObject = runtimeTemplate.globalObject;
69
83
  const { linkPreload, linkPrefetch } =
70
84
  JsonpChunkLoadingRuntimeModule.getCompilationHooks(compilation);
71
85
  const fn = RuntimeGlobals.ensureChunkHandlers;
@@ -96,18 +110,14 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
96
110
  )}]`;
97
111
  const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
98
112
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
99
- const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
113
+ const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
100
114
 
101
115
  const stateExpression = withHmr
102
116
  ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_jsonp`
103
117
  : undefined;
104
118
 
105
119
  return Template.asString([
106
- withBaseURI
107
- ? Template.asString([
108
- `${RuntimeGlobals.baseURI} = document.baseURI || self.location.href;`
109
- ])
110
- : "// no baseURI",
120
+ withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
111
121
  "",
112
122
  "// object to store loaded and loading chunks",
113
123
  "// undefined = chunk not loaded, null = chunk preloaded/prefetched",
@@ -253,15 +263,17 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
253
263
  'link.as = "script";',
254
264
  `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
255
265
  crossOriginLoading
256
- ? Template.asString([
257
- "if (link.href.indexOf(window.location.origin + '/') !== 0) {",
258
- Template.indent(
259
- `link.crossOrigin = ${JSON.stringify(
260
- crossOriginLoading
261
- )};`
262
- ),
263
- "}"
264
- ])
266
+ ? crossOriginLoading === "use-credentials"
267
+ ? 'link.crossOrigin = "use-credentials";'
268
+ : Template.asString([
269
+ "if (link.href.indexOf(window.location.origin + '/') !== 0) {",
270
+ Template.indent(
271
+ `link.crossOrigin = ${JSON.stringify(
272
+ crossOriginLoading
273
+ )};`
274
+ ),
275
+ "}"
276
+ ])
265
277
  : ""
266
278
  ]),
267
279
  chunk
@@ -276,8 +288,9 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
276
288
  ? Template.asString([
277
289
  "var currentUpdatedModulesList;",
278
290
  "var waitingUpdateResolves = {};",
279
- "function loadUpdateChunk(chunkId) {",
291
+ "function loadUpdateChunk(chunkId, updatedModulesList) {",
280
292
  Template.indent([
293
+ "currentUpdatedModulesList = updatedModulesList;",
281
294
  `return new Promise(${runtimeTemplate.basicFunction(
282
295
  "resolve, reject",
283
296
  [
@@ -419,7 +432,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
419
432
  `if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) && installedChunks[chunkId]) {`,
420
433
  Template.indent("installedChunks[chunkId][0]();"),
421
434
  "}",
422
- "installedChunks[chunkIds[i]] = 0;"
435
+ "installedChunks[chunkId] = 0;"
423
436
  ]),
424
437
  "}",
425
438
  withOnChunkLoad
package/lib/webpack.js CHANGED
@@ -61,8 +61,7 @@ const createMultiCompiler = (childOptions, options) => {
61
61
  const createCompiler = rawOptions => {
62
62
  const options = getNormalizedWebpackOptions(rawOptions);
63
63
  applyWebpackOptionsBaseDefaults(options);
64
- const compiler = new Compiler(options.context);
65
- compiler.options = options;
64
+ const compiler = new Compiler(options.context, options);
66
65
  new NodeEnvironmentPlugin({
67
66
  infrastructureLogging: options.infrastructureLogging
68
67
  }).apply(compiler);
@@ -97,6 +96,9 @@ const createCompiler = rawOptions => {
97
96
  * @returns {MultiCompiler} the multi compiler object
98
97
  */
99
98
 
99
+ const asArray = options =>
100
+ Array.isArray(options) ? Array.from(options) : [options];
101
+
100
102
  const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
101
103
  /**
102
104
  * @param {WebpackOptions | (ReadonlyArray<WebpackOptions> & MultiCompilerOptions)} options options
@@ -105,8 +107,13 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
105
107
  */
106
108
  (options, callback) => {
107
109
  const create = () => {
108
- if (!webpackOptionsSchemaCheck(options)) {
110
+ if (!asArray(options).every(webpackOptionsSchemaCheck)) {
109
111
  getValidateSchema()(webpackOptionsSchema, options);
112
+ util.deprecate(
113
+ () => {},
114
+ "webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
115
+ "DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
116
+ )();
110
117
  }
111
118
  /** @type {MultiCompiler|Compiler} */
112
119
  let compiler;
@@ -6,7 +6,6 @@
6
6
  "use strict";
7
7
 
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
- const CreateScriptUrlRuntimeModule = require("../runtime/CreateScriptUrlRuntimeModule");
10
9
  const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
11
10
  const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
12
11
 
@@ -43,7 +42,9 @@ class ImportScriptsChunkLoadingPlugin {
43
42
  const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
44
43
  set.add(RuntimeGlobals.moduleFactoriesAddOnly);
45
44
  set.add(RuntimeGlobals.hasOwnProperty);
46
- if (withCreateScriptUrl) set.add(RuntimeGlobals.createScriptUrl);
45
+ if (withCreateScriptUrl) {
46
+ set.add(RuntimeGlobals.createScriptUrl);
47
+ }
47
48
  compilation.addRuntimeModule(
48
49
  chunk,
49
50
  new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl)
@@ -61,15 +62,6 @@ class ImportScriptsChunkLoadingPlugin {
61
62
  compilation.hooks.runtimeRequirementInTree
62
63
  .for(RuntimeGlobals.baseURI)
63
64
  .tap("ImportScriptsChunkLoadingPlugin", handler);
64
- compilation.hooks.runtimeRequirementInTree
65
- .for(RuntimeGlobals.createScriptUrl)
66
- .tap("RuntimePlugin", (chunk, set) => {
67
- compilation.addRuntimeModule(
68
- chunk,
69
- new CreateScriptUrlRuntimeModule()
70
- );
71
- return true;
72
- });
73
65
 
74
66
  compilation.hooks.runtimeRequirementInTree
75
67
  .for(RuntimeGlobals.ensureChunkHandlers)
@@ -15,6 +15,8 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
15
15
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
+ /** @typedef {import("../Chunk")} Chunk */
19
+
18
20
  class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
19
21
  constructor(runtimeRequirements, withCreateScriptUrl) {
20
22
  super("importScripts chunk loading", RuntimeModule.STAGE_ATTACH);
@@ -22,6 +24,33 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
22
24
  this._withCreateScriptUrl = withCreateScriptUrl;
23
25
  }
24
26
 
27
+ /**
28
+ * @private
29
+ * @param {Chunk} chunk chunk
30
+ * @returns {string} generated code
31
+ */
32
+ _generateBaseUri(chunk) {
33
+ const options = chunk.getEntryOptions();
34
+ if (options && options.baseUri) {
35
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
36
+ }
37
+ const outputName = this.compilation.getPath(
38
+ getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
39
+ {
40
+ chunk,
41
+ contentHashType: "javascript"
42
+ }
43
+ );
44
+ const rootOutputDir = getUndoPath(
45
+ outputName,
46
+ this.compilation.outputOptions.path,
47
+ false
48
+ );
49
+ return `${RuntimeGlobals.baseURI} = self.location + ${JSON.stringify(
50
+ rootOutputDir ? "/../" + rootOutputDir : ""
51
+ )};`;
52
+ }
53
+
25
54
  /**
26
55
  * @returns {string} runtime code
27
56
  */
@@ -31,10 +60,11 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
31
60
  chunkGraph,
32
61
  compilation: {
33
62
  runtimeTemplate,
34
- outputOptions: { globalObject, chunkLoadingGlobal, hotUpdateGlobal }
63
+ outputOptions: { chunkLoadingGlobal, hotUpdateGlobal }
35
64
  },
36
65
  _withCreateScriptUrl: withCreateScriptUrl
37
66
  } = this;
67
+ const globalObject = runtimeTemplate.globalObject;
38
68
  const fn = RuntimeGlobals.ensureChunkHandlers;
39
69
  const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
40
70
  const withLoading = this.runtimeRequirements.has(
@@ -52,33 +82,14 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
52
82
  const hasJsMatcher = compileBooleanMatcher(
53
83
  chunkGraph.getChunkConditionMap(chunk, chunkHasJs)
54
84
  );
55
- const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
56
-
57
- const outputName = this.compilation.getPath(
58
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
59
- {
60
- chunk,
61
- contentHashType: "javascript"
62
- }
63
- );
64
- const rootOutputDir = getUndoPath(
65
- outputName,
66
- this.compilation.outputOptions.path,
67
- false
68
- );
85
+ const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
69
86
 
70
87
  const stateExpression = withHmr
71
88
  ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_importScripts`
72
89
  : undefined;
73
90
 
74
91
  return Template.asString([
75
- withBaseURI
76
- ? Template.asString([
77
- `${RuntimeGlobals.baseURI} = self.location + ${JSON.stringify(
78
- rootOutputDir ? "/../" + rootOutputDir : ""
79
- )};`
80
- ])
81
- : "// no baseURI",
92
+ withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
82
93
  "",
83
94
  "// object to store loaded chunks",
84
95
  '// "1" means "already loaded"',
package/module.d.ts ADDED
@@ -0,0 +1,215 @@
1
+ declare namespace webpack {
2
+ type HotEvent =
3
+ | {
4
+ type: "disposed";
5
+ /** The module in question. */
6
+ moduleId: number;
7
+ }
8
+ | {
9
+ type: "self-declined" | "unaccepted";
10
+ /** The module in question. */
11
+ moduleId: number;
12
+ /** the chain from where the update was propagated. */
13
+ chain: number[];
14
+ }
15
+ | {
16
+ type: "declined";
17
+ /** The module in question. */
18
+ moduleId: number;
19
+ /** the chain from where the update was propagated. */
20
+ chain: number[];
21
+ /** the module id of the declining parent */
22
+ parentId: number;
23
+ }
24
+ | {
25
+ type: "accepted";
26
+ /** The module in question. */
27
+ moduleId: number;
28
+ /** the chain from where the update was propagated. */
29
+ chain: number[];
30
+ /** the modules that are outdated and will be disposed */
31
+ outdatedModules: number[];
32
+ /** the accepted dependencies that are outdated */
33
+ outdatedDependencies: {
34
+ [id: number]: number[];
35
+ };
36
+ }
37
+ | {
38
+ type: "accept-error-handler-errored";
39
+ /** The module in question. */
40
+ moduleId: number;
41
+ /** the module id owning the accept handler. */
42
+ dependencyId: number;
43
+ /** the thrown error */
44
+ error: Error;
45
+ /** the error thrown by the module before the error handler tried to handle it. */
46
+ originalError: Error;
47
+ }
48
+ | {
49
+ type: "self-accept-error-handler-errored";
50
+ /** The module in question. */
51
+ moduleId: number;
52
+ /** the thrown error */
53
+ error: Error;
54
+ /** the error thrown by the module before the error handler tried to handle it. */
55
+ originalError: Error;
56
+ }
57
+ | {
58
+ type: "accept-errored";
59
+ /** The module in question. */
60
+ moduleId: number;
61
+ /** the module id owning the accept handler. */
62
+ dependencyId: number;
63
+ /** the thrown error */
64
+ error: Error;
65
+ }
66
+ | {
67
+ type: "self-accept-errored";
68
+ /** The module in question. */
69
+ moduleId: number;
70
+ /** the thrown error */
71
+ error: Error;
72
+ };
73
+
74
+ interface ApplyOptions {
75
+ ignoreUnaccepted?: boolean;
76
+ ignoreDeclined?: boolean;
77
+ ignoreErrored?: boolean;
78
+ onDeclined?(callback: (info: HotEvent) => void): void;
79
+ onUnaccepted?(callback: (info: HotEvent) => void): void;
80
+ onAccepted?(callback: (info: HotEvent) => void): void;
81
+ onDisposed?(callback: (info: HotEvent) => void): void;
82
+ onErrored?(callback: (info: HotEvent) => void): void;
83
+ }
84
+
85
+ const enum HotUpdateStatus {
86
+ idle = "idle",
87
+ check = "check",
88
+ prepare = "prepare",
89
+ ready = "ready",
90
+ dispose = "dispose",
91
+ apply = "apply",
92
+ abort = "abort",
93
+ fail = "fail"
94
+ }
95
+
96
+ interface Hot {
97
+ accept: {
98
+ (
99
+ modules: string | string[],
100
+ callback?: (outdatedDependencies: string[]) => void,
101
+ errorHandler?: (
102
+ err: Error,
103
+ context: { moduleId: string | number; dependencyId: string | number }
104
+ ) => void
105
+ ): void;
106
+ (
107
+ errorHandler?: (
108
+ err: Error,
109
+ ids: { moduleId: string | number; module: NodeJS.Module }
110
+ ) => void
111
+ ): void;
112
+ };
113
+ status(): HotUpdateStatus;
114
+ decline(module?: string | string[]): void;
115
+ dispose(callback: (data: object) => void): void;
116
+ addDisposeHandler(callback: (data: object) => void): void;
117
+ removeDisposeHandler(callback: (data: object) => void): void;
118
+ invalidate(): void;
119
+ addStatusHandler(callback: (status: HotUpdateStatus) => void): void;
120
+ removeStatusHandler(callback: (status: HotUpdateStatus) => void): void;
121
+ data: object;
122
+ check(
123
+ autoApply?: boolean | ApplyOptions
124
+ ): Promise<(string | number)[] | null>;
125
+ apply(options?: ApplyOptions): Promise<(string | number)[] | null>;
126
+ }
127
+
128
+ interface ExportInfo {
129
+ used: boolean;
130
+ provideInfo: boolean | null | undefined;
131
+ useInfo: boolean | null | undefined;
132
+ canMangle: boolean;
133
+ }
134
+
135
+ interface ExportsInfo {
136
+ [k: string]: ExportInfo & ExportsInfo;
137
+ }
138
+
139
+ interface Context {
140
+ resolve(dependency: string): string | number;
141
+ keys(): Array<string>;
142
+ id: string | number;
143
+ (dependency: string): unknown;
144
+ }
145
+ }
146
+
147
+ interface ImportMeta {
148
+ url: string;
149
+ webpack: number;
150
+ webpackHot: webpack.Hot;
151
+ webpackContext: (
152
+ request: string,
153
+ options?: {
154
+ recursive?: boolean;
155
+ regExp?: RegExp;
156
+ include?: RegExp;
157
+ exclude?: RegExp;
158
+ preload?: boolean | number;
159
+ prefetch?: boolean | number;
160
+ chunkName?: string;
161
+ exports?: string | string[][];
162
+ mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
163
+ }
164
+ ) => webpack.Context;
165
+ }
166
+
167
+ declare const __resourceQuery: string;
168
+ declare var __webpack_public_path__: string;
169
+ declare var __webpack_nonce__: string;
170
+ declare const __webpack_chunkname__: string;
171
+ declare var __webpack_base_uri__: string;
172
+ declare var __webpack_runtime_id__: string;
173
+ declare const __webpack_hash__: string;
174
+ declare const __webpack_modules__: Record<string | number, NodeJS.Module>;
175
+ declare const __webpack_require__: (id: string | number) => unknown;
176
+ declare var __webpack_chunk_load__: (chunkId: string | number) => Promise<void>;
177
+ declare var __webpack_get_script_filename__: (
178
+ chunkId: string | number
179
+ ) => string;
180
+ declare var __webpack_is_included__: (request: string) => boolean;
181
+ declare var __webpack_exports_info__: webpack.ExportsInfo;
182
+ declare const __webpack_share_scopes__: Record<
183
+ string,
184
+ Record<
185
+ string,
186
+ { loaded?: 1; get: () => Promise<unknown>; from: string; eager: boolean }
187
+ >
188
+ >;
189
+ declare var __webpack_init_sharing__: (scope: string) => Promise<void>;
190
+ declare var __non_webpack_require__: (id: any) => unknown;
191
+ declare const __system_context__: object;
192
+
193
+ declare namespace NodeJS {
194
+ interface Module {
195
+ hot: webpack.Hot;
196
+ }
197
+
198
+ interface Require {
199
+ ensure(
200
+ dependencies: string[],
201
+ callback: (require: (module: string) => void) => void,
202
+ errorCallback?: (error: Error) => void,
203
+ chunkName?: string
204
+ ): void;
205
+ context(
206
+ request: string,
207
+ includeSubdirectories?: boolean,
208
+ filter?: RegExp,
209
+ mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once"
210
+ ): webpack.Context;
211
+ include(dependency: string): void;
212
+ resolveWeak(dependency: string): void;
213
+ onError?: (error: Error) => void;
214
+ }
215
+ }
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.59.0",
3
+ "version": "5.76.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@types/eslint-scope": "^3.7.0",
9
- "@types/estree": "^0.0.50",
8
+ "@types/eslint-scope": "^3.7.3",
9
+ "@types/estree": "^0.0.51",
10
10
  "@webassemblyjs/ast": "1.11.1",
11
11
  "@webassemblyjs/wasm-edit": "1.11.1",
12
12
  "@webassemblyjs/wasm-parser": "1.11.1",
13
- "acorn": "^8.4.1",
13
+ "acorn": "^8.7.1",
14
14
  "acorn-import-assertions": "^1.7.6",
15
15
  "browserslist": "^4.14.5",
16
16
  "chrome-trace-event": "^1.0.2",
17
- "enhanced-resolve": "^5.8.3",
17
+ "enhanced-resolve": "^5.10.0",
18
18
  "es-module-lexer": "^0.9.0",
19
19
  "eslint-scope": "5.1.1",
20
20
  "events": "^3.2.0",
21
21
  "glob-to-regexp": "^0.4.1",
22
- "graceful-fs": "^4.2.4",
23
- "json-parse-better-errors": "^1.0.2",
22
+ "graceful-fs": "^4.2.9",
23
+ "json-parse-even-better-errors": "^2.3.1",
24
24
  "loader-runner": "^4.2.0",
25
25
  "mime-types": "^2.1.27",
26
26
  "neo-async": "^2.6.2",
27
27
  "schema-utils": "^3.1.0",
28
28
  "tapable": "^2.1.1",
29
29
  "terser-webpack-plugin": "^5.1.3",
30
- "watchpack": "^2.2.0",
31
- "webpack-sources": "^3.2.0"
30
+ "watchpack": "^2.4.0",
31
+ "webpack-sources": "^3.2.3"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
34
  "webpack-cli": {
@@ -39,8 +39,8 @@
39
39
  "@babel/core": "^7.11.1",
40
40
  "@babel/preset-react": "^7.10.4",
41
41
  "@types/es-module-lexer": "^0.4.1",
42
- "@types/jest": "^27.0.1",
43
- "@types/node": "^15.0.1",
42
+ "@types/jest": "^27.4.0",
43
+ "@types/node": "^17.0.16",
44
44
  "assemblyscript": "^0.19.16",
45
45
  "babel-loader": "^8.1.0",
46
46
  "benchmark": "^2.1.4",
@@ -56,7 +56,7 @@
56
56
  "es6-promise-polyfill": "^1.2.0",
57
57
  "eslint": "^7.14.0",
58
58
  "eslint-config-prettier": "^8.1.0",
59
- "eslint-plugin-jest": "^24.3.6",
59
+ "eslint-plugin-jest": "^24.7.0",
60
60
  "eslint-plugin-jsdoc": "^33.0.0",
61
61
  "eslint-plugin-node": "^11.0.0",
62
62
  "eslint-plugin-prettier": "^4.0.0",
@@ -66,17 +66,17 @@
66
66
  "husky": "^6.0.0",
67
67
  "is-ci": "^3.0.0",
68
68
  "istanbul": "^0.4.5",
69
- "jest": "^27.0.6",
70
- "jest-circus": "^27.0.6",
71
- "jest-cli": "^27.0.6",
72
- "jest-diff": "^27.0.2",
73
- "jest-junit": "^12.0.0",
69
+ "jest": "^27.5.0",
70
+ "jest-circus": "^27.5.0",
71
+ "jest-cli": "^27.5.0",
72
+ "jest-diff": "^27.5.0",
73
+ "jest-junit": "^13.0.0",
74
74
  "json-loader": "^0.5.7",
75
75
  "json5": "^2.1.3",
76
76
  "less": "^4.0.0",
77
77
  "less-loader": "^8.0.0",
78
78
  "lint-staged": "^11.0.0",
79
- "loader-utils": "^2.0.0",
79
+ "loader-utils": "^2.0.3",
80
80
  "lodash": "^4.17.19",
81
81
  "lodash-es": "^4.17.15",
82
82
  "memfs": "^3.2.0",
@@ -84,7 +84,7 @@
84
84
  "mini-svg-data-uri": "^1.2.3",
85
85
  "nyc": "^15.1.0",
86
86
  "open-cli": "^6.0.1",
87
- "prettier": "^2.2.0",
87
+ "prettier": "^2.7.1",
88
88
  "pretty-format": "^27.0.2",
89
89
  "pug": "^3.0.0",
90
90
  "pug-loader": "^2.4.0",
@@ -98,9 +98,9 @@
98
98
  "style-loader": "^2.0.0",
99
99
  "terser": "^5.7.0",
100
100
  "toml": "^3.0.0",
101
- "tooling": "webpack/tooling#v1.20.0",
101
+ "tooling": "webpack/tooling#v1.22.0",
102
102
  "ts-loader": "^8.0.2",
103
- "typescript": "^4.2.0-beta",
103
+ "typescript": "^4.8.4",
104
104
  "url-loader": "^4.1.0",
105
105
  "wast-loader": "^1.11.0",
106
106
  "webassembly-feature": "1.3.0",
@@ -121,6 +121,7 @@
121
121
  "url": "https://opencollective.com/webpack"
122
122
  },
123
123
  "homepage": "https://github.com/webpack/webpack",
124
+ "bugs": "https://github.com/webpack/webpack/issues",
124
125
  "main": "lib/index.js",
125
126
  "bin": {
126
127
  "webpack": "bin/webpack.js"
@@ -132,6 +133,7 @@
132
133
  "hot/",
133
134
  "schemas/",
134
135
  "SECURITY.md",
136
+ "module.d.ts",
135
137
  "types.d.ts"
136
138
  ],
137
139
  "scripts": {
@@ -142,28 +144,22 @@
142
144
  "test:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"<rootDir>/test/*.{basictest,longtest,test}.js\"",
143
145
  "test:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"<rootDir>/test/*.basictest.js\"",
144
146
  "test:unit": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.unittest.js\"",
145
- "travis:integration": "yarn cover:integration --ci $JEST",
146
- "travis:basic": "yarn cover:basic --ci $JEST",
147
- "travis:lintunit": "yarn lint && yarn cover:unit --ci $JEST",
148
- "travis:benchmark": "yarn benchmark --ci",
149
- "appveyor:integration": "yarn cover:integration --ci %JEST%",
150
- "appveyor:unit": "yarn cover:unit --ci %JEST%",
151
- "appveyor:benchmark": "yarn benchmark --ci",
152
147
  "build:examples": "cd examples && node buildAll.js",
153
148
  "type-report": "rimraf coverage && yarn cover:types && yarn cover:report && open-cli coverage/lcov-report/index.html",
154
149
  "pretest": "yarn lint",
155
150
  "prelint": "yarn setup",
156
- "lint": "yarn code-lint && yarn special-lint && yarn type-lint && yarn typings-lint && yarn yarn-lint && yarn pretty-lint && yarn spellcheck",
151
+ "lint": "yarn code-lint && yarn special-lint && yarn type-lint && yarn typings-test && yarn module-typings-test && yarn yarn-lint && yarn pretty-lint && yarn spellcheck",
157
152
  "code-lint": "eslint . --ext '.js' --cache",
158
153
  "type-lint": "tsc",
159
- "typings-lint": "tsc -p tsconfig.test.json",
160
- "spellcheck": "cspell \"{.github,benchmark,bin,examples,hot,lib,schemas,setup,tooling}/**/*.{md,yml,yaml,js,json}\" \"*.md\"",
154
+ "typings-test": "tsc -p tsconfig.types.test.json",
155
+ "module-typings-test": "tsc -p tsconfig.module.test.json",
156
+ "spellcheck": "cspell \"**/*\"",
161
157
  "special-lint": "node node_modules/tooling/lockfile-lint && node node_modules/tooling/schemas-lint && node node_modules/tooling/inherit-types && node node_modules/tooling/format-schemas && node tooling/generate-runtime-code.js && node tooling/generate-wasm-code.js && node node_modules/tooling/format-file-header && node node_modules/tooling/compile-to-definitions && node node_modules/tooling/precompile-schemas && node node_modules/tooling/generate-types --no-template-literals",
162
158
  "special-lint-fix": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-schemas --write && node tooling/generate-runtime-code.js --write && node tooling/generate-wasm-code.js --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/compile-to-definitions --write && node node_modules/tooling/precompile-schemas --write && node node_modules/tooling/generate-types --no-template-literals --write",
163
159
  "fix": "yarn code-lint --fix && yarn special-lint-fix && yarn pretty-lint-fix",
164
160
  "prepare": "husky install",
165
161
  "pretty-lint-base": "prettier \"*.{ts,json,yml,yaml,md}\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.json\" \"examples/*.md\"",
166
- "pretty-lint-base-all": "yarn pretty-lint-base \"*.js\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.js\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases,benchmarkCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"",
162
+ "pretty-lint-base-all": "yarn pretty-lint-base \"*.js\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.js\" \"module.d.ts\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases,benchmarkCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"",
167
163
  "pretty-lint-fix": "yarn pretty-lint-base-all --loglevel warn --write",
168
164
  "pretty-lint": "yarn pretty-lint-base --check",
169
165
  "yarn-lint": "yarn-deduplicate --fail --list -s highest yarn.lock",