webpack 5.66.0 → 5.69.1

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 (97) 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 +2 -2
  5. package/lib/ChunkGraph.js +1 -2
  6. package/lib/CleanPlugin.js +1 -1
  7. package/lib/Compilation.js +14 -9
  8. package/lib/Compiler.js +57 -3
  9. package/lib/ContextModule.js +21 -17
  10. package/lib/DelegatedModule.js +1 -1
  11. package/lib/DependencyTemplates.js +1 -1
  12. package/lib/DllModule.js +1 -1
  13. package/lib/EvalDevToolModulePlugin.js +16 -1
  14. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  15. package/lib/ExportsInfo.js +4 -4
  16. package/lib/ExternalModule.js +1 -1
  17. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  18. package/lib/FileSystemInfo.js +29 -25
  19. package/lib/HookWebpackError.js +1 -1
  20. package/lib/Module.js +1 -3
  21. package/lib/MultiCompiler.js +1 -1
  22. package/lib/MultiWatching.js +1 -1
  23. package/lib/NormalModule.js +6 -4
  24. package/lib/NormalModuleFactory.js +25 -27
  25. package/lib/ProgressPlugin.js +1 -1
  26. package/lib/RawModule.js +1 -1
  27. package/lib/RuntimeGlobals.js +18 -0
  28. package/lib/RuntimeModule.js +1 -1
  29. package/lib/RuntimePlugin.js +28 -3
  30. package/lib/RuntimeTemplate.js +1 -1
  31. package/lib/TemplatedPathPlugin.js +48 -23
  32. package/lib/Watching.js +1 -1
  33. package/lib/WebpackOptionsApply.js +1 -1
  34. package/lib/asset/AssetGenerator.js +65 -26
  35. package/lib/asset/AssetModulesPlugin.js +3 -0
  36. package/lib/asset/RawDataUrlModule.js +8 -5
  37. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  38. package/lib/buildChunkGraph.js +1 -1
  39. package/lib/cache/ResolverCachePlugin.js +1 -1
  40. package/lib/cli.js +44 -3
  41. package/lib/config/defaults.js +30 -7
  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 +3 -0
  48. package/lib/css/CssLoadingRuntimeModule.js +201 -154
  49. package/lib/css/CssModulesPlugin.js +22 -4
  50. package/lib/debug/ProfilingPlugin.js +15 -14
  51. package/lib/dependencies/ContextElementDependency.js +8 -2
  52. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  53. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  54. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  55. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  56. package/lib/dependencies/LoaderPlugin.js +2 -2
  57. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  58. package/lib/hmr/lazyCompilationBackend.js +1 -1
  59. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  60. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  61. package/lib/ids/IdHelpers.js +24 -10
  62. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  63. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  64. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  65. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  66. package/lib/index.js +10 -0
  67. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  68. package/lib/javascript/StartupHelpers.js +3 -2
  69. package/lib/library/AssignLibraryPlugin.js +8 -2
  70. package/lib/node/NodeTargetPlugin.js +1 -0
  71. package/lib/optimize/ConcatenatedModule.js +11 -5
  72. package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
  73. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  74. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  75. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  76. package/lib/schemes/HttpUriPlugin.js +32 -11
  77. package/lib/serialization/FileMiddleware.js +44 -9
  78. package/lib/sharing/ConsumeSharedModule.js +4 -2
  79. package/lib/sharing/ProvideSharedModule.js +4 -2
  80. package/lib/sharing/utils.js +1 -1
  81. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  82. package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
  83. package/lib/util/ArrayHelpers.js +18 -4
  84. package/lib/util/AsyncQueue.js +1 -1
  85. package/lib/util/compileBooleanMatcher.js +1 -1
  86. package/lib/util/deterministicGrouping.js +1 -1
  87. package/lib/util/identifier.js +65 -44
  88. package/lib/util/nonNumericOnlyHash.js +22 -0
  89. package/lib/util/semver.js +17 -10
  90. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  91. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  92. package/package.json +14 -21
  93. package/schemas/WebpackOptions.check.js +1 -1
  94. package/schemas/WebpackOptions.json +47 -6
  95. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  96. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  97. package/types.d.ts +207 -60
@@ -1185,7 +1185,7 @@ class FileSystemInfo {
1185
1185
 
1186
1186
  /**
1187
1187
  * @param {string} path file path
1188
- * @param {function(WebpackError=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1188
+ * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1189
1189
  * @returns {void}
1190
1190
  */
1191
1191
  getFileTimestamp(path, callback) {
@@ -1196,7 +1196,7 @@ class FileSystemInfo {
1196
1196
 
1197
1197
  /**
1198
1198
  * @param {string} path context path
1199
- * @param {function(WebpackError=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1199
+ * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1200
1200
  * @returns {void}
1201
1201
  */
1202
1202
  getContextTimestamp(path, callback) {
@@ -1217,7 +1217,7 @@ class FileSystemInfo {
1217
1217
 
1218
1218
  /**
1219
1219
  * @param {string} path context path
1220
- * @param {function(WebpackError=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1220
+ * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1221
1221
  * @returns {void}
1222
1222
  */
1223
1223
  _getUnresolvedContextTimestamp(path, callback) {
@@ -1228,7 +1228,7 @@ class FileSystemInfo {
1228
1228
 
1229
1229
  /**
1230
1230
  * @param {string} path file path
1231
- * @param {function(WebpackError=, string=): void} callback callback function
1231
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1232
1232
  * @returns {void}
1233
1233
  */
1234
1234
  getFileHash(path, callback) {
@@ -1239,7 +1239,7 @@ class FileSystemInfo {
1239
1239
 
1240
1240
  /**
1241
1241
  * @param {string} path context path
1242
- * @param {function(WebpackError=, string=): void} callback callback function
1242
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1243
1243
  * @returns {void}
1244
1244
  */
1245
1245
  getContextHash(path, callback) {
@@ -1259,7 +1259,7 @@ class FileSystemInfo {
1259
1259
 
1260
1260
  /**
1261
1261
  * @param {string} path context path
1262
- * @param {function(WebpackError=, ContextHash=): void} callback callback function
1262
+ * @param {function((WebpackError | null)=, ContextHash=): void} callback callback function
1263
1263
  * @returns {void}
1264
1264
  */
1265
1265
  _getUnresolvedContextHash(path, callback) {
@@ -1270,7 +1270,7 @@ class FileSystemInfo {
1270
1270
 
1271
1271
  /**
1272
1272
  * @param {string} path context path
1273
- * @param {function(WebpackError=, ResolvedContextTimestampAndHash=): void} callback callback function
1273
+ * @param {function((WebpackError | null)=, ResolvedContextTimestampAndHash=): void} callback callback function
1274
1274
  * @returns {void}
1275
1275
  */
1276
1276
  getContextTsh(path, callback) {
@@ -1290,7 +1290,7 @@ class FileSystemInfo {
1290
1290
 
1291
1291
  /**
1292
1292
  * @param {string} path context path
1293
- * @param {function(WebpackError=, ContextTimestampAndHash=): void} callback callback function
1293
+ * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function
1294
1294
  * @returns {void}
1295
1295
  */
1296
1296
  _getUnresolvedContextTsh(path, callback) {
@@ -1330,7 +1330,7 @@ class FileSystemInfo {
1330
1330
  /**
1331
1331
  * @param {string} context context directory
1332
1332
  * @param {Iterable<string>} deps dependencies
1333
- * @param {function(Error=, ResolveBuildDependenciesResult=): void} callback callback function
1333
+ * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function
1334
1334
  * @returns {void}
1335
1335
  */
1336
1336
  resolveBuildDependencies(context, deps, callback) {
@@ -1798,7 +1798,7 @@ class FileSystemInfo {
1798
1798
 
1799
1799
  /**
1800
1800
  * @param {Map<string, string | false>} resolveResults results from resolving
1801
- * @param {function(Error=, boolean=): void} callback callback with true when resolveResults resolve the same way
1801
+ * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way
1802
1802
  * @returns {void}
1803
1803
  */
1804
1804
  checkResolveResultsValid(resolveResults, callback) {
@@ -1880,7 +1880,7 @@ class FileSystemInfo {
1880
1880
  * @param {Object} options options object (for future extensions)
1881
1881
  * @param {boolean=} options.hash should use hash to snapshot
1882
1882
  * @param {boolean=} options.timestamp should use timestamp to snapshot
1883
- * @param {function(WebpackError=, Snapshot=): void} callback callback function
1883
+ * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function
1884
1884
  * @returns {void}
1885
1885
  */
1886
1886
  createSnapshot(startTime, files, directories, missing, options, callback) {
@@ -2256,8 +2256,10 @@ class FileSystemInfo {
2256
2256
  for (const path of managedItems) {
2257
2257
  const cache = this._managedItems.get(path);
2258
2258
  if (cache !== undefined) {
2259
- if (cache !== "missing") {
2259
+ if (!cache.startsWith("*")) {
2260
2260
  managedFiles.add(join(this.fs, path, "package.json"));
2261
+ } else if (cache === "*nested") {
2262
+ managedMissing.add(join(this.fs, path, "package.json"));
2261
2263
  }
2262
2264
  managedItemInfo.set(path, cache);
2263
2265
  } else {
@@ -2271,8 +2273,10 @@ class FileSystemInfo {
2271
2273
  }
2272
2274
  jobError();
2273
2275
  } else if (entry) {
2274
- if (entry !== "missing") {
2276
+ if (!entry.startsWith("*")) {
2275
2277
  managedFiles.add(join(this.fs, path, "package.json"));
2278
+ } else if (cache === "*nested") {
2279
+ managedMissing.add(join(this.fs, path, "package.json"));
2276
2280
  }
2277
2281
  managedItemInfo.set(path, entry);
2278
2282
  jobDone();
@@ -2375,7 +2379,7 @@ class FileSystemInfo {
2375
2379
 
2376
2380
  /**
2377
2381
  * @param {Snapshot} snapshot the snapshot made
2378
- * @param {function(WebpackError=, boolean=): void} callback callback function
2382
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2379
2383
  * @returns {void}
2380
2384
  */
2381
2385
  checkSnapshotValid(snapshot, callback) {
@@ -2395,7 +2399,7 @@ class FileSystemInfo {
2395
2399
 
2396
2400
  /**
2397
2401
  * @param {Snapshot} snapshot the snapshot made
2398
- * @param {function(WebpackError=, boolean=): void} callback callback function
2402
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2399
2403
  * @returns {void}
2400
2404
  */
2401
2405
  _checkSnapshotValidNoCache(snapshot, callback) {
@@ -2944,7 +2948,7 @@ class FileSystemInfo {
2944
2948
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file
2945
2949
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory
2946
2950
  * @param {function(string[], ItemType[]): T} options.reduce called from all context items
2947
- * @param {function(Error=, (T)=): void} callback callback
2951
+ * @param {function((Error | null)=, (T)=): void} callback callback
2948
2952
  */
2949
2953
  _readContext(
2950
2954
  {
@@ -3127,7 +3131,7 @@ class FileSystemInfo {
3127
3131
 
3128
3132
  /**
3129
3133
  * @param {ContextFileSystemInfoEntry} entry entry
3130
- * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3134
+ * @param {function((Error | null)=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3131
3135
  * @returns {void}
3132
3136
  */
3133
3137
  _resolveContextTimestamp(entry, callback) {
@@ -3235,7 +3239,7 @@ class FileSystemInfo {
3235
3239
 
3236
3240
  /**
3237
3241
  * @param {ContextHash} entry context hash
3238
- * @param {function(Error=, string=): void} callback callback
3242
+ * @param {function((Error | null)=, string=): void} callback callback
3239
3243
  * @returns {void}
3240
3244
  */
3241
3245
  _resolveContextHash(entry, callback) {
@@ -3391,7 +3395,7 @@ class FileSystemInfo {
3391
3395
 
3392
3396
  /**
3393
3397
  * @param {ContextTimestampAndHash} entry entry
3394
- * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
3398
+ * @param {function((Error | null)=, ResolvedContextTimestampAndHash=): void} callback callback
3395
3399
  * @returns {void}
3396
3400
  */
3397
3401
  _resolveContextTsh(entry, callback) {
@@ -3471,8 +3475,8 @@ class FileSystemInfo {
3471
3475
  }
3472
3476
  if (!elements.has(path)) {
3473
3477
  // file or directory doesn't exist
3474
- this._managedItems.set(path, "missing");
3475
- return callback(null, "missing");
3478
+ this._managedItems.set(path, "*missing");
3479
+ return callback(null, "*missing");
3476
3480
  }
3477
3481
  // something exists
3478
3482
  // it may be a file or directory
@@ -3481,8 +3485,8 @@ class FileSystemInfo {
3481
3485
  (path.endsWith("/node_modules") || path.endsWith("\\node_modules"))
3482
3486
  ) {
3483
3487
  // we are only interested in existence of this special directory
3484
- this._managedItems.set(path, "exists");
3485
- return callback(null, "exists");
3488
+ this._managedItems.set(path, "*node_modules");
3489
+ return callback(null, "*node_modules");
3486
3490
  }
3487
3491
 
3488
3492
  // we assume it's a directory, as files shouldn't occur in managed paths
@@ -3499,8 +3503,8 @@ class FileSystemInfo {
3499
3503
  ) {
3500
3504
  // This is only a grouping folder e. g. used by yarn
3501
3505
  // we are only interested in existence of this special directory
3502
- this._managedItems.set(path, "nested");
3503
- return callback(null, "nested");
3506
+ this._managedItems.set(path, "*nested");
3507
+ return callback(null, "*nested");
3504
3508
  }
3505
3509
  this.logger.warn(
3506
3510
  `Managed item ${path} isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)`
@@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError;
51
51
 
52
52
  /**
53
53
  * @template T
54
- * @param {function(WebpackError=, T=): void} callback webpack error callback
54
+ * @param {function((WebpackError | null)=, T=): void} callback webpack error callback
55
55
  * @param {string} hook name of hook
56
56
  * @returns {Callback<T>} generic callback
57
57
  */
package/lib/Module.js CHANGED
@@ -400,7 +400,6 @@ class Module extends DependenciesBlock {
400
400
  // BACKWARD-COMPAT END
401
401
 
402
402
  /**
403
- * @deprecated moved to .buildInfo.exportsArgument
404
403
  * @returns {string} name of the exports argument
405
404
  */
406
405
  get exportsArgument() {
@@ -408,7 +407,6 @@ class Module extends DependenciesBlock {
408
407
  }
409
408
 
410
409
  /**
411
- * @deprecated moved to .buildInfo.moduleArgument
412
410
  * @returns {string} name of the module argument
413
411
  */
414
412
  get moduleArgument() {
@@ -691,7 +689,7 @@ class Module extends DependenciesBlock {
691
689
 
692
690
  /**
693
691
  * @param {NeedBuildContext} context context info
694
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
692
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
695
693
  * @returns {void}
696
694
  */
697
695
  needBuild(context, callback) {
@@ -27,7 +27,7 @@ const ArrayQueue = require("./util/ArrayQueue");
27
27
  /**
28
28
  * @template T
29
29
  * @callback Callback
30
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
31
31
  * @param {T=} result
32
32
  */
33
33
 
@@ -13,7 +13,7 @@ const asyncLib = require("neo-async");
13
13
  /**
14
14
  * @template T
15
15
  * @callback Callback
16
- * @param {Error=} err
16
+ * @param {(Error | null)=} err
17
17
  * @param {T=} result
18
18
  */
19
19
 
@@ -310,7 +310,7 @@ class NormalModule extends Module {
310
310
  }
311
311
 
312
312
  // Info from Build
313
- /** @type {WebpackError=} */
313
+ /** @type {(WebpackError | null)=} */
314
314
  this.error = null;
315
315
  /** @private @type {Source=} */
316
316
  this._source = null;
@@ -355,11 +355,13 @@ class NormalModule extends Module {
355
355
  * @returns {string | null} an identifier for library inclusion
356
356
  */
357
357
  libIdent(options) {
358
- return contextify(
358
+ let ident = contextify(
359
359
  options.context,
360
360
  this.userRequest,
361
361
  options.associatedObjectForCache
362
362
  );
363
+ if (this.layer) ident = `(${this.layer})/${ident}`;
364
+ return ident;
363
365
  }
364
366
 
365
367
  /**
@@ -730,7 +732,7 @@ class NormalModule extends Module {
730
732
  * @param {ResolverWithOptions} resolver the resolver
731
733
  * @param {InputFileSystem} fs the file system
732
734
  * @param {NormalModuleCompilationHooks} hooks the hooks
733
- * @param {function(WebpackError=): void} callback callback function
735
+ * @param {function((WebpackError | null)=): void} callback callback function
734
736
  * @returns {void}
735
737
  */
736
738
  _doBuild(options, compilation, resolver, fs, hooks, callback) {
@@ -1236,7 +1238,7 @@ class NormalModule extends Module {
1236
1238
 
1237
1239
  /**
1238
1240
  * @param {NeedBuildContext} context context info
1239
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1241
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1240
1242
  * @returns {void}
1241
1243
  */
1242
1244
  needBuild(context, callback) {
@@ -28,7 +28,10 @@ const LazySet = require("./util/LazySet");
28
28
  const { getScheme } = require("./util/URLAbsoluteSpecifier");
29
29
  const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge");
30
30
  const { join } = require("./util/fs");
31
- const { parseResource } = require("./util/identifier");
31
+ const {
32
+ parseResource,
33
+ parseResourceWithoutFragment
34
+ } = require("./util/identifier");
32
35
 
33
36
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
34
37
  /** @typedef {import("./Generator")} Generator */
@@ -66,6 +69,11 @@ const { parseResource } = require("./util/identifier");
66
69
 
67
70
  /** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
68
71
 
72
+ /** @typedef {Object} ParsedLoaderRequest
73
+ * @property {string} loader loader
74
+ * @property {string|undefined} options options
75
+ */
76
+
69
77
  const EMPTY_RESOLVE_OPTIONS = {};
70
78
  const EMPTY_PARSER_OPTIONS = {};
71
79
  const EMPTY_GENERATOR_OPTIONS = {};
@@ -97,27 +105,6 @@ const stringifyLoadersAndResource = (loaders, resource) => {
97
105
  return str + resource;
98
106
  };
99
107
 
100
- /**
101
- * @param {string} resultString resultString
102
- * @returns {{loader: string, options: string|undefined}} parsed loader request
103
- */
104
- const identToLoaderRequest = resultString => {
105
- const idx = resultString.indexOf("?");
106
- if (idx >= 0) {
107
- const loader = resultString.substr(0, idx);
108
- const options = resultString.substr(idx + 1);
109
- return {
110
- loader,
111
- options
112
- };
113
- } else {
114
- return {
115
- loader: resultString,
116
- options: undefined
117
- };
118
- }
119
- };
120
-
121
108
  const needCalls = (times, callback) => {
122
109
  return err => {
123
110
  if (--times === 0) {
@@ -264,6 +251,9 @@ class NormalModuleFactory extends ModuleFactory {
264
251
  const cacheParseResource = parseResource.bindCache(
265
252
  associatedObjectForCache
266
253
  );
254
+ const cachedParseResourceWithoutFragment =
255
+ parseResourceWithoutFragment.bindCache(associatedObjectForCache);
256
+ this._parseResourceWithoutFragment = cachedParseResourceWithoutFragment;
267
257
 
268
258
  this.hooks.factorize.tapAsync(
269
259
  {
@@ -351,7 +341,7 @@ class NormalModuleFactory extends ModuleFactory {
351
341
  let matchResourceData = undefined;
352
342
  /** @type {string} */
353
343
  let unresolvedResource;
354
- /** @type {{loader: string, options: string|undefined}[]} */
344
+ /** @type {ParsedLoaderRequest[]} */
355
345
  let elements;
356
346
  let noPreAutoLoaders = false;
357
347
  let noAutoLoaders = false;
@@ -405,7 +395,13 @@ class NormalModuleFactory extends ModuleFactory {
405
395
  )
406
396
  .split(/!+/);
407
397
  unresolvedResource = rawElements.pop();
408
- elements = rawElements.map(identToLoaderRequest);
398
+ elements = rawElements.map(el => {
399
+ const { path, query } = cachedParseResourceWithoutFragment(el);
400
+ return {
401
+ loader: path,
402
+ options: query ? query.slice(1) : undefined
403
+ };
404
+ });
409
405
  scheme = getScheme(unresolvedResource);
410
406
  } else {
411
407
  unresolvedResource = requestWithoutMatchResource;
@@ -1017,12 +1013,14 @@ If changing the source code is not an option there is also a resolve options cal
1017
1013
  }
1018
1014
  if (err) return callback(err);
1019
1015
 
1020
- const parsedResult = identToLoaderRequest(result);
1016
+ const parsedResult = this._parseResourceWithoutFragment(result);
1021
1017
  const resolved = {
1022
- loader: parsedResult.loader,
1018
+ loader: parsedResult.path,
1023
1019
  options:
1024
1020
  item.options === undefined
1025
- ? parsedResult.options
1021
+ ? parsedResult.query
1022
+ ? parsedResult.query.slice(1)
1023
+ : undefined
1026
1024
  : item.options,
1027
1025
  ident: item.options === undefined ? undefined : item.ident
1028
1026
  };
@@ -96,7 +96,7 @@ const createDefaultHandler = (profile, logger) => {
96
96
  /**
97
97
  * @callback ReportProgress
98
98
  * @param {number} p
99
- * @param {...string[]} [args]
99
+ * @param {...string} [args]
100
100
  * @returns {void}
101
101
  */
102
102
 
package/lib/RawModule.js CHANGED
@@ -74,7 +74,7 @@ class RawModule extends Module {
74
74
 
75
75
  /**
76
76
  * @param {NeedBuildContext} context context info
77
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
77
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
78
78
  * @returns {void}
79
79
  */
80
80
  needBuild(context, callback) {
@@ -168,6 +168,13 @@ exports.scriptNonce = "__webpack_require__.nc";
168
168
  */
169
169
  exports.loadScript = "__webpack_require__.l";
170
170
 
171
+ /**
172
+ * function to promote a string to a TrustedScript using webpack's Trusted
173
+ * Types policy
174
+ * Arguments: (script: string) => TrustedScript
175
+ */
176
+ exports.createScript = "__webpack_require__.ts";
177
+
171
178
  /**
172
179
  * function to promote a string to a TrustedScriptURL using webpack's Trusted
173
180
  * Types policy
@@ -175,6 +182,12 @@ exports.loadScript = "__webpack_require__.l";
175
182
  */
176
183
  exports.createScriptUrl = "__webpack_require__.tu";
177
184
 
185
+ /**
186
+ * function to return webpack's Trusted Types policy
187
+ * Arguments: () => TrustedTypePolicy
188
+ */
189
+ exports.getTrustedTypesPolicy = "__webpack_require__.tt";
190
+
178
191
  /**
179
192
  * the chunk name of the chunk with the runtime
180
193
  */
@@ -195,6 +208,11 @@ exports.getChunkScriptFilename = "__webpack_require__.u";
195
208
  */
196
209
  exports.getChunkCssFilename = "__webpack_require__.k";
197
210
 
211
+ /**
212
+ * a flag when a module/chunk/tree has css modules
213
+ */
214
+ exports.hasCssModules = "has css modules";
215
+
198
216
  /**
199
217
  * the filename of the script part of the hot update chunk
200
218
  */
@@ -78,7 +78,7 @@ class RuntimeModule extends Module {
78
78
 
79
79
  /**
80
80
  * @param {NeedBuildContext} context context info
81
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
81
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
82
82
  * @returns {void}
83
83
  */
84
84
  needBuild(context, callback) {
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const RuntimeGlobals = require("./RuntimeGlobals");
9
+ const { getChunkFilenameTemplate } = require("./css/CssModulesPlugin");
9
10
  const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency");
10
11
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
11
12
  const AsyncModuleRuntimeModule = require("./runtime/AsyncModuleRuntimeModule");
@@ -13,11 +14,13 @@ const AutoPublicPathRuntimeModule = require("./runtime/AutoPublicPathRuntimeModu
13
14
  const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
14
15
  const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
15
16
  const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
17
+ const CreateScriptRuntimeModule = require("./runtime/CreateScriptRuntimeModule");
16
18
  const CreateScriptUrlRuntimeModule = require("./runtime/CreateScriptUrlRuntimeModule");
17
19
  const DefinePropertyGettersRuntimeModule = require("./runtime/DefinePropertyGettersRuntimeModule");
18
20
  const EnsureChunkRuntimeModule = require("./runtime/EnsureChunkRuntimeModule");
19
21
  const GetChunkFilenameRuntimeModule = require("./runtime/GetChunkFilenameRuntimeModule");
20
22
  const GetMainFilenameRuntimeModule = require("./runtime/GetMainFilenameRuntimeModule");
23
+ const GetTrustedTypesPolicyRuntimeModule = require("./runtime/GetTrustedTypesPolicyRuntimeModule");
21
24
  const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule");
22
25
  const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModule");
23
26
  const LoadScriptRuntimeModule = require("./runtime/LoadScriptRuntimeModule");
@@ -39,7 +42,9 @@ const GLOBALS_ON_REQUIRE = [
39
42
  RuntimeGlobals.runtimeId,
40
43
  RuntimeGlobals.compatGetDefaultExport,
41
44
  RuntimeGlobals.createFakeNamespaceObject,
45
+ RuntimeGlobals.createScript,
42
46
  RuntimeGlobals.createScriptUrl,
47
+ RuntimeGlobals.getTrustedTypesPolicy,
43
48
  RuntimeGlobals.definePropertyGetters,
44
49
  RuntimeGlobals.ensureChunk,
45
50
  RuntimeGlobals.entryModuleId,
@@ -279,9 +284,8 @@ class RuntimePlugin {
279
284
  "css",
280
285
  RuntimeGlobals.getChunkCssFilename,
281
286
  chunk =>
282
- chunk.cssFilenameTemplate ||
283
- compilation.outputOptions.cssChunkFilename,
284
- false
287
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
288
+ set.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
285
289
  )
286
290
  );
287
291
  return true;
@@ -364,15 +368,36 @@ class RuntimePlugin {
364
368
  );
365
369
  return true;
366
370
  });
371
+ compilation.hooks.runtimeRequirementInTree
372
+ .for(RuntimeGlobals.createScript)
373
+ .tap("RuntimePlugin", (chunk, set) => {
374
+ if (compilation.outputOptions.trustedTypes) {
375
+ set.add(RuntimeGlobals.getTrustedTypesPolicy);
376
+ }
377
+ compilation.addRuntimeModule(chunk, new CreateScriptRuntimeModule());
378
+ return true;
379
+ });
367
380
  compilation.hooks.runtimeRequirementInTree
368
381
  .for(RuntimeGlobals.createScriptUrl)
369
382
  .tap("RuntimePlugin", (chunk, set) => {
383
+ if (compilation.outputOptions.trustedTypes) {
384
+ set.add(RuntimeGlobals.getTrustedTypesPolicy);
385
+ }
370
386
  compilation.addRuntimeModule(
371
387
  chunk,
372
388
  new CreateScriptUrlRuntimeModule()
373
389
  );
374
390
  return true;
375
391
  });
392
+ compilation.hooks.runtimeRequirementInTree
393
+ .for(RuntimeGlobals.getTrustedTypesPolicy)
394
+ .tap("RuntimePlugin", (chunk, set) => {
395
+ compilation.addRuntimeModule(
396
+ chunk,
397
+ new GetTrustedTypesPolicyRuntimeModule(set)
398
+ );
399
+ return true;
400
+ });
376
401
  compilation.hooks.runtimeRequirementInTree
377
402
  .for(RuntimeGlobals.relativeUrl)
378
403
  .tap("RuntimePlugin", (chunk, set) => {
@@ -1031,7 +1031,7 @@ class RuntimeTemplate {
1031
1031
  const codeGen = codeGenerationResults.get(module, runtime);
1032
1032
  const { data } = codeGen;
1033
1033
  const url = data.get("url");
1034
- if (url) return url;
1034
+ if (url) return url.toString();
1035
1035
  const filename = data.get("filename");
1036
1036
  return publicPath + filename;
1037
1037
  }
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const mime = require("mime-types");
8
9
  const { basename, extname } = require("path");
9
10
  const util = require("util");
10
11
  const Chunk = require("./Chunk");
@@ -117,29 +118,53 @@ const replacePathVariables = (path, data, assetInfo) => {
117
118
  // [name] - file
118
119
  // [ext] - .js
119
120
  if (typeof data.filename === "string") {
120
- const { path: file, query, fragment } = parseResource(data.filename);
121
-
122
- const ext = extname(file);
123
- const base = basename(file);
124
- const name = base.slice(0, base.length - ext.length);
125
- const path = file.slice(0, file.length - base.length);
126
-
127
- replacements.set("file", replacer(file));
128
- replacements.set("query", replacer(query, true));
129
- replacements.set("fragment", replacer(fragment, true));
130
- replacements.set("path", replacer(path, true));
131
- replacements.set("base", replacer(base));
132
- replacements.set("name", replacer(name));
133
- replacements.set("ext", replacer(ext, true));
134
- // Legacy
135
- replacements.set(
136
- "filebase",
137
- deprecated(
138
- replacer(base),
139
- "[filebase] is now [base]",
140
- "DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
141
- )
142
- );
121
+ // check that filename is data uri
122
+ let match = data.filename.match(/^data:([^;,]+)/);
123
+ if (match) {
124
+ const ext = mime.extension(match[1]);
125
+ const emptyReplacer = replacer("", true);
126
+
127
+ replacements.set("file", emptyReplacer);
128
+ replacements.set("query", emptyReplacer);
129
+ replacements.set("fragment", emptyReplacer);
130
+ replacements.set("path", emptyReplacer);
131
+ replacements.set("base", emptyReplacer);
132
+ replacements.set("name", emptyReplacer);
133
+ replacements.set("ext", replacer(ext ? `.${ext}` : "", true));
134
+ // Legacy
135
+ replacements.set(
136
+ "filebase",
137
+ deprecated(
138
+ emptyReplacer,
139
+ "[filebase] is now [base]",
140
+ "DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
141
+ )
142
+ );
143
+ } else {
144
+ const { path: file, query, fragment } = parseResource(data.filename);
145
+
146
+ const ext = extname(file);
147
+ const base = basename(file);
148
+ const name = base.slice(0, base.length - ext.length);
149
+ const path = file.slice(0, file.length - base.length);
150
+
151
+ replacements.set("file", replacer(file));
152
+ replacements.set("query", replacer(query, true));
153
+ replacements.set("fragment", replacer(fragment, true));
154
+ replacements.set("path", replacer(path, true));
155
+ replacements.set("base", replacer(base));
156
+ replacements.set("name", replacer(name));
157
+ replacements.set("ext", replacer(ext, true));
158
+ // Legacy
159
+ replacements.set(
160
+ "filebase",
161
+ deprecated(
162
+ replacer(base),
163
+ "[filebase] is now [base]",
164
+ "DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
165
+ )
166
+ );
167
+ }
143
168
  }
144
169
 
145
170
  // Compilation context
package/lib/Watching.js CHANGED
@@ -15,7 +15,7 @@ const Stats = require("./Stats");
15
15
  /**
16
16
  * @template T
17
17
  * @callback Callback
18
- * @param {Error=} err
18
+ * @param {(Error | null)=} err
19
19
  * @param {T=} result
20
20
  */
21
21
 
@@ -291,7 +291,7 @@ class WebpackOptionsApply extends OptionsApply {
291
291
 
292
292
  if (options.experiments.css) {
293
293
  const CssModulesPlugin = require("./css/CssModulesPlugin");
294
- new CssModulesPlugin().apply(compiler);
294
+ new CssModulesPlugin(options.experiments.css).apply(compiler);
295
295
  }
296
296
 
297
297
  if (options.experiments.lazyCompilation) {