webpack 5.57.0 → 5.58.2

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.

@@ -206,17 +206,17 @@ class Snapshot {
206
206
  this._flags = 0;
207
207
  /** @type {number | undefined} */
208
208
  this.startTime = undefined;
209
- /** @type {Map<string, FileSystemInfoEntry> | undefined} */
209
+ /** @type {Map<string, FileSystemInfoEntry | null> | undefined} */
210
210
  this.fileTimestamps = undefined;
211
- /** @type {Map<string, string> | undefined} */
211
+ /** @type {Map<string, string | null> | undefined} */
212
212
  this.fileHashes = undefined;
213
- /** @type {Map<string, TimestampAndHash | string> | undefined} */
213
+ /** @type {Map<string, TimestampAndHash | string | null> | undefined} */
214
214
  this.fileTshs = undefined;
215
- /** @type {Map<string, ResolvedContextFileSystemInfoEntry> | undefined} */
215
+ /** @type {Map<string, ResolvedContextFileSystemInfoEntry | null> | undefined} */
216
216
  this.contextTimestamps = undefined;
217
- /** @type {Map<string, string> | undefined} */
217
+ /** @type {Map<string, string | null> | undefined} */
218
218
  this.contextHashes = undefined;
219
- /** @type {Map<string, ResolvedContextTimestampAndHash> | undefined} */
219
+ /** @type {Map<string, ResolvedContextTimestampAndHash | null> | undefined} */
220
220
  this.contextTshs = undefined;
221
221
  /** @type {Map<string, boolean> | undefined} */
222
222
  this.missingExistence = undefined;
@@ -823,11 +823,10 @@ const getManagedItem = (managedPath, path) => {
823
823
 
824
824
  /**
825
825
  * @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
826
- * @param {T | "ignore"} entry entry
826
+ * @param {T} entry entry
827
827
  * @returns {T["resolved"] | undefined} the resolved entry
828
828
  */
829
829
  const getResolvedTimestamp = entry => {
830
- if (entry === "ignore") return undefined;
831
830
  if (entry === null) return null;
832
831
  if (entry.resolved !== undefined) return entry.resolved;
833
832
  return entry.symlinks === undefined ? entry : undefined;
@@ -1191,6 +1190,7 @@ class FileSystemInfo {
1191
1190
  getContextTimestamp(path, callback) {
1192
1191
  const cache = this._contextTimestamps.get(path);
1193
1192
  if (cache !== undefined) {
1193
+ if (cache === "ignore") return callback(null, "ignore");
1194
1194
  const resolved = getResolvedTimestamp(cache);
1195
1195
  if (resolved !== undefined) return callback(null, resolved);
1196
1196
  return this._resolveContextTimestamp(cache, callback);
@@ -1876,17 +1876,17 @@ class FileSystemInfo {
1876
1876
  * @returns {void}
1877
1877
  */
1878
1878
  createSnapshot(startTime, files, directories, missing, options, callback) {
1879
- /** @type {Map<string, FileSystemInfoEntry>} */
1879
+ /** @type {Map<string, FileSystemInfoEntry | null>} */
1880
1880
  const fileTimestamps = new Map();
1881
- /** @type {Map<string, string>} */
1881
+ /** @type {Map<string, string | null>} */
1882
1882
  const fileHashes = new Map();
1883
- /** @type {Map<string, TimestampAndHash | string>} */
1883
+ /** @type {Map<string, TimestampAndHash | string | null>} */
1884
1884
  const fileTshs = new Map();
1885
- /** @type {Map<string, FileSystemInfoEntry>} */
1885
+ /** @type {Map<string, FileSystemInfoEntry | null>} */
1886
1886
  const contextTimestamps = new Map();
1887
- /** @type {Map<string, string>} */
1887
+ /** @type {Map<string, string | null>} */
1888
1888
  const contextHashes = new Map();
1889
- /** @type {Map<string, TimestampAndHash | string>} */
1889
+ /** @type {Map<string, ResolvedContextTimestampAndHash | null>} */
1890
1890
  const contextTshs = new Map();
1891
1891
  /** @type {Map<string, boolean>} */
1892
1892
  const missingExistence = new Map();
@@ -2080,6 +2080,7 @@ class FileSystemInfo {
2080
2080
  this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
2081
2081
  for (const path of capturedDirectories) {
2082
2082
  const cache = this._contextTshs.get(path);
2083
+ /** @type {ResolvedContextTimestampAndHash} */
2083
2084
  let resolved;
2084
2085
  if (
2085
2086
  cache !== undefined &&
@@ -2088,6 +2089,11 @@ class FileSystemInfo {
2088
2089
  contextTshs.set(path, resolved);
2089
2090
  } else {
2090
2091
  jobs++;
2092
+ /**
2093
+ * @param {Error=} err error
2094
+ * @param {ResolvedContextTimestampAndHash=} entry entry
2095
+ * @returns {void}
2096
+ */
2091
2097
  const callback = (err, entry) => {
2092
2098
  if (err) {
2093
2099
  if (this.logger) {
@@ -2152,14 +2158,20 @@ class FileSystemInfo {
2152
2158
  );
2153
2159
  for (const path of capturedDirectories) {
2154
2160
  const cache = this._contextTimestamps.get(path);
2161
+ if (cache === "ignore") continue;
2155
2162
  let resolved;
2156
2163
  if (
2157
2164
  cache !== undefined &&
2158
2165
  (resolved = getResolvedTimestamp(cache)) !== undefined
2159
2166
  ) {
2160
2167
  contextTimestamps.set(path, resolved);
2161
- } else if (cache !== "ignore") {
2168
+ } else {
2162
2169
  jobs++;
2170
+ /**
2171
+ * @param {Error=} err error
2172
+ * @param {ResolvedContextFileSystemInfoEntry=} entry entry
2173
+ * @returns {void}
2174
+ */
2163
2175
  const callback = (err, entry) => {
2164
2176
  if (err) {
2165
2177
  if (this.logger) {
@@ -2572,14 +2584,14 @@ class FileSystemInfo {
2572
2584
  const cache = this._fileTimestamps.get(path);
2573
2585
  if (cache !== undefined) {
2574
2586
  if (cache === "ignore" || !checkFile(path, cache, tsh, false)) {
2575
- processFileHashSnapshot(path, tsh.hash);
2587
+ processFileHashSnapshot(path, tsh && tsh.hash);
2576
2588
  }
2577
2589
  } else {
2578
2590
  jobs++;
2579
2591
  this.fileTimestampQueue.add(path, (err, entry) => {
2580
2592
  if (err) return invalidWithError(path, err);
2581
2593
  if (!checkFile(path, entry, tsh, false)) {
2582
- processFileHashSnapshot(path, tsh.hash);
2594
+ processFileHashSnapshot(path, tsh && tsh.hash);
2583
2595
  }
2584
2596
  jobDone();
2585
2597
  });
@@ -2592,6 +2604,7 @@ class FileSystemInfo {
2592
2604
  this._statTestedEntries += contextTimestamps.size;
2593
2605
  for (const [path, ts] of contextTimestamps) {
2594
2606
  const cache = this._contextTimestamps.get(path);
2607
+ if (cache === "ignore") continue;
2595
2608
  let resolved;
2596
2609
  if (
2597
2610
  cache !== undefined &&
@@ -2601,8 +2614,13 @@ class FileSystemInfo {
2601
2614
  invalid();
2602
2615
  return;
2603
2616
  }
2604
- } else if (cache !== "ignore") {
2617
+ } else {
2605
2618
  jobs++;
2619
+ /**
2620
+ * @param {Error=} err error
2621
+ * @param {ResolvedContextFileSystemInfoEntry=} entry entry
2622
+ * @returns {void}
2623
+ */
2606
2624
  const callback = (err, entry) => {
2607
2625
  if (err) return invalidWithError(path, err);
2608
2626
  if (!checkContext(path, entry, ts)) {
@@ -2662,27 +2680,33 @@ class FileSystemInfo {
2662
2680
  processContextHashSnapshot(path, tsh);
2663
2681
  } else {
2664
2682
  const cache = this._contextTimestamps.get(path);
2683
+ if (cache === "ignore") continue;
2665
2684
  let resolved;
2666
2685
  if (
2667
2686
  cache !== undefined &&
2668
2687
  (resolved = getResolvedTimestamp(cache)) !== undefined
2669
2688
  ) {
2670
2689
  if (!checkContext(path, resolved, tsh, false)) {
2671
- processContextHashSnapshot(path, tsh.hash);
2690
+ processContextHashSnapshot(path, tsh && tsh.hash);
2672
2691
  }
2673
- } else if (cache !== "ignore") {
2692
+ } else {
2674
2693
  jobs++;
2694
+ /**
2695
+ * @param {Error=} err error
2696
+ * @param {ResolvedContextFileSystemInfoEntry=} entry entry
2697
+ * @returns {void}
2698
+ */
2675
2699
  const callback = (err, entry) => {
2676
2700
  if (err) return invalidWithError(path, err);
2677
2701
  if (!checkContext(path, entry, tsh, false)) {
2678
- processContextHashSnapshot(path, tsh.hash);
2702
+ processContextHashSnapshot(path, tsh && tsh.hash);
2679
2703
  }
2680
2704
  jobDone();
2681
2705
  };
2682
2706
  if (cache !== undefined) {
2683
- this._resolveContextTsh(cache, callback);
2707
+ this._resolveContextTimestamp(cache, callback);
2684
2708
  } else {
2685
- this.getContextTsh(path, callback);
2709
+ this.getContextTimestamp(path, callback);
2686
2710
  }
2687
2711
  }
2688
2712
  }
@@ -3032,6 +3056,11 @@ class FileSystemInfo {
3032
3056
  );
3033
3057
  }
3034
3058
 
3059
+ /**
3060
+ * @param {ContextFileSystemInfoEntry} entry entry
3061
+ * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3062
+ * @returns {void}
3063
+ */
3035
3064
  _resolveContextTimestamp(entry, callback) {
3036
3065
  const hashes = [];
3037
3066
  let safeTime = 0;
@@ -3135,6 +3164,11 @@ class FileSystemInfo {
3135
3164
  );
3136
3165
  }
3137
3166
 
3167
+ /**
3168
+ * @param {ContextHash} entry context hash
3169
+ * @param {function(Error=, string=): void} callback callback
3170
+ * @returns {void}
3171
+ */
3138
3172
  _resolveContextHash(entry, callback) {
3139
3173
  const hashes = [];
3140
3174
  processAsyncTree(
@@ -3286,6 +3320,11 @@ class FileSystemInfo {
3286
3320
  }
3287
3321
  }
3288
3322
 
3323
+ /**
3324
+ * @param {ContextTimestampAndHash} entry entry
3325
+ * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
3326
+ * @returns {void}
3327
+ */
3289
3328
  _resolveContextTsh(entry, callback) {
3290
3329
  const hashes = [];
3291
3330
  const tsHashes = [];
package/lib/Module.js CHANGED
@@ -885,6 +885,10 @@ class Module extends DependenciesBlock {
885
885
  return true;
886
886
  }
887
887
 
888
+ hasChunkCondition() {
889
+ return this.chunkCondition !== Module.prototype.chunkCondition;
890
+ }
891
+
888
892
  /**
889
893
  * Assuming this module is in the cache. Update the (cached) module with
890
894
  * the fresh module from the factory. Usually updates internal references
@@ -123,14 +123,6 @@ class ModuleGraph {
123
123
  /** @type {WeakMap<any, Object>} */
124
124
  this._metaMap = new WeakMap();
125
125
 
126
- // Caching
127
- this._cacheModuleGraphModuleKey1 = undefined;
128
- this._cacheModuleGraphModuleValue1 = undefined;
129
- this._cacheModuleGraphModuleKey2 = undefined;
130
- this._cacheModuleGraphModuleValue2 = undefined;
131
- this._cacheModuleGraphDependencyKey = undefined;
132
- this._cacheModuleGraphDependencyValue = undefined;
133
-
134
126
  /** @type {WeakTupleMap<any[], any>} */
135
127
  this._cache = undefined;
136
128
 
@@ -143,19 +135,11 @@ class ModuleGraph {
143
135
  * @returns {ModuleGraphModule} the internal module
144
136
  */
145
137
  _getModuleGraphModule(module) {
146
- if (this._cacheModuleGraphModuleKey1 === module)
147
- return this._cacheModuleGraphModuleValue1;
148
- if (this._cacheModuleGraphModuleKey2 === module)
149
- return this._cacheModuleGraphModuleValue2;
150
138
  let mgm = this._moduleMap.get(module);
151
139
  if (mgm === undefined) {
152
140
  mgm = new ModuleGraphModule();
153
141
  this._moduleMap.set(module, mgm);
154
142
  }
155
- this._cacheModuleGraphModuleKey2 = this._cacheModuleGraphModuleKey1;
156
- this._cacheModuleGraphModuleValue2 = this._cacheModuleGraphModuleValue1;
157
- this._cacheModuleGraphModuleKey1 = module;
158
- this._cacheModuleGraphModuleValue1 = mgm;
159
143
  return mgm;
160
144
  }
161
145
 
@@ -163,9 +147,11 @@ class ModuleGraph {
163
147
  * @param {Dependency} dependency the dependency
164
148
  * @param {DependenciesBlock} block parent block
165
149
  * @param {Module} module parent module
150
+ * @param {number=} indexInBlock position in block
166
151
  * @returns {void}
167
152
  */
168
- setParents(dependency, block, module) {
153
+ setParents(dependency, block, module, indexInBlock = -1) {
154
+ dependency._parentDependenciesBlockIndex = indexInBlock;
169
155
  dependency._parentDependenciesBlock = block;
170
156
  dependency._parentModule = module;
171
157
  }
@@ -186,6 +172,14 @@ class ModuleGraph {
186
172
  return dependency._parentDependenciesBlock;
187
173
  }
188
174
 
175
+ /**
176
+ * @param {Dependency} dependency the dependency
177
+ * @returns {number} index
178
+ */
179
+ getParentBlockIndex(dependency) {
180
+ return dependency._parentDependenciesBlockIndex;
181
+ }
182
+
189
183
  /**
190
184
  * @param {Module} originModule the referencing module
191
185
  * @param {Dependency} dependency the referencing dependency
@@ -37,6 +37,7 @@ const {
37
37
  keepOriginalOrder
38
38
  } = require("./util/comparators");
39
39
  const createHash = require("./util/createHash");
40
+ const { createFakeHook } = require("./util/deprecation");
40
41
  const { join } = require("./util/fs");
41
42
  const {
42
43
  contextify,
@@ -187,6 +188,7 @@ makeSerializable(
187
188
  * @property {SyncHook<[object, NormalModule]>} loader
188
189
  * @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
189
190
  * @property {HookMap<AsyncSeriesBailHook<[string, NormalModule], string | Buffer>>} readResourceForScheme
191
+ * @property {HookMap<AsyncSeriesBailHook<[object], string | Buffer>>} readResource
190
192
  * @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
191
193
  */
192
194
 
@@ -209,8 +211,28 @@ class NormalModule extends Module {
209
211
  hooks = {
210
212
  loader: new SyncHook(["loaderContext", "module"]),
211
213
  beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
212
- readResourceForScheme: new HookMap(
213
- () => new AsyncSeriesBailHook(["resource", "module"])
214
+ // TODO webpack 6 deprecate
215
+ readResourceForScheme: new HookMap(scheme => {
216
+ const hook = hooks.readResource.for(scheme);
217
+ return createFakeHook(
218
+ /** @type {AsyncSeriesBailHook<[string, NormalModule], string | Buffer>} */ ({
219
+ tap: (options, fn) =>
220
+ hook.tap(options, loaderContext =>
221
+ fn(loaderContext.resource, loaderContext._module)
222
+ ),
223
+ tapAsync: (options, fn) =>
224
+ hook.tapAsync(options, (loaderContext, callback) =>
225
+ fn(loaderContext.resource, loaderContext._module, callback)
226
+ ),
227
+ tapPromise: (options, fn) =>
228
+ hook.tapPromise(options, loaderContext =>
229
+ fn(loaderContext.resource, loaderContext._module)
230
+ )
231
+ })
232
+ );
233
+ }),
234
+ readResource: new HookMap(
235
+ () => new AsyncSeriesBailHook(["loaderContext"])
214
236
  ),
215
237
  needBuild: new AsyncSeriesBailHook(["module", "context"])
216
238
  };
@@ -786,20 +808,15 @@ class NormalModule extends Module {
786
808
  processResource: (loaderContext, resourcePath, callback) => {
787
809
  const resource = loaderContext.resource;
788
810
  const scheme = getScheme(resource);
789
- if (scheme) {
790
- hooks.readResourceForScheme
791
- .for(scheme)
792
- .callAsync(resource, this, (err, result) => {
793
- if (err) return callback(err);
794
- if (typeof result !== "string" && !result) {
795
- return callback(new UnhandledSchemeError(scheme, resource));
796
- }
797
- return callback(null, result);
798
- });
799
- } else {
800
- loaderContext.addDependency(resourcePath);
801
- fs.readFile(resourcePath, callback);
802
- }
811
+ hooks.readResource
812
+ .for(scheme)
813
+ .callAsync(loaderContext, (err, result) => {
814
+ if (err) return callback(err);
815
+ if (typeof result !== "string" && !result) {
816
+ return callback(new UnhandledSchemeError(scheme, resource));
817
+ }
818
+ return callback(null, result);
819
+ });
803
820
  }
804
821
  },
805
822
  (err, result) => {
@@ -466,49 +466,68 @@ class NormalModuleFactory extends ModuleFactory {
466
466
  : "") +
467
467
  stringifyLoadersAndResource(loaders, resourceData.resource);
468
468
 
469
- const resourceDataForRules = matchResourceData || resourceData;
470
- const result = this.ruleSet.exec({
471
- resource: resourceDataForRules.path,
472
- realResource: resourceData.path,
473
- resourceQuery: resourceDataForRules.query,
474
- resourceFragment: resourceDataForRules.fragment,
475
- scheme,
476
- assertions,
477
- mimetype: matchResourceData ? "" : resourceData.data.mimetype || "",
478
- dependency: dependencyType,
479
- descriptionData: matchResourceData
480
- ? undefined
481
- : resourceData.data.descriptionFileData,
482
- issuer: contextInfo.issuer,
483
- compiler: contextInfo.compiler,
484
- issuerLayer: contextInfo.issuerLayer || ""
485
- });
486
469
  const settings = {};
487
470
  const useLoadersPost = [];
488
471
  const useLoaders = [];
489
472
  const useLoadersPre = [];
490
- for (const r of result) {
491
- if (r.type === "use") {
492
- if (!noAutoLoaders && !noPrePostAutoLoaders) {
493
- useLoaders.push(r.value);
494
- }
495
- } else if (r.type === "use-post") {
496
- if (!noPrePostAutoLoaders) {
497
- useLoadersPost.push(r.value);
498
- }
499
- } else if (r.type === "use-pre") {
500
- if (!noPreAutoLoaders && !noPrePostAutoLoaders) {
501
- useLoadersPre.push(r.value);
473
+
474
+ // handle .webpack[] suffix
475
+ let resource;
476
+ let match;
477
+ if (
478
+ matchResourceData &&
479
+ typeof (resource = matchResourceData.resource) === "string" &&
480
+ (match = /\.webpack\[([^\]]+)\]$/.exec(resource))
481
+ ) {
482
+ settings.type = match[1];
483
+ matchResourceData.resource = matchResourceData.resource.slice(
484
+ 0,
485
+ -settings.type.length - 10
486
+ );
487
+ } else {
488
+ settings.type = "javascript/auto";
489
+ const resourceDataForRules = matchResourceData || resourceData;
490
+ const result = this.ruleSet.exec({
491
+ resource: resourceDataForRules.path,
492
+ realResource: resourceData.path,
493
+ resourceQuery: resourceDataForRules.query,
494
+ resourceFragment: resourceDataForRules.fragment,
495
+ scheme,
496
+ assertions,
497
+ mimetype: matchResourceData
498
+ ? ""
499
+ : resourceData.data.mimetype || "",
500
+ dependency: dependencyType,
501
+ descriptionData: matchResourceData
502
+ ? undefined
503
+ : resourceData.data.descriptionFileData,
504
+ issuer: contextInfo.issuer,
505
+ compiler: contextInfo.compiler,
506
+ issuerLayer: contextInfo.issuerLayer || ""
507
+ });
508
+ for (const r of result) {
509
+ if (r.type === "use") {
510
+ if (!noAutoLoaders && !noPrePostAutoLoaders) {
511
+ useLoaders.push(r.value);
512
+ }
513
+ } else if (r.type === "use-post") {
514
+ if (!noPrePostAutoLoaders) {
515
+ useLoadersPost.push(r.value);
516
+ }
517
+ } else if (r.type === "use-pre") {
518
+ if (!noPreAutoLoaders && !noPrePostAutoLoaders) {
519
+ useLoadersPre.push(r.value);
520
+ }
521
+ } else if (
522
+ typeof r.value === "object" &&
523
+ r.value !== null &&
524
+ typeof settings[r.type] === "object" &&
525
+ settings[r.type] !== null
526
+ ) {
527
+ settings[r.type] = cachedCleverMerge(settings[r.type], r.value);
528
+ } else {
529
+ settings[r.type] = r.value;
502
530
  }
503
- } else if (
504
- typeof r.value === "object" &&
505
- r.value !== null &&
506
- typeof settings[r.type] === "object" &&
507
- settings[r.type] !== null
508
- ) {
509
- settings[r.type] = cachedCleverMerge(settings[r.type], r.value);
510
- } else {
511
- settings[r.type] = r.value;
512
531
  }
513
532
  }
514
533
 
@@ -528,23 +547,6 @@ class NormalModuleFactory extends ModuleFactory {
528
547
  }
529
548
  for (const loader of preLoaders) allLoaders.push(loader);
530
549
  let type = settings.type;
531
- if (!type) {
532
- let resource;
533
- let match;
534
- if (
535
- matchResourceData &&
536
- typeof (resource = matchResourceData.resource) === "string" &&
537
- (match = /\.webpack\[([^\]]+)\]$/.exec(resource))
538
- ) {
539
- type = match[1];
540
- matchResourceData.resource = matchResourceData.resource.slice(
541
- 0,
542
- -type.length - 10
543
- );
544
- } else {
545
- type = "javascript/auto";
546
- }
547
- }
548
550
  const resolveOptions = settings.resolve;
549
551
  const layer = settings.layer;
550
552
  if (layer !== undefined && !layers) {