webpack 5.57.1 → 5.59.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.
- package/lib/AsyncDependenciesBlock.js +0 -2
- package/lib/ChunkGraph.js +0 -26
- package/lib/Compilation.js +222 -115
- package/lib/Compiler.js +2 -2
- package/lib/DefinePlugin.js +1 -1
- package/lib/DependenciesBlock.js +9 -0
- package/lib/Dependency.js +2 -0
- package/lib/FileSystemInfo.js +112 -30
- package/lib/Module.js +4 -0
- package/lib/ModuleGraph.js +11 -17
- package/lib/NormalModule.js +64 -27
- package/lib/NormalModuleFactory.js +57 -55
- package/lib/RuntimeTemplate.js +1 -1
- package/lib/WebpackOptionsApply.js +0 -2
- package/lib/buildChunkGraph.js +157 -100
- package/lib/cache/AddManagedPathsPlugin.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/config/defaults.js +65 -43
- package/lib/config/normalization.js +6 -1
- package/lib/logging/Logger.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +1 -1
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -0
- package/lib/optimize/SplitChunksPlugin.js +57 -4
- package/lib/schemes/FileUriPlugin.js +9 -0
- package/lib/schemes/HttpUriPlugin.js +107 -31
- package/lib/serialization/Serializer.js +2 -4
- package/lib/util/fs.js +2 -0
- package/lib/util/propertyAccess.js +2 -2
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +258 -55
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +28 -0
- package/types.d.ts +118 -91
package/lib/FileSystemInfo.js
CHANGED
@@ -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
|
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;
|
@@ -854,8 +853,8 @@ class FileSystemInfo {
|
|
854
853
|
/**
|
855
854
|
* @param {InputFileSystem} fs file system
|
856
855
|
* @param {Object} options options
|
857
|
-
* @param {Iterable<string>=} options.managedPaths paths that are only managed by a package manager
|
858
|
-
* @param {Iterable<string>=} options.immutablePaths paths that are immutable
|
856
|
+
* @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
|
857
|
+
* @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
|
859
858
|
* @param {Logger=} options.logger logger used to log invalid snapshots
|
860
859
|
* @param {string | Hash=} options.hashFunction the hash function to use
|
861
860
|
*/
|
@@ -997,12 +996,19 @@ class FileSystemInfo {
|
|
997
996
|
processor: this._getManagedItemDirectoryInfo.bind(this)
|
998
997
|
});
|
999
998
|
this.managedPaths = Array.from(managedPaths);
|
1000
|
-
this.managedPathsWithSlash =
|
1001
|
-
|
999
|
+
this.managedPathsWithSlash = /** @type {string[]} */ (
|
1000
|
+
this.managedPaths.filter(p => typeof p === "string")
|
1001
|
+
).map(p => join(fs, p, "_").slice(0, -1));
|
1002
|
+
|
1003
|
+
this.managedPathsRegExps = /** @type {RegExp[]} */ (
|
1004
|
+
this.managedPaths.filter(p => typeof p !== "string")
|
1002
1005
|
);
|
1003
1006
|
this.immutablePaths = Array.from(immutablePaths);
|
1004
|
-
this.immutablePathsWithSlash =
|
1005
|
-
|
1007
|
+
this.immutablePathsWithSlash = /** @type {string[]} */ (
|
1008
|
+
this.immutablePaths.filter(p => typeof p === "string")
|
1009
|
+
).map(p => join(fs, p, "_").slice(0, -1));
|
1010
|
+
this.immutablePathsRegExps = /** @type {RegExp[]} */ (
|
1011
|
+
this.immutablePaths.filter(p => typeof p !== "string")
|
1006
1012
|
);
|
1007
1013
|
|
1008
1014
|
this._cachedDeprecatedFileTimestamps = undefined;
|
@@ -1191,6 +1197,7 @@ class FileSystemInfo {
|
|
1191
1197
|
getContextTimestamp(path, callback) {
|
1192
1198
|
const cache = this._contextTimestamps.get(path);
|
1193
1199
|
if (cache !== undefined) {
|
1200
|
+
if (cache === "ignore") return callback(null, "ignore");
|
1194
1201
|
const resolved = getResolvedTimestamp(cache);
|
1195
1202
|
if (resolved !== undefined) return callback(null, resolved);
|
1196
1203
|
return this._resolveContextTimestamp(cache, callback);
|
@@ -1876,17 +1883,17 @@ class FileSystemInfo {
|
|
1876
1883
|
* @returns {void}
|
1877
1884
|
*/
|
1878
1885
|
createSnapshot(startTime, files, directories, missing, options, callback) {
|
1879
|
-
/** @type {Map<string, FileSystemInfoEntry>} */
|
1886
|
+
/** @type {Map<string, FileSystemInfoEntry | null>} */
|
1880
1887
|
const fileTimestamps = new Map();
|
1881
|
-
/** @type {Map<string, string>} */
|
1888
|
+
/** @type {Map<string, string | null>} */
|
1882
1889
|
const fileHashes = new Map();
|
1883
|
-
/** @type {Map<string, TimestampAndHash | string>} */
|
1890
|
+
/** @type {Map<string, TimestampAndHash | string | null>} */
|
1884
1891
|
const fileTshs = new Map();
|
1885
|
-
/** @type {Map<string, FileSystemInfoEntry>} */
|
1892
|
+
/** @type {Map<string, FileSystemInfoEntry | null>} */
|
1886
1893
|
const contextTimestamps = new Map();
|
1887
|
-
/** @type {Map<string, string>} */
|
1894
|
+
/** @type {Map<string, string | null>} */
|
1888
1895
|
const contextHashes = new Map();
|
1889
|
-
/** @type {Map<string,
|
1896
|
+
/** @type {Map<string, ResolvedContextTimestampAndHash | null>} */
|
1890
1897
|
const contextTshs = new Map();
|
1891
1898
|
/** @type {Map<string, boolean>} */
|
1892
1899
|
const missingExistence = new Map();
|
@@ -1966,12 +1973,29 @@ class FileSystemInfo {
|
|
1966
1973
|
}
|
1967
1974
|
};
|
1968
1975
|
const checkManaged = (path, managedSet) => {
|
1976
|
+
for (const immutablePath of this.immutablePathsRegExps) {
|
1977
|
+
if (immutablePath.test(path)) {
|
1978
|
+
managedSet.add(path);
|
1979
|
+
return true;
|
1980
|
+
}
|
1981
|
+
}
|
1969
1982
|
for (const immutablePath of this.immutablePathsWithSlash) {
|
1970
1983
|
if (path.startsWith(immutablePath)) {
|
1971
1984
|
managedSet.add(path);
|
1972
1985
|
return true;
|
1973
1986
|
}
|
1974
1987
|
}
|
1988
|
+
for (const managedPath of this.managedPathsRegExps) {
|
1989
|
+
const match = managedPath.exec(path);
|
1990
|
+
if (match) {
|
1991
|
+
const managedItem = getManagedItem(managedPath[1], path);
|
1992
|
+
if (managedItem) {
|
1993
|
+
managedItems.add(managedItem);
|
1994
|
+
managedSet.add(path);
|
1995
|
+
return true;
|
1996
|
+
}
|
1997
|
+
}
|
1998
|
+
}
|
1975
1999
|
for (const managedPath of this.managedPathsWithSlash) {
|
1976
2000
|
if (path.startsWith(managedPath)) {
|
1977
2001
|
const managedItem = getManagedItem(managedPath, path);
|
@@ -2080,6 +2104,7 @@ class FileSystemInfo {
|
|
2080
2104
|
this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
|
2081
2105
|
for (const path of capturedDirectories) {
|
2082
2106
|
const cache = this._contextTshs.get(path);
|
2107
|
+
/** @type {ResolvedContextTimestampAndHash} */
|
2083
2108
|
let resolved;
|
2084
2109
|
if (
|
2085
2110
|
cache !== undefined &&
|
@@ -2088,6 +2113,11 @@ class FileSystemInfo {
|
|
2088
2113
|
contextTshs.set(path, resolved);
|
2089
2114
|
} else {
|
2090
2115
|
jobs++;
|
2116
|
+
/**
|
2117
|
+
* @param {Error=} err error
|
2118
|
+
* @param {ResolvedContextTimestampAndHash=} entry entry
|
2119
|
+
* @returns {void}
|
2120
|
+
*/
|
2091
2121
|
const callback = (err, entry) => {
|
2092
2122
|
if (err) {
|
2093
2123
|
if (this.logger) {
|
@@ -2152,14 +2182,20 @@ class FileSystemInfo {
|
|
2152
2182
|
);
|
2153
2183
|
for (const path of capturedDirectories) {
|
2154
2184
|
const cache = this._contextTimestamps.get(path);
|
2185
|
+
if (cache === "ignore") continue;
|
2155
2186
|
let resolved;
|
2156
2187
|
if (
|
2157
2188
|
cache !== undefined &&
|
2158
2189
|
(resolved = getResolvedTimestamp(cache)) !== undefined
|
2159
2190
|
) {
|
2160
2191
|
contextTimestamps.set(path, resolved);
|
2161
|
-
} else
|
2192
|
+
} else {
|
2162
2193
|
jobs++;
|
2194
|
+
/**
|
2195
|
+
* @param {Error=} err error
|
2196
|
+
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
|
2197
|
+
* @returns {void}
|
2198
|
+
*/
|
2163
2199
|
const callback = (err, entry) => {
|
2164
2200
|
if (err) {
|
2165
2201
|
if (this.logger) {
|
@@ -2572,14 +2608,14 @@ class FileSystemInfo {
|
|
2572
2608
|
const cache = this._fileTimestamps.get(path);
|
2573
2609
|
if (cache !== undefined) {
|
2574
2610
|
if (cache === "ignore" || !checkFile(path, cache, tsh, false)) {
|
2575
|
-
processFileHashSnapshot(path, tsh.hash);
|
2611
|
+
processFileHashSnapshot(path, tsh && tsh.hash);
|
2576
2612
|
}
|
2577
2613
|
} else {
|
2578
2614
|
jobs++;
|
2579
2615
|
this.fileTimestampQueue.add(path, (err, entry) => {
|
2580
2616
|
if (err) return invalidWithError(path, err);
|
2581
2617
|
if (!checkFile(path, entry, tsh, false)) {
|
2582
|
-
processFileHashSnapshot(path, tsh.hash);
|
2618
|
+
processFileHashSnapshot(path, tsh && tsh.hash);
|
2583
2619
|
}
|
2584
2620
|
jobDone();
|
2585
2621
|
});
|
@@ -2592,6 +2628,7 @@ class FileSystemInfo {
|
|
2592
2628
|
this._statTestedEntries += contextTimestamps.size;
|
2593
2629
|
for (const [path, ts] of contextTimestamps) {
|
2594
2630
|
const cache = this._contextTimestamps.get(path);
|
2631
|
+
if (cache === "ignore") continue;
|
2595
2632
|
let resolved;
|
2596
2633
|
if (
|
2597
2634
|
cache !== undefined &&
|
@@ -2601,8 +2638,13 @@ class FileSystemInfo {
|
|
2601
2638
|
invalid();
|
2602
2639
|
return;
|
2603
2640
|
}
|
2604
|
-
} else
|
2641
|
+
} else {
|
2605
2642
|
jobs++;
|
2643
|
+
/**
|
2644
|
+
* @param {Error=} err error
|
2645
|
+
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
|
2646
|
+
* @returns {void}
|
2647
|
+
*/
|
2606
2648
|
const callback = (err, entry) => {
|
2607
2649
|
if (err) return invalidWithError(path, err);
|
2608
2650
|
if (!checkContext(path, entry, ts)) {
|
@@ -2662,27 +2704,33 @@ class FileSystemInfo {
|
|
2662
2704
|
processContextHashSnapshot(path, tsh);
|
2663
2705
|
} else {
|
2664
2706
|
const cache = this._contextTimestamps.get(path);
|
2707
|
+
if (cache === "ignore") continue;
|
2665
2708
|
let resolved;
|
2666
2709
|
if (
|
2667
2710
|
cache !== undefined &&
|
2668
2711
|
(resolved = getResolvedTimestamp(cache)) !== undefined
|
2669
2712
|
) {
|
2670
2713
|
if (!checkContext(path, resolved, tsh, false)) {
|
2671
|
-
processContextHashSnapshot(path, tsh.hash);
|
2714
|
+
processContextHashSnapshot(path, tsh && tsh.hash);
|
2672
2715
|
}
|
2673
|
-
} else
|
2716
|
+
} else {
|
2674
2717
|
jobs++;
|
2718
|
+
/**
|
2719
|
+
* @param {Error=} err error
|
2720
|
+
* @param {ResolvedContextFileSystemInfoEntry=} entry entry
|
2721
|
+
* @returns {void}
|
2722
|
+
*/
|
2675
2723
|
const callback = (err, entry) => {
|
2676
2724
|
if (err) return invalidWithError(path, err);
|
2677
2725
|
if (!checkContext(path, entry, tsh, false)) {
|
2678
|
-
processContextHashSnapshot(path, tsh.hash);
|
2726
|
+
processContextHashSnapshot(path, tsh && tsh.hash);
|
2679
2727
|
}
|
2680
2728
|
jobDone();
|
2681
2729
|
};
|
2682
2730
|
if (cache !== undefined) {
|
2683
|
-
this.
|
2731
|
+
this._resolveContextTimestamp(cache, callback);
|
2684
2732
|
} else {
|
2685
|
-
this.
|
2733
|
+
this.getContextTimestamp(path, callback);
|
2686
2734
|
}
|
2687
2735
|
}
|
2688
2736
|
}
|
@@ -2899,10 +2947,29 @@ class FileSystemInfo {
|
|
2899
2947
|
files,
|
2900
2948
|
(file, callback) => {
|
2901
2949
|
const child = join(this.fs, path, file);
|
2950
|
+
for (const immutablePath of this.immutablePathsRegExps) {
|
2951
|
+
if (immutablePath.test(path)) {
|
2952
|
+
// ignore any immutable path for timestamping
|
2953
|
+
return callback(null, fromImmutablePath(path));
|
2954
|
+
}
|
2955
|
+
}
|
2902
2956
|
for (const immutablePath of this.immutablePathsWithSlash) {
|
2903
2957
|
if (path.startsWith(immutablePath)) {
|
2904
2958
|
// ignore any immutable path for timestamping
|
2905
|
-
return callback(null, fromImmutablePath(
|
2959
|
+
return callback(null, fromImmutablePath(path));
|
2960
|
+
}
|
2961
|
+
}
|
2962
|
+
for (const managedPath of this.managedPathsRegExps) {
|
2963
|
+
const match = managedPath.exec(path);
|
2964
|
+
if (match) {
|
2965
|
+
const managedItem = getManagedItem(managedPath[1], path);
|
2966
|
+
if (managedItem) {
|
2967
|
+
// construct timestampHash from managed info
|
2968
|
+
return this.managedItemQueue.add(managedItem, (err, info) => {
|
2969
|
+
if (err) return callback(err);
|
2970
|
+
return callback(null, fromManagedItem(info));
|
2971
|
+
});
|
2972
|
+
}
|
2906
2973
|
}
|
2907
2974
|
}
|
2908
2975
|
for (const managedPath of this.managedPathsWithSlash) {
|
@@ -3032,6 +3099,11 @@ class FileSystemInfo {
|
|
3032
3099
|
);
|
3033
3100
|
}
|
3034
3101
|
|
3102
|
+
/**
|
3103
|
+
* @param {ContextFileSystemInfoEntry} entry entry
|
3104
|
+
* @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
|
3105
|
+
* @returns {void}
|
3106
|
+
*/
|
3035
3107
|
_resolveContextTimestamp(entry, callback) {
|
3036
3108
|
const hashes = [];
|
3037
3109
|
let safeTime = 0;
|
@@ -3135,6 +3207,11 @@ class FileSystemInfo {
|
|
3135
3207
|
);
|
3136
3208
|
}
|
3137
3209
|
|
3210
|
+
/**
|
3211
|
+
* @param {ContextHash} entry context hash
|
3212
|
+
* @param {function(Error=, string=): void} callback callback
|
3213
|
+
* @returns {void}
|
3214
|
+
*/
|
3138
3215
|
_resolveContextHash(entry, callback) {
|
3139
3216
|
const hashes = [];
|
3140
3217
|
processAsyncTree(
|
@@ -3286,6 +3363,11 @@ class FileSystemInfo {
|
|
3286
3363
|
}
|
3287
3364
|
}
|
3288
3365
|
|
3366
|
+
/**
|
3367
|
+
* @param {ContextTimestampAndHash} entry entry
|
3368
|
+
* @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
|
3369
|
+
* @returns {void}
|
3370
|
+
*/
|
3289
3371
|
_resolveContextTsh(entry, callback) {
|
3290
3372
|
const hashes = [];
|
3291
3373
|
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
|
package/lib/ModuleGraph.js
CHANGED
@@ -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
|
package/lib/NormalModule.js
CHANGED
@@ -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,
|
@@ -186,7 +187,10 @@ makeSerializable(
|
|
186
187
|
* @typedef {Object} NormalModuleCompilationHooks
|
187
188
|
* @property {SyncHook<[object, NormalModule]>} loader
|
188
189
|
* @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
|
190
|
+
* @property {SyncHook<[NormalModule]>} beforeParse
|
191
|
+
* @property {SyncHook<[NormalModule]>} beforeSnapshot
|
189
192
|
* @property {HookMap<AsyncSeriesBailHook<[string, NormalModule], string | Buffer>>} readResourceForScheme
|
193
|
+
* @property {HookMap<AsyncSeriesBailHook<[object], string | Buffer>>} readResource
|
190
194
|
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
|
191
195
|
*/
|
192
196
|
|
@@ -209,8 +213,30 @@ class NormalModule extends Module {
|
|
209
213
|
hooks = {
|
210
214
|
loader: new SyncHook(["loaderContext", "module"]),
|
211
215
|
beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
|
212
|
-
|
213
|
-
|
216
|
+
beforeParse: new SyncHook(["module"]),
|
217
|
+
beforeSnapshot: new SyncHook(["module"]),
|
218
|
+
// TODO webpack 6 deprecate
|
219
|
+
readResourceForScheme: new HookMap(scheme => {
|
220
|
+
const hook = hooks.readResource.for(scheme);
|
221
|
+
return createFakeHook(
|
222
|
+
/** @type {AsyncSeriesBailHook<[string, NormalModule], string | Buffer>} */ ({
|
223
|
+
tap: (options, fn) =>
|
224
|
+
hook.tap(options, loaderContext =>
|
225
|
+
fn(loaderContext.resource, loaderContext._module)
|
226
|
+
),
|
227
|
+
tapAsync: (options, fn) =>
|
228
|
+
hook.tapAsync(options, (loaderContext, callback) =>
|
229
|
+
fn(loaderContext.resource, loaderContext._module, callback)
|
230
|
+
),
|
231
|
+
tapPromise: (options, fn) =>
|
232
|
+
hook.tapPromise(options, loaderContext =>
|
233
|
+
fn(loaderContext.resource, loaderContext._module)
|
234
|
+
)
|
235
|
+
})
|
236
|
+
);
|
237
|
+
}),
|
238
|
+
readResource: new HookMap(
|
239
|
+
() => new AsyncSeriesBailHook(["loaderContext"])
|
214
240
|
),
|
215
241
|
needBuild: new AsyncSeriesBailHook(["module", "context"])
|
216
242
|
};
|
@@ -365,6 +391,7 @@ class NormalModule extends Module {
|
|
365
391
|
this.generator = m.generator;
|
366
392
|
this.generatorOptions = m.generatorOptions;
|
367
393
|
this.resource = m.resource;
|
394
|
+
this.resourceResolveData = m.resourceResolveData;
|
368
395
|
this.context = m.context;
|
369
396
|
this.matchResource = m.matchResource;
|
370
397
|
this.loaders = m.loaders;
|
@@ -466,9 +493,10 @@ class NormalModule extends Module {
|
|
466
493
|
* @param {WebpackOptions} options webpack options
|
467
494
|
* @param {Compilation} compilation the compilation
|
468
495
|
* @param {InputFileSystem} fs file system from reading
|
496
|
+
* @param {NormalModuleCompilationHooks} hooks the hooks
|
469
497
|
* @returns {NormalModuleLoaderContext} loader context
|
470
498
|
*/
|
471
|
-
|
499
|
+
_createLoaderContext(resolver, options, compilation, fs, hooks) {
|
472
500
|
const { requestShortener } = compilation.runtimeTemplate;
|
473
501
|
const getCurrentLoaderName = () => {
|
474
502
|
const currentLoader = this.getCurrentLoader(loaderContext);
|
@@ -637,10 +665,7 @@ class NormalModule extends Module {
|
|
637
665
|
|
638
666
|
Object.assign(loaderContext, options.loader);
|
639
667
|
|
640
|
-
|
641
|
-
loaderContext,
|
642
|
-
this
|
643
|
-
);
|
668
|
+
hooks.loader.call(loaderContext, this);
|
644
669
|
|
645
670
|
return loaderContext;
|
646
671
|
}
|
@@ -701,15 +726,17 @@ class NormalModule extends Module {
|
|
701
726
|
* @param {Compilation} compilation the compilation
|
702
727
|
* @param {ResolverWithOptions} resolver the resolver
|
703
728
|
* @param {InputFileSystem} fs the file system
|
729
|
+
* @param {NormalModuleCompilationHooks} hooks the hooks
|
704
730
|
* @param {function(WebpackError=): void} callback callback function
|
705
731
|
* @returns {void}
|
706
732
|
*/
|
707
|
-
|
708
|
-
const loaderContext = this.
|
733
|
+
_doBuild(options, compilation, resolver, fs, hooks, callback) {
|
734
|
+
const loaderContext = this._createLoaderContext(
|
709
735
|
resolver,
|
710
736
|
options,
|
711
737
|
compilation,
|
712
|
-
fs
|
738
|
+
fs,
|
739
|
+
hooks
|
713
740
|
);
|
714
741
|
|
715
742
|
const processResult = (err, result) => {
|
@@ -763,8 +790,6 @@ class NormalModule extends Module {
|
|
763
790
|
return callback();
|
764
791
|
};
|
765
792
|
|
766
|
-
const hooks = NormalModule.getCompilationHooks(compilation);
|
767
|
-
|
768
793
|
this.buildInfo.fileDependencies = new LazySet();
|
769
794
|
this.buildInfo.contextDependencies = new LazySet();
|
770
795
|
this.buildInfo.missingDependencies = new LazySet();
|
@@ -786,20 +811,15 @@ class NormalModule extends Module {
|
|
786
811
|
processResource: (loaderContext, resourcePath, callback) => {
|
787
812
|
const resource = loaderContext.resource;
|
788
813
|
const scheme = getScheme(resource);
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
});
|
799
|
-
} else {
|
800
|
-
loaderContext.addDependency(resourcePath);
|
801
|
-
fs.readFile(resourcePath, callback);
|
802
|
-
}
|
814
|
+
hooks.readResource
|
815
|
+
.for(scheme)
|
816
|
+
.callAsync(loaderContext, (err, result) => {
|
817
|
+
if (err) return callback(err);
|
818
|
+
if (typeof result !== "string" && !result) {
|
819
|
+
return callback(new UnhandledSchemeError(scheme, resource));
|
820
|
+
}
|
821
|
+
return callback(null, result);
|
822
|
+
});
|
803
823
|
}
|
804
824
|
},
|
805
825
|
(err, result) => {
|
@@ -925,7 +945,9 @@ class NormalModule extends Module {
|
|
925
945
|
|
926
946
|
const startTime = compilation.compiler.fsStartTime || Date.now();
|
927
947
|
|
928
|
-
|
948
|
+
const hooks = NormalModule.getCompilationHooks(compilation);
|
949
|
+
|
950
|
+
return this._doBuild(options, compilation, resolver, fs, hooks, err => {
|
929
951
|
// if we have an error mark module as failed and exit
|
930
952
|
if (err) {
|
931
953
|
this.markModuleAsErrored(err);
|
@@ -957,6 +979,13 @@ class NormalModule extends Module {
|
|
957
979
|
};
|
958
980
|
|
959
981
|
const handleBuildDone = () => {
|
982
|
+
try {
|
983
|
+
hooks.beforeSnapshot.call(this);
|
984
|
+
} catch (err) {
|
985
|
+
this.markModuleAsErrored(err);
|
986
|
+
return callback();
|
987
|
+
}
|
988
|
+
|
960
989
|
const snapshotOptions = compilation.options.snapshot.module;
|
961
990
|
if (!this.buildInfo.cacheable || !snapshotOptions) {
|
962
991
|
return callback();
|
@@ -1021,6 +1050,14 @@ class NormalModule extends Module {
|
|
1021
1050
|
);
|
1022
1051
|
};
|
1023
1052
|
|
1053
|
+
try {
|
1054
|
+
hooks.beforeParse.call(this);
|
1055
|
+
} catch (err) {
|
1056
|
+
this.markModuleAsErrored(err);
|
1057
|
+
this._initBuildHash(compilation);
|
1058
|
+
return callback();
|
1059
|
+
}
|
1060
|
+
|
1024
1061
|
// check if this module should !not! be parsed.
|
1025
1062
|
// if so, exit here;
|
1026
1063
|
const noParseRule = options.module && options.module.noParse;
|