webpack 5.65.0 → 5.68.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 (117) 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/CleanPlugin.js +1 -1
  7. package/lib/Compilation.js +91 -47
  8. package/lib/Compiler.js +57 -3
  9. package/lib/ContextModule.js +21 -17
  10. package/lib/DelegatedModule.js +1 -1
  11. package/lib/Dependency.js +10 -0
  12. package/lib/DependencyTemplate.js +9 -0
  13. package/lib/DependencyTemplates.js +1 -1
  14. package/lib/DllModule.js +1 -1
  15. package/lib/EvalDevToolModulePlugin.js +16 -1
  16. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  17. package/lib/ExternalModule.js +93 -53
  18. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  19. package/lib/FileSystemInfo.js +29 -25
  20. package/lib/Generator.js +2 -0
  21. package/lib/HookWebpackError.js +1 -1
  22. package/lib/Module.js +25 -4
  23. package/lib/ModuleFilenameHelpers.js +5 -1
  24. package/lib/MultiCompiler.js +1 -1
  25. package/lib/MultiWatching.js +1 -1
  26. package/lib/NormalModule.js +9 -5
  27. package/lib/RawModule.js +1 -1
  28. package/lib/RuntimeGlobals.js +29 -1
  29. package/lib/RuntimeModule.js +1 -1
  30. package/lib/RuntimePlugin.js +50 -0
  31. package/lib/RuntimeTemplate.js +21 -0
  32. package/lib/Template.js +2 -1
  33. package/lib/Watching.js +2 -2
  34. package/lib/WebpackOptionsApply.js +43 -2
  35. package/lib/asset/AssetGenerator.js +64 -24
  36. package/lib/asset/AssetModulesPlugin.js +3 -0
  37. package/lib/asset/RawDataUrlModule.js +148 -0
  38. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  39. package/lib/cache/ResolverCachePlugin.js +1 -1
  40. package/lib/cli.js +44 -3
  41. package/lib/config/defaults.js +79 -5
  42. package/lib/config/normalization.js +5 -0
  43. package/lib/container/ContainerEntryModule.js +4 -2
  44. package/lib/container/FallbackModule.js +4 -4
  45. package/lib/container/RemoteModule.js +4 -2
  46. package/lib/css/CssExportsGenerator.js +139 -0
  47. package/lib/css/CssGenerator.js +109 -0
  48. package/lib/css/CssLoadingRuntimeModule.js +447 -0
  49. package/lib/css/CssModulesPlugin.js +461 -0
  50. package/lib/css/CssParser.js +618 -0
  51. package/lib/css/walkCssTokens.js +659 -0
  52. package/lib/debug/ProfilingPlugin.js +12 -10
  53. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  54. package/lib/dependencies/CssExportDependency.js +85 -0
  55. package/lib/dependencies/CssImportDependency.js +75 -0
  56. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  57. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  58. package/lib/dependencies/CssUrlDependency.js +132 -0
  59. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  60. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  61. package/lib/dependencies/LoaderPlugin.js +2 -2
  62. package/lib/dependencies/URLDependency.js +3 -8
  63. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  64. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  65. package/lib/hmr/lazyCompilationBackend.js +4 -2
  66. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  67. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  68. package/lib/ids/IdHelpers.js +24 -10
  69. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  70. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  71. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  72. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  73. package/lib/index.js +5 -0
  74. package/lib/javascript/JavascriptGenerator.js +1 -0
  75. package/lib/javascript/StartupHelpers.js +3 -3
  76. package/lib/library/AssignLibraryPlugin.js +26 -3
  77. package/lib/library/EnableLibraryPlugin.js +11 -0
  78. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  79. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  80. package/lib/optimize/ConcatenatedModule.js +11 -5
  81. package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
  82. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  83. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  84. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  85. package/lib/schemes/HttpUriPlugin.js +8 -8
  86. package/lib/sharing/ConsumeSharedModule.js +4 -2
  87. package/lib/sharing/ProvideSharedModule.js +4 -2
  88. package/lib/sharing/utils.js +1 -1
  89. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  90. package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
  91. package/lib/util/ArrayHelpers.js +18 -4
  92. package/lib/util/AsyncQueue.js +1 -1
  93. package/lib/util/hash/xxhash64.js +2 -2
  94. package/lib/util/internalSerializables.js +11 -0
  95. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  96. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -2
  97. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  98. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  99. package/package.json +4 -11
  100. package/schemas/WebpackOptions.check.js +1 -1
  101. package/schemas/WebpackOptions.json +96 -1
  102. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  103. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  104. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  105. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  106. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  107. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  108. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  109. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  110. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  111. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  112. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  113. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  114. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  115. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  116. package/schemas/plugins/css/CssParserOptions.json +3 -0
  117. package/types.d.ts +249 -39
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} */
@@ -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
  */
@@ -1020,7 +1020,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1020
1020
  /** @type {Map<DepConstructor, ModuleFactory>} */
1021
1021
  this.dependencyFactories = new Map();
1022
1022
  /** @type {DependencyTemplates} */
1023
- this.dependencyTemplates = new DependencyTemplates();
1023
+ this.dependencyTemplates = new DependencyTemplates(
1024
+ this.outputOptions.hashFunction
1025
+ );
1024
1026
  this.childrenCounters = {};
1025
1027
  /** @type {Set<number|string>} */
1026
1028
  this.usedChunkIds = null;
@@ -3193,47 +3195,87 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3193
3195
  this;
3194
3196
  const results = this.codeGenerationResults;
3195
3197
  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);
3198
+ /** @type {Set<Module> | undefined} */
3199
+ let notCodeGeneratedModules = undefined;
3200
+ const runIteration = () => {
3201
+ let delayedJobs = [];
3202
+ let delayedModules = new Set();
3203
+ asyncLib.eachLimit(
3204
+ jobs,
3205
+ this.options.parallelism,
3206
+ (job, callback) => {
3207
+ const { module } = job;
3208
+ const { codeGenerationDependencies } = module;
3209
+ if (codeGenerationDependencies !== undefined) {
3210
+ if (
3211
+ notCodeGeneratedModules === undefined ||
3212
+ codeGenerationDependencies.some(dep => {
3213
+ const referencedModule = moduleGraph.getModule(dep);
3214
+ return notCodeGeneratedModules.has(referencedModule);
3215
+ })
3216
+ ) {
3217
+ delayedJobs.push(job);
3218
+ delayedModules.add(module);
3219
+ return callback();
3220
+ }
3215
3221
  }
3216
- );
3217
- },
3218
- err => {
3219
- if (err) return callback(err);
3220
- if (errors.length > 0) {
3221
- errors.sort(
3222
- compareSelect(err => err.module, compareModulesByIdentifier)
3222
+ const { hash, runtime, runtimes } = job;
3223
+ this._codeGenerationModule(
3224
+ module,
3225
+ runtime,
3226
+ runtimes,
3227
+ hash,
3228
+ dependencyTemplates,
3229
+ chunkGraph,
3230
+ moduleGraph,
3231
+ runtimeTemplate,
3232
+ errors,
3233
+ results,
3234
+ (err, codeGenerated) => {
3235
+ if (codeGenerated) statModulesGenerated++;
3236
+ else statModulesFromCache++;
3237
+ callback(err);
3238
+ }
3223
3239
  );
3224
- for (const error of errors) {
3225
- this.errors.push(error);
3240
+ },
3241
+ err => {
3242
+ if (err) return callback(err);
3243
+ if (delayedJobs.length > 0) {
3244
+ if (delayedJobs.length === jobs.length) {
3245
+ return callback(
3246
+ new Error(
3247
+ `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3248
+ delayedModules,
3249
+ m => m.identifier()
3250
+ ).join(", ")}`
3251
+ )
3252
+ );
3253
+ }
3254
+ jobs = delayedJobs;
3255
+ delayedJobs = [];
3256
+ notCodeGeneratedModules = delayedModules;
3257
+ delayedModules = new Set();
3258
+ return runIteration();
3259
+ }
3260
+ if (errors.length > 0) {
3261
+ errors.sort(
3262
+ compareSelect(err => err.module, compareModulesByIdentifier)
3263
+ );
3264
+ for (const error of errors) {
3265
+ this.errors.push(error);
3266
+ }
3226
3267
  }
3268
+ this.logger.log(
3269
+ `${Math.round(
3270
+ (100 * statModulesGenerated) /
3271
+ (statModulesGenerated + statModulesFromCache)
3272
+ )}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
3273
+ );
3274
+ callback();
3227
3275
  }
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
- );
3276
+ );
3277
+ };
3278
+ runIteration();
3237
3279
  }
3238
3280
 
3239
3281
  /**
@@ -3283,7 +3325,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3283
3325
  moduleGraph,
3284
3326
  dependencyTemplates,
3285
3327
  runtimeTemplate,
3286
- runtime
3328
+ runtime,
3329
+ codeGenerationResults: results
3287
3330
  });
3288
3331
  } catch (err) {
3289
3332
  errors.push(new CodeGenerationError(module, err));
@@ -3512,10 +3555,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3512
3555
  }
3513
3556
 
3514
3557
  /**
3558
+ * If `module` is passed, `loc` and `request` must also be passed.
3515
3559
  * @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
3560
+ * @param {Module=} module the module the references the chunk group
3561
+ * @param {DependencyLocation=} loc the location from with the chunk group is referenced (inside of module)
3562
+ * @param {string=} request the request from which the the chunk group is referenced
3519
3563
  * @returns {ChunkGroup} the new or existing chunk group
3520
3564
  */
3521
3565
  addChunkInGroup(groupOptions, module, loc, request) {
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();
@@ -71,7 +71,7 @@ const makeSerializable = require("./util/makeSerializable");
71
71
 
72
72
  /**
73
73
  * @callback ResolveDependenciesCallback
74
- * @param {Error=} err
74
+ * @param {(Error | null)=} err
75
75
  * @param {ContextElementDependency[]=} dependencies
76
76
  */
77
77
 
@@ -149,12 +149,9 @@ class ContextModule extends Module {
149
149
  this.resolveDependencies = undefined;
150
150
  }
151
151
 
152
- prettyRegExp(regexString) {
153
- // remove the "/" at the front and the beginning
154
- // "/foo/" -> "foo"
155
- return regexString
156
- .substring(1, regexString.length - 1)
157
- .replace(/!/g, "%21");
152
+ _prettyRegExp(regexString, stripSlash = true) {
153
+ const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C");
154
+ return stripSlash ? str.substring(1, str.length - 1) : str;
158
155
  }
159
156
 
160
157
  _createIdentifier() {
@@ -175,13 +172,19 @@ class ContextModule extends Module {
175
172
  identifier += `|${this.options.addon}`;
176
173
  }
177
174
  if (this.options.regExp) {
178
- identifier += `|${this.options.regExp}`;
175
+ identifier += `|${this._prettyRegExp(this.options.regExp, false)}`;
179
176
  }
180
177
  if (this.options.include) {
181
- identifier += `|include: ${this.options.include}`;
178
+ identifier += `|include: ${this._prettyRegExp(
179
+ this.options.include,
180
+ false
181
+ )}`;
182
182
  }
183
183
  if (this.options.exclude) {
184
- identifier += `|exclude: ${this.options.exclude}`;
184
+ identifier += `|exclude: ${this._prettyRegExp(
185
+ this.options.exclude,
186
+ false
187
+ )}`;
185
188
  }
186
189
  if (this.options.referencedExports) {
187
190
  identifier += `|referencedExports: ${JSON.stringify(
@@ -231,13 +234,13 @@ class ContextModule extends Module {
231
234
  identifier += ` ${requestShortener.shorten(this.options.addon)}`;
232
235
  }
233
236
  if (this.options.regExp) {
234
- identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
237
+ identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
235
238
  }
236
239
  if (this.options.include) {
237
- identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
240
+ identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
238
241
  }
239
242
  if (this.options.exclude) {
240
- identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
243
+ identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
241
244
  }
242
245
  if (this.options.referencedExports) {
243
246
  identifier += ` referencedExports: ${this.options.referencedExports
@@ -272,6 +275,7 @@ class ContextModule extends Module {
272
275
  this.context,
273
276
  options.associatedObjectForCache
274
277
  );
278
+ if (this.layer) identifier = `(${this.layer})/${identifier}`;
275
279
  if (this.options.mode) {
276
280
  identifier += ` ${this.options.mode}`;
277
281
  }
@@ -286,13 +290,13 @@ class ContextModule extends Module {
286
290
  )}`;
287
291
  }
288
292
  if (this.options.regExp) {
289
- identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
293
+ identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
290
294
  }
291
295
  if (this.options.include) {
292
- identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
296
+ identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
293
297
  }
294
298
  if (this.options.exclude) {
295
- identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
299
+ identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
296
300
  }
297
301
  if (this.options.referencedExports) {
298
302
  identifier += ` referencedExports: ${this.options.referencedExports
@@ -312,7 +316,7 @@ class ContextModule extends Module {
312
316
 
313
317
  /**
314
318
  * @param {NeedBuildContext} context context info
315
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
319
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
316
320
  * @returns {void}
317
321
  */
318
322
  needBuild({ fileSystemInfo }, callback) {
@@ -91,7 +91,7 @@ class DelegatedModule extends Module {
91
91
 
92
92
  /**
93
93
  * @param {NeedBuildContext} context context info
94
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
94
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
95
95
  * @returns {void}
96
96
  */
97
97
  needBuild(context, callback) {
package/lib/Dependency.js CHANGED
@@ -172,6 +172,16 @@ class Dependency {
172
172
  this._loc = loc;
173
173
  }
174
174
 
175
+ setLoc(startLine, startColumn, endLine, endColumn) {
176
+ this._locSL = startLine;
177
+ this._locSC = startColumn;
178
+ this._locEL = endLine;
179
+ this._locEC = endColumn;
180
+ this._locI = undefined;
181
+ this._locN = undefined;
182
+ this._loc = undefined;
183
+ }
184
+
175
185
  /**
176
186
  * @returns {string | null} an identifier to merge equal requests
177
187
  */
@@ -7,6 +7,7 @@
7
7
 
8
8
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
9
9
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
10
+ /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
10
11
  /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
11
12
  /** @typedef {import("./Dependency")} Dependency */
12
13
  /** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
@@ -28,8 +29,16 @@
28
29
  * @property {RuntimeSpec} runtime current runtimes, for which code is generated
29
30
  * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
30
31
  * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
32
+ * @property {CodeGenerationResults} codeGenerationResults the code generation results
31
33
  */
32
34
 
35
+ /**
36
+ * @typedef {Object} CssDependencyTemplateContextExtras
37
+ * @property {Map<string, string>} cssExports the css exports
38
+ */
39
+
40
+ /** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
41
+
33
42
  class DependencyTemplate {
34
43
  /* istanbul ignore next */
35
44
  /**
@@ -57,7 +57,7 @@ class DependencyTemplates {
57
57
  }
58
58
 
59
59
  clone() {
60
- const newInstance = new DependencyTemplates();
60
+ const newInstance = new DependencyTemplates(this._hashFunction);
61
61
  newInstance._map = new Map(this._map);
62
62
  newInstance._hash = this._hash;
63
63
  return newInstance;
package/lib/DllModule.js CHANGED
@@ -96,7 +96,7 @@ class DllModule extends Module {
96
96
 
97
97
  /**
98
98
  * @param {NeedBuildContext} context context info
99
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
99
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
100
100
  * @returns {void}
101
101
  */
102
102
  needBuild(context, callback) {
@@ -8,6 +8,7 @@
8
8
  const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ExternalModule = require("./ExternalModule");
10
10
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
11
+ const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
@@ -77,7 +78,13 @@ class EvalDevToolModulePlugin {
77
78
  .replace(/^\//, "")
78
79
  );
79
80
  const result = new RawSource(
80
- `eval(${JSON.stringify(content + footer)});`
81
+ `eval(${
82
+ compilation.outputOptions.trustedTypes
83
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
84
+ content + footer
85
+ )})`
86
+ : JSON.stringify(content + footer)
87
+ });`
81
88
  );
82
89
  cache.set(source, result);
83
90
  return result;
@@ -95,6 +102,14 @@ class EvalDevToolModulePlugin {
95
102
  hash.update("EvalDevToolModulePlugin");
96
103
  hash.update("2");
97
104
  });
105
+ if (compilation.outputOptions.trustedTypes) {
106
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
107
+ "EvalDevToolModulePlugin",
108
+ (module, set, context) => {
109
+ set.add(RuntimeGlobals.createScript);
110
+ }
111
+ );
112
+ }
98
113
  });
99
114
  }
100
115
  }
@@ -8,6 +8,7 @@
8
8
  const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
10
  const NormalModule = require("./NormalModule");
11
+ const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
12
13
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
13
14
  const ConcatenatedModule = require("./optimize/ConcatenatedModule");
@@ -165,7 +166,15 @@ class EvalSourceMapDevToolPlugin {
165
166
  ) + `\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
166
167
 
167
168
  return result(
168
- new RawSource(`eval(${JSON.stringify(content + footer)});`)
169
+ new RawSource(
170
+ `eval(${
171
+ compilation.outputOptions.trustedTypes
172
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
173
+ content + footer
174
+ )})`
175
+ : JSON.stringify(content + footer)
176
+ });`
177
+ )
169
178
  );
170
179
  }
171
180
  );
@@ -181,6 +190,14 @@ class EvalSourceMapDevToolPlugin {
181
190
  hash.update("EvalSourceMapDevToolPlugin");
182
191
  hash.update("2");
183
192
  });
193
+ if (compilation.outputOptions.trustedTypes) {
194
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
195
+ "EvalSourceMapDevToolPlugin",
196
+ (module, set, context) => {
197
+ set.add(RuntimeGlobals.createScript);
198
+ }
199
+ );
200
+ }
184
201
  }
185
202
  );
186
203
  }