webpack 5.65.0 → 5.69.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 (134) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +33 -0
  3. package/lib/Cache.js +1 -1
  4. package/lib/CacheFacade.js +4 -11
  5. package/lib/Chunk.js +2 -0
  6. package/lib/ChunkGraph.js +1 -2
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +93 -47
  9. package/lib/Compiler.js +57 -3
  10. package/lib/ContextModule.js +100 -41
  11. package/lib/ContextModuleFactory.js +60 -21
  12. package/lib/DelegatedModule.js +1 -1
  13. package/lib/Dependency.js +10 -0
  14. package/lib/DependencyTemplate.js +9 -0
  15. package/lib/DependencyTemplates.js +1 -1
  16. package/lib/DllModule.js +1 -1
  17. package/lib/EvalDevToolModulePlugin.js +16 -1
  18. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  19. package/lib/ExportsInfo.js +4 -4
  20. package/lib/ExternalModule.js +93 -53
  21. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  22. package/lib/FileSystemInfo.js +29 -25
  23. package/lib/Generator.js +2 -0
  24. package/lib/HookWebpackError.js +1 -1
  25. package/lib/Module.js +25 -4
  26. package/lib/ModuleFilenameHelpers.js +5 -1
  27. package/lib/MultiCompiler.js +1 -1
  28. package/lib/MultiWatching.js +1 -1
  29. package/lib/NormalModule.js +9 -5
  30. package/lib/NormalModuleFactory.js +25 -27
  31. package/lib/ProgressPlugin.js +1 -1
  32. package/lib/RawModule.js +1 -1
  33. package/lib/RuntimeGlobals.js +29 -1
  34. package/lib/RuntimeModule.js +1 -1
  35. package/lib/RuntimePlugin.js +50 -0
  36. package/lib/RuntimeTemplate.js +21 -0
  37. package/lib/Template.js +2 -1
  38. package/lib/TemplatedPathPlugin.js +48 -23
  39. package/lib/Watching.js +2 -2
  40. package/lib/WebpackOptionsApply.js +43 -2
  41. package/lib/asset/AssetGenerator.js +67 -26
  42. package/lib/asset/AssetModulesPlugin.js +3 -0
  43. package/lib/asset/RawDataUrlModule.js +148 -0
  44. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  45. package/lib/buildChunkGraph.js +1 -1
  46. package/lib/cache/ResolverCachePlugin.js +81 -29
  47. package/lib/cli.js +44 -3
  48. package/lib/config/defaults.js +86 -7
  49. package/lib/config/normalization.js +5 -0
  50. package/lib/container/ContainerEntryModule.js +4 -2
  51. package/lib/container/FallbackModule.js +4 -4
  52. package/lib/container/RemoteModule.js +4 -2
  53. package/lib/css/CssExportsGenerator.js +139 -0
  54. package/lib/css/CssGenerator.js +109 -0
  55. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  56. package/lib/css/CssModulesPlugin.js +462 -0
  57. package/lib/css/CssParser.js +618 -0
  58. package/lib/css/walkCssTokens.js +659 -0
  59. package/lib/debug/ProfilingPlugin.js +15 -14
  60. package/lib/dependencies/ContextElementDependency.js +8 -2
  61. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  62. package/lib/dependencies/CssExportDependency.js +85 -0
  63. package/lib/dependencies/CssImportDependency.js +75 -0
  64. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  65. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  66. package/lib/dependencies/CssUrlDependency.js +132 -0
  67. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  68. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  69. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  70. package/lib/dependencies/LoaderPlugin.js +2 -2
  71. package/lib/dependencies/URLDependency.js +3 -8
  72. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  73. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  74. package/lib/hmr/lazyCompilationBackend.js +4 -2
  75. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  76. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  77. package/lib/ids/IdHelpers.js +24 -10
  78. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  79. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  80. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  81. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  82. package/lib/index.js +10 -0
  83. package/lib/javascript/JavascriptGenerator.js +1 -0
  84. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  85. package/lib/javascript/StartupHelpers.js +6 -5
  86. package/lib/library/AssignLibraryPlugin.js +34 -5
  87. package/lib/library/EnableLibraryPlugin.js +11 -0
  88. package/lib/node/NodeTargetPlugin.js +1 -0
  89. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  90. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  91. package/lib/optimize/ConcatenatedModule.js +21 -9
  92. package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
  93. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  94. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  95. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  96. package/lib/schemes/HttpUriPlugin.js +32 -11
  97. package/lib/serialization/FileMiddleware.js +44 -9
  98. package/lib/sharing/ConsumeSharedModule.js +4 -2
  99. package/lib/sharing/ProvideSharedModule.js +4 -2
  100. package/lib/sharing/utils.js +1 -1
  101. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  102. package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
  103. package/lib/util/ArrayHelpers.js +18 -4
  104. package/lib/util/AsyncQueue.js +1 -1
  105. package/lib/util/compileBooleanMatcher.js +1 -1
  106. package/lib/util/deterministicGrouping.js +1 -1
  107. package/lib/util/hash/xxhash64.js +2 -2
  108. package/lib/util/identifier.js +65 -44
  109. package/lib/util/internalSerializables.js +11 -0
  110. package/lib/util/nonNumericOnlyHash.js +22 -0
  111. package/lib/util/semver.js +17 -10
  112. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  113. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -2
  114. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  115. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  116. package/package.json +16 -23
  117. package/schemas/WebpackOptions.check.js +1 -1
  118. package/schemas/WebpackOptions.json +96 -1
  119. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  120. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  121. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  122. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  123. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  124. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  125. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  126. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  127. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  128. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  129. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  130. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  131. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  132. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  133. package/schemas/plugins/css/CssParserOptions.json +3 -0
  134. package/types.d.ts +295 -59
package/README.md CHANGED
@@ -687,7 +687,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
687
687
 
688
688
  - [@google](https://github.com/google) for [Google Web Toolkit (GWT)](http://www.gwtproject.org/), which aims to compile Java to JavaScript. It features a similar [Code Splitting](http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html) as webpack.
689
689
  - [@medikoo](https://github.com/medikoo) for [modules-webmake](https://github.com/medikoo/modules-webmake), which is a similar project. webpack was born because I wanted Code Splitting for modules-webmake. Interestingly the [Code Splitting issue is still open](https://github.com/medikoo/modules-webmake/issues/7) (thanks also to @Phoscur for the discussion).
690
- - [@substack](https://github.com/substack) for [browserify](http://browserify.org/), which is a similar project and source for many ideas.
690
+ - [@substack](https://github.com/substack) for [browserify](https://browserify.org/), which is a similar project and source for many ideas.
691
691
  - [@jrburke](https://github.com/jrburke) for [require.js](https://requirejs.org/), which is a similar project and source for many ideas.
692
692
  - [@defunctzombie](https://github.com/defunctzombie) for the [browser-field spec](https://github.com/defunctzombie/package-browser-field-spec), which makes modules available for node.js, browserify and webpack.
693
693
  - Every early webpack user, which contributed to webpack by writing issues or PRs. You influenced the direction...
package/lib/APIPlugin.js CHANGED
@@ -201,6 +201,39 @@ class APIPlugin {
201
201
  )
202
202
  .setRange(expr.range)
203
203
  );
204
+
205
+ parser.hooks.expression
206
+ .for("__webpack_module__.id")
207
+ .tap("APIPlugin", expr => {
208
+ parser.state.module.buildInfo.moduleConcatenationBailout =
209
+ "__webpack_module__.id";
210
+ const dep = new ConstDependency(
211
+ parser.state.module.moduleArgument + ".id",
212
+ expr.range,
213
+ [RuntimeGlobals.moduleId]
214
+ );
215
+ dep.loc = expr.loc;
216
+ parser.state.module.addPresentationalDependency(dep);
217
+ return true;
218
+ });
219
+
220
+ parser.hooks.expression
221
+ .for("__webpack_module__")
222
+ .tap("APIPlugin", expr => {
223
+ parser.state.module.buildInfo.moduleConcatenationBailout =
224
+ "__webpack_module__";
225
+ const dep = new ConstDependency(
226
+ parser.state.module.moduleArgument,
227
+ expr.range,
228
+ [RuntimeGlobals.module]
229
+ );
230
+ dep.loc = expr.loc;
231
+ parser.state.module.addPresentationalDependency(dep);
232
+ return true;
233
+ });
234
+ parser.hooks.evaluateTypeof
235
+ .for("__webpack_module__")
236
+ .tap("APIPlugin", evaluateToString("object"));
204
237
  };
205
238
 
206
239
  normalModuleFactory.hooks.parser
package/lib/Cache.js CHANGED
@@ -21,7 +21,7 @@ const {
21
21
  /**
22
22
  * @template T
23
23
  * @callback CallbackCache
24
- * @param {WebpackError=} err
24
+ * @param {(WebpackError | null)=} err
25
25
  * @param {T=} result
26
26
  * @returns {void}
27
27
  */
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { forEachBail } = require("enhanced-resolve");
8
9
  const asyncLib = require("neo-async");
9
10
  const getLazyHashedEtag = require("./cache/getLazyHashedEtag");
10
11
  const mergeEtags = require("./cache/mergeEtags");
@@ -18,7 +19,7 @@ const mergeEtags = require("./cache/mergeEtags");
18
19
  /**
19
20
  * @template T
20
21
  * @callback CallbackCache
21
- * @param {WebpackError=} err
22
+ * @param {(WebpackError | null)=} err
22
23
  * @param {T=} result
23
24
  * @returns {void}
24
25
  */
@@ -26,7 +27,7 @@ const mergeEtags = require("./cache/mergeEtags");
26
27
  /**
27
28
  * @template T
28
29
  * @callback CallbackNormalErrorCache
29
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
30
31
  * @param {T=} result
31
32
  * @returns {void}
32
33
  */
@@ -46,15 +47,7 @@ class MultiItemCache {
46
47
  * @returns {void}
47
48
  */
48
49
  get(callback) {
49
- const next = i => {
50
- this._items[i].get((err, result) => {
51
- if (err) return callback(err);
52
- if (result !== undefined) return callback(null, result);
53
- if (++i >= this._items.length) return callback();
54
- next(i);
55
- });
56
- };
57
- next(0);
50
+ forEachBail(this._items, (item, callback) => item.get(callback), callback);
58
51
  }
59
52
 
60
53
  /**
package/lib/Chunk.js CHANGED
@@ -80,6 +80,8 @@ class Chunk {
80
80
  this.preventIntegration = false;
81
81
  /** @type {(string | function(PathData, AssetInfo=): string)?} */
82
82
  this.filenameTemplate = undefined;
83
+ /** @type {(string | function(PathData, AssetInfo=): string)?} */
84
+ this.cssFilenameTemplate = undefined;
83
85
  /** @private @type {SortableSet<ChunkGroup>} */
84
86
  this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
85
87
  /** @type {RuntimeSpec} */
package/lib/ChunkGraph.js CHANGED
@@ -46,6 +46,7 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
46
46
 
47
47
  /** @typedef {(c: Chunk, chunkGraph: ChunkGraph) => boolean} ChunkFilterPredicate */
48
48
  /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
49
+ /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
49
50
 
50
51
  /**
51
52
  * @typedef {Object} ChunkSizeOptions
@@ -1180,8 +1181,6 @@ class ChunkGraph {
1180
1181
  return cgc.dependentHashModules;
1181
1182
  }
1182
1183
 
1183
- /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
1184
-
1185
1184
  /**
1186
1185
  * @param {Chunk} chunk the chunk
1187
1186
  * @returns {Iterable<EntryModuleWithChunkGroup>} iterable of modules (do not modify)
@@ -45,7 +45,7 @@ const validate = createSchemaValidation(
45
45
  * @param {OutputFileSystem} fs filesystem
46
46
  * @param {string} outputPath output path
47
47
  * @param {Set<string>} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
48
- * @param {function(Error=, Set<string>=): void} callback returns the filenames of the assets that shouldn't be there
48
+ * @param {function((Error | null)=, Set<string>=): void} callback returns the filenames of the assets that shouldn't be there
49
49
  * @returns {void}
50
50
  */
51
51
  const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
@@ -116,34 +116,34 @@ const { isSourceEqual } = require("./util/source");
116
116
 
117
117
  /**
118
118
  * @callback Callback
119
- * @param {WebpackError=} err
119
+ * @param {(WebpackError | null)=} err
120
120
  * @returns {void}
121
121
  */
122
122
 
123
123
  /**
124
124
  * @callback ModuleCallback
125
- * @param {WebpackError=} err
125
+ * @param {(WebpackError | null)=} err
126
126
  * @param {Module=} result
127
127
  * @returns {void}
128
128
  */
129
129
 
130
130
  /**
131
131
  * @callback ModuleFactoryResultCallback
132
- * @param {WebpackError=} err
132
+ * @param {(WebpackError | null)=} err
133
133
  * @param {ModuleFactoryResult=} result
134
134
  * @returns {void}
135
135
  */
136
136
 
137
137
  /**
138
138
  * @callback ModuleOrFactoryResultCallback
139
- * @param {WebpackError=} err
139
+ * @param {(WebpackError | null)=} err
140
140
  * @param {Module | ModuleFactoryResult=} result
141
141
  * @returns {void}
142
142
  */
143
143
 
144
144
  /**
145
145
  * @callback ExecuteModuleCallback
146
- * @param {WebpackError=} err
146
+ * @param {(WebpackError | null)=} err
147
147
  * @param {ExecuteModuleResult=} result
148
148
  * @returns {void}
149
149
  */
@@ -182,6 +182,7 @@ const { isSourceEqual } = require("./util/source");
182
182
 
183
183
  /**
184
184
  * @typedef {Object} ChunkHashContext
185
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
185
186
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
186
187
  * @property {ModuleGraph} moduleGraph the module graph
187
188
  * @property {ChunkGraph} chunkGraph the chunk graph
@@ -1020,7 +1021,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1020
1021
  /** @type {Map<DepConstructor, ModuleFactory>} */
1021
1022
  this.dependencyFactories = new Map();
1022
1023
  /** @type {DependencyTemplates} */
1023
- this.dependencyTemplates = new DependencyTemplates();
1024
+ this.dependencyTemplates = new DependencyTemplates(
1025
+ this.outputOptions.hashFunction
1026
+ );
1024
1027
  this.childrenCounters = {};
1025
1028
  /** @type {Set<number|string>} */
1026
1029
  this.usedChunkIds = null;
@@ -3193,47 +3196,87 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3193
3196
  this;
3194
3197
  const results = this.codeGenerationResults;
3195
3198
  const errors = [];
3196
- asyncLib.eachLimit(
3197
- jobs,
3198
- this.options.parallelism,
3199
- ({ module, hash, runtime, runtimes }, callback) => {
3200
- this._codeGenerationModule(
3201
- module,
3202
- runtime,
3203
- runtimes,
3204
- hash,
3205
- dependencyTemplates,
3206
- chunkGraph,
3207
- moduleGraph,
3208
- runtimeTemplate,
3209
- errors,
3210
- results,
3211
- (err, codeGenerated) => {
3212
- if (codeGenerated) statModulesGenerated++;
3213
- else statModulesFromCache++;
3214
- callback(err);
3199
+ /** @type {Set<Module> | undefined} */
3200
+ let notCodeGeneratedModules = undefined;
3201
+ const runIteration = () => {
3202
+ let delayedJobs = [];
3203
+ let delayedModules = new Set();
3204
+ asyncLib.eachLimit(
3205
+ jobs,
3206
+ this.options.parallelism,
3207
+ (job, callback) => {
3208
+ const { module } = job;
3209
+ const { codeGenerationDependencies } = module;
3210
+ if (codeGenerationDependencies !== undefined) {
3211
+ if (
3212
+ notCodeGeneratedModules === undefined ||
3213
+ codeGenerationDependencies.some(dep => {
3214
+ const referencedModule = moduleGraph.getModule(dep);
3215
+ return notCodeGeneratedModules.has(referencedModule);
3216
+ })
3217
+ ) {
3218
+ delayedJobs.push(job);
3219
+ delayedModules.add(module);
3220
+ return callback();
3221
+ }
3215
3222
  }
3216
- );
3217
- },
3218
- err => {
3219
- if (err) return callback(err);
3220
- if (errors.length > 0) {
3221
- errors.sort(
3222
- compareSelect(err => err.module, compareModulesByIdentifier)
3223
+ const { hash, runtime, runtimes } = job;
3224
+ this._codeGenerationModule(
3225
+ module,
3226
+ runtime,
3227
+ runtimes,
3228
+ hash,
3229
+ dependencyTemplates,
3230
+ chunkGraph,
3231
+ moduleGraph,
3232
+ runtimeTemplate,
3233
+ errors,
3234
+ results,
3235
+ (err, codeGenerated) => {
3236
+ if (codeGenerated) statModulesGenerated++;
3237
+ else statModulesFromCache++;
3238
+ callback(err);
3239
+ }
3223
3240
  );
3224
- for (const error of errors) {
3225
- this.errors.push(error);
3241
+ },
3242
+ err => {
3243
+ if (err) return callback(err);
3244
+ if (delayedJobs.length > 0) {
3245
+ if (delayedJobs.length === jobs.length) {
3246
+ return callback(
3247
+ new Error(
3248
+ `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3249
+ delayedModules,
3250
+ m => m.identifier()
3251
+ ).join(", ")}`
3252
+ )
3253
+ );
3254
+ }
3255
+ jobs = delayedJobs;
3256
+ delayedJobs = [];
3257
+ notCodeGeneratedModules = delayedModules;
3258
+ delayedModules = new Set();
3259
+ return runIteration();
3260
+ }
3261
+ if (errors.length > 0) {
3262
+ errors.sort(
3263
+ compareSelect(err => err.module, compareModulesByIdentifier)
3264
+ );
3265
+ for (const error of errors) {
3266
+ this.errors.push(error);
3267
+ }
3226
3268
  }
3269
+ this.logger.log(
3270
+ `${Math.round(
3271
+ (100 * statModulesGenerated) /
3272
+ (statModulesGenerated + statModulesFromCache)
3273
+ )}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
3274
+ );
3275
+ callback();
3227
3276
  }
3228
- this.logger.log(
3229
- `${Math.round(
3230
- (100 * statModulesGenerated) /
3231
- (statModulesGenerated + statModulesFromCache)
3232
- )}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
3233
- );
3234
- callback();
3235
- }
3236
- );
3277
+ );
3278
+ };
3279
+ runIteration();
3237
3280
  }
3238
3281
 
3239
3282
  /**
@@ -3283,7 +3326,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3283
3326
  moduleGraph,
3284
3327
  dependencyTemplates,
3285
3328
  runtimeTemplate,
3286
- runtime
3329
+ runtime,
3330
+ codeGenerationResults: results
3287
3331
  });
3288
3332
  } catch (err) {
3289
3333
  errors.push(new CodeGenerationError(module, err));
@@ -3512,10 +3556,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3512
3556
  }
3513
3557
 
3514
3558
  /**
3559
+ * If `module` is passed, `loc` and `request` must also be passed.
3515
3560
  * @param {string | ChunkGroupOptions} groupOptions options for the chunk group
3516
- * @param {Module} module the module the references the chunk group
3517
- * @param {DependencyLocation} loc the location from with the chunk group is referenced (inside of module)
3518
- * @param {string} request the request from which the the chunk group is referenced
3561
+ * @param {Module=} module the module the references the chunk group
3562
+ * @param {DependencyLocation=} loc the location from with the chunk group is referenced (inside of module)
3563
+ * @param {string=} request the request from which the the chunk group is referenced
3519
3564
  * @returns {ChunkGroup} the new or existing chunk group
3520
3565
  */
3521
3566
  addChunkInGroup(groupOptions, module, loc, request) {
@@ -4093,6 +4138,7 @@ This prevents using hashes of each other and should be avoided.`);
4093
4138
  chunk.updateHash(chunkHash, chunkGraph);
4094
4139
  this.hooks.chunkHash.call(chunk, chunkHash, {
4095
4140
  chunkGraph,
4141
+ codeGenerationResults: this.codeGenerationResults,
4096
4142
  moduleGraph: this.moduleGraph,
4097
4143
  runtimeTemplate: this.runtimeTemplate
4098
4144
  });
package/lib/Compiler.js CHANGED
@@ -58,13 +58,13 @@ const { isSourceEqual } = require("./util/source");
58
58
  /**
59
59
  * @template T
60
60
  * @callback Callback
61
- * @param {Error=} err
61
+ * @param {(Error | null)=} err
62
62
  * @param {T=} result
63
63
  */
64
64
 
65
65
  /**
66
66
  * @callback RunAsChildCallback
67
- * @param {Error=} err
67
+ * @param {(Error | null)=} err
68
68
  * @param {Chunk[]=} entries
69
69
  * @param {Compilation=} compilation
70
70
  */
@@ -165,6 +165,11 @@ class Compiler {
165
165
  /** @type {AsyncSeriesHook<[Compilation]>} */
166
166
  afterCompile: new AsyncSeriesHook(["compilation"]),
167
167
 
168
+ /** @type {AsyncSeriesHook<[]>} */
169
+ readRecords: new AsyncSeriesHook([]),
170
+ /** @type {AsyncSeriesHook<[]>} */
171
+ emitRecords: new AsyncSeriesHook([]),
172
+
168
173
  /** @type {AsyncSeriesHook<[Compiler]>} */
169
174
  watchRun: new AsyncSeriesHook(["compiler"]),
170
175
  /** @type {SyncHook<[Error]>} */
@@ -882,8 +887,32 @@ ${other}`);
882
887
  * @returns {void}
883
888
  */
884
889
  emitRecords(callback) {
885
- if (!this.recordsOutputPath) return callback();
890
+ if (this.hooks.emitRecords.isUsed()) {
891
+ if (this.recordsOutputPath) {
892
+ asyncLib.parallel(
893
+ [
894
+ cb => this.hooks.emitRecords.callAsync(cb),
895
+ this._emitRecords.bind(this)
896
+ ],
897
+ err => callback(err)
898
+ );
899
+ } else {
900
+ this.hooks.emitRecords.callAsync(callback);
901
+ }
902
+ } else {
903
+ if (this.recordsOutputPath) {
904
+ this._emitRecords(callback);
905
+ } else {
906
+ callback();
907
+ }
908
+ }
909
+ }
886
910
 
911
+ /**
912
+ * @param {Callback<void>} callback signals when the call finishes
913
+ * @returns {void}
914
+ */
915
+ _emitRecords(callback) {
887
916
  const writeFile = () => {
888
917
  this.outputFileSystem.writeFile(
889
918
  this.recordsOutputPath,
@@ -926,6 +955,31 @@ ${other}`);
926
955
  * @returns {void}
927
956
  */
928
957
  readRecords(callback) {
958
+ if (this.hooks.readRecords.isUsed()) {
959
+ if (this.recordsInputPath) {
960
+ asyncLib.parallel([
961
+ cb => this.hooks.readRecords.callAsync(cb),
962
+ this._readRecords.bind(this)
963
+ ]);
964
+ } else {
965
+ this.records = {};
966
+ this.hooks.readRecords.callAsync(callback);
967
+ }
968
+ } else {
969
+ if (this.recordsInputPath) {
970
+ this._readRecords(callback);
971
+ } else {
972
+ this.records = {};
973
+ callback();
974
+ }
975
+ }
976
+ }
977
+
978
+ /**
979
+ * @param {Callback<void>} callback signals when the call finishes
980
+ * @returns {void}
981
+ */
982
+ _readRecords(callback) {
929
983
  if (!this.recordsInputPath) {
930
984
  this.records = {};
931
985
  return callback();