webpack 5.51.1 → 5.53.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/bin/webpack.js +0 -0
- package/lib/ChunkGraph.js +75 -1
- package/lib/Compilation.js +7 -0
- package/lib/Compiler.js +7 -0
- package/lib/ExternalModule.js +25 -16
- package/lib/FileSystemInfo.js +9 -12
- package/lib/HotModuleReplacementPlugin.js +14 -0
- package/lib/InitFragment.js +23 -0
- package/lib/NodeStuffInWebError.js +34 -0
- package/lib/NodeStuffPlugin.js +59 -16
- package/lib/NormalModuleFactory.js +7 -4
- package/lib/RuntimeModule.js +2 -1
- package/lib/Watching.js +8 -10
- package/lib/WebpackOptionsApply.js +1 -3
- package/lib/cache/PackFileCacheStrategy.js +181 -52
- package/lib/config/defaults.js +14 -6
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -2
- package/lib/dependencies/LoaderPlugin.js +94 -98
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/MangleExportsPlugin.js +21 -4
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -0
- package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/propertyAccess.js +54 -1
- package/lib/util/serialization.js +6 -2
- package/package.json +4 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +5 -5
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.json +4 -2
- package/types.d.ts +20 -7
package/bin/webpack.js
CHANGED
File without changes
|
package/lib/ChunkGraph.js
CHANGED
@@ -205,6 +205,8 @@ class ChunkGraphChunk {
|
|
205
205
|
this.runtimeModules = new SortableSet();
|
206
206
|
/** @type {Set<RuntimeModule> | undefined} */
|
207
207
|
this.fullHashModules = undefined;
|
208
|
+
/** @type {Set<RuntimeModule> | undefined} */
|
209
|
+
this.dependentHashModules = undefined;
|
208
210
|
/** @type {Set<string> | undefined} */
|
209
211
|
this.runtimeRequirements = undefined;
|
210
212
|
/** @type {Set<string>} */
|
@@ -389,6 +391,20 @@ class ChunkGraph {
|
|
389
391
|
}
|
390
392
|
}
|
391
393
|
|
394
|
+
/**
|
395
|
+
* @param {Chunk} chunk the chunk
|
396
|
+
* @param {Iterable<RuntimeModule>} modules the modules that require a full hash
|
397
|
+
* @returns {void}
|
398
|
+
*/
|
399
|
+
attachDependentHashModules(chunk, modules) {
|
400
|
+
const cgc = this._getChunkGraphChunk(chunk);
|
401
|
+
if (cgc.dependentHashModules === undefined)
|
402
|
+
cgc.dependentHashModules = new Set();
|
403
|
+
for (const module of modules) {
|
404
|
+
cgc.dependentHashModules.add(module);
|
405
|
+
}
|
406
|
+
}
|
407
|
+
|
392
408
|
/**
|
393
409
|
* @param {Module} oldModule the replaced module
|
394
410
|
* @param {Module} newModule the replacing module
|
@@ -444,6 +460,17 @@ class ChunkGraph {
|
|
444
460
|
cgc.fullHashModules.delete(/** @type {RuntimeModule} */ (oldModule));
|
445
461
|
cgc.fullHashModules.add(/** @type {RuntimeModule} */ (newModule));
|
446
462
|
}
|
463
|
+
if (
|
464
|
+
cgc.dependentHashModules !== undefined &&
|
465
|
+
cgc.dependentHashModules.has(/** @type {RuntimeModule} */ (oldModule))
|
466
|
+
) {
|
467
|
+
cgc.dependentHashModules.delete(
|
468
|
+
/** @type {RuntimeModule} */ (oldModule)
|
469
|
+
);
|
470
|
+
cgc.dependentHashModules.add(
|
471
|
+
/** @type {RuntimeModule} */ (newModule)
|
472
|
+
);
|
473
|
+
}
|
447
474
|
}
|
448
475
|
oldCgm.runtimeInChunks = undefined;
|
449
476
|
}
|
@@ -529,13 +556,22 @@ class ChunkGraph {
|
|
529
556
|
|
530
557
|
/**
|
531
558
|
* @param {Chunk} chunk the chunk
|
532
|
-
* @returns {number} the number of
|
559
|
+
* @returns {number} the number of modules which are contained in this chunk
|
533
560
|
*/
|
534
561
|
getNumberOfChunkModules(chunk) {
|
535
562
|
const cgc = this._getChunkGraphChunk(chunk);
|
536
563
|
return cgc.modules.size;
|
537
564
|
}
|
538
565
|
|
566
|
+
/**
|
567
|
+
* @param {Chunk} chunk the chunk
|
568
|
+
* @returns {number} the number of full hash modules which are contained in this chunk
|
569
|
+
*/
|
570
|
+
getNumberOfChunkFullHashModules(chunk) {
|
571
|
+
const cgc = this._getChunkGraphChunk(chunk);
|
572
|
+
return cgc.fullHashModules === undefined ? 0 : cgc.fullHashModules.size;
|
573
|
+
}
|
574
|
+
|
539
575
|
/**
|
540
576
|
* @param {Chunk} chunk the chunk
|
541
577
|
* @returns {Iterable<Module>} return the modules for this chunk
|
@@ -900,6 +936,23 @@ class ChunkGraph {
|
|
900
936
|
ChunkGraph.clearChunkGraphForChunk(chunkB);
|
901
937
|
}
|
902
938
|
|
939
|
+
/**
|
940
|
+
* @param {Chunk} chunk the chunk to upgrade
|
941
|
+
* @returns {void}
|
942
|
+
*/
|
943
|
+
upgradeDependentToFullHashModules(chunk) {
|
944
|
+
const cgc = this._getChunkGraphChunk(chunk);
|
945
|
+
if (cgc.dependentHashModules === undefined) return;
|
946
|
+
if (cgc.fullHashModules === undefined) {
|
947
|
+
cgc.fullHashModules = cgc.dependentHashModules;
|
948
|
+
} else {
|
949
|
+
for (const m of cgc.dependentHashModules) {
|
950
|
+
cgc.fullHashModules.add(m);
|
951
|
+
}
|
952
|
+
cgc.dependentHashModules = undefined;
|
953
|
+
}
|
954
|
+
}
|
955
|
+
|
903
956
|
/**
|
904
957
|
* @param {Module} module the checked module
|
905
958
|
* @param {Chunk} chunk the checked chunk
|
@@ -952,6 +1005,18 @@ class ChunkGraph {
|
|
952
1005
|
cgc.fullHashModules.add(module);
|
953
1006
|
}
|
954
1007
|
|
1008
|
+
/**
|
1009
|
+
* @param {Chunk} chunk the new chunk
|
1010
|
+
* @param {RuntimeModule} module the module that require a full hash
|
1011
|
+
* @returns {void}
|
1012
|
+
*/
|
1013
|
+
addDependentHashModuleToChunk(chunk, module) {
|
1014
|
+
const cgc = this._getChunkGraphChunk(chunk);
|
1015
|
+
if (cgc.dependentHashModules === undefined)
|
1016
|
+
cgc.dependentHashModules = new Set();
|
1017
|
+
cgc.dependentHashModules.add(module);
|
1018
|
+
}
|
1019
|
+
|
955
1020
|
/**
|
956
1021
|
* @param {Chunk} chunk the new chunk
|
957
1022
|
* @param {Module} module the entry module
|
@@ -1128,6 +1193,15 @@ class ChunkGraph {
|
|
1128
1193
|
return cgc.fullHashModules;
|
1129
1194
|
}
|
1130
1195
|
|
1196
|
+
/**
|
1197
|
+
* @param {Chunk} chunk the chunk
|
1198
|
+
* @returns {Iterable<RuntimeModule> | undefined} iterable of modules (do not modify)
|
1199
|
+
*/
|
1200
|
+
getChunkDependentHashModulesIterable(chunk) {
|
1201
|
+
const cgc = this._getChunkGraphChunk(chunk);
|
1202
|
+
return cgc.dependentHashModules;
|
1203
|
+
}
|
1204
|
+
|
1131
1205
|
/** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
|
1132
1206
|
|
1133
1207
|
/**
|
package/lib/Compilation.js
CHANGED
@@ -2879,6 +2879,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2879
2879
|
chunkGraph.connectChunkAndRuntimeModule(chunk, module);
|
2880
2880
|
if (module.fullHash) {
|
2881
2881
|
chunkGraph.addFullHashModuleToChunk(chunk, module);
|
2882
|
+
} else if (module.dependentHash) {
|
2883
|
+
chunkGraph.addDependentHashModuleToChunk(chunk, module);
|
2882
2884
|
}
|
2883
2885
|
|
2884
2886
|
// attach runtime module
|
@@ -3344,8 +3346,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3344
3346
|
if (remaining > 0) {
|
3345
3347
|
const readyChunks = [];
|
3346
3348
|
for (const chunk of runtimeChunks) {
|
3349
|
+
const hasFullHashModules =
|
3350
|
+
chunkGraph.getNumberOfChunkFullHashModules(chunk) !== 0;
|
3347
3351
|
const info = runtimeChunksMap.get(chunk);
|
3348
3352
|
for (const otherInfo of info.referencedBy) {
|
3353
|
+
if (hasFullHashModules) {
|
3354
|
+
chunkGraph.upgradeDependentToFullHashModules(otherInfo.chunk);
|
3355
|
+
}
|
3349
3356
|
remaining--;
|
3350
3357
|
if (--otherInfo.remaining === 0) {
|
3351
3358
|
readyChunks.push(otherInfo.chunk);
|
package/lib/Compiler.js
CHANGED
@@ -1130,6 +1130,13 @@ ${other}`);
|
|
1130
1130
|
* @returns {void}
|
1131
1131
|
*/
|
1132
1132
|
close(callback) {
|
1133
|
+
if (this.watching) {
|
1134
|
+
// When there is still an active watching, close this first
|
1135
|
+
this.watching.close(err => {
|
1136
|
+
this.close(callback);
|
1137
|
+
});
|
1138
|
+
return;
|
1139
|
+
}
|
1133
1140
|
this.hooks.shutdown.callAsync(err => {
|
1134
1141
|
if (err) return callback(err);
|
1135
1142
|
// Get rid of reference to last compilation to avoid leaking memory
|
package/lib/ExternalModule.js
CHANGED
@@ -13,6 +13,7 @@ const Module = require("./Module");
|
|
13
13
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
14
14
|
const Template = require("./Template");
|
15
15
|
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
|
16
|
+
const createHash = require("./util/createHash");
|
16
17
|
const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
|
17
18
|
const makeSerializable = require("./util/makeSerializable");
|
18
19
|
const propertyAccess = require("./util/propertyAccess");
|
@@ -159,18 +160,25 @@ const getSourceForImportExternal = (moduleAndSpecifiers, runtimeTemplate) => {
|
|
159
160
|
};
|
160
161
|
|
161
162
|
class ModuleExternalInitFragment extends InitFragment {
|
162
|
-
constructor(
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
constructor(request, ident) {
|
164
|
+
if (ident === undefined) {
|
165
|
+
ident = Template.toIdentifier(request);
|
166
|
+
if (ident !== request) {
|
167
|
+
ident += `_${createHash("md4")
|
168
|
+
.update(request)
|
169
|
+
.digest("hex")
|
170
|
+
.slice(0, 8)}`;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
166
174
|
super(
|
167
175
|
`import * as ${identifier} from ${JSON.stringify(request)};\n`,
|
168
176
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
169
177
|
0,
|
170
|
-
`external module import ${
|
178
|
+
`external module import ${ident}`
|
171
179
|
);
|
180
|
+
this._ident = ident;
|
172
181
|
this._identifier = identifier;
|
173
|
-
this._id = id;
|
174
182
|
this._request = request;
|
175
183
|
}
|
176
184
|
|
@@ -185,8 +193,8 @@ register(
|
|
185
193
|
"ModuleExternalInitFragment",
|
186
194
|
{
|
187
195
|
serialize(obj, { write }) {
|
188
|
-
write(obj._id);
|
189
196
|
write(obj._request);
|
197
|
+
write(obj._ident);
|
190
198
|
},
|
191
199
|
deserialize({ read }) {
|
192
200
|
return new ModuleExternalInitFragment(read(), read());
|
@@ -236,10 +244,7 @@ const getSourceForModuleExternal = (
|
|
236
244
|
) => {
|
237
245
|
if (!Array.isArray(moduleAndSpecifiers))
|
238
246
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
239
|
-
const initFragment = new ModuleExternalInitFragment(
|
240
|
-
id,
|
241
|
-
moduleAndSpecifiers[0]
|
242
|
-
);
|
247
|
+
const initFragment = new ModuleExternalInitFragment(moduleAndSpecifiers[0]);
|
243
248
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
244
249
|
moduleAndSpecifiers,
|
245
250
|
1
|
@@ -400,7 +405,7 @@ class ExternalModule extends Module {
|
|
400
405
|
* @returns {string} a unique identifier of the module
|
401
406
|
*/
|
402
407
|
identifier() {
|
403
|
-
return
|
408
|
+
return `external ${this.externalType} ${JSON.stringify(this.request)}`;
|
404
409
|
}
|
405
410
|
|
406
411
|
/**
|
@@ -531,18 +536,20 @@ class ExternalModule extends Module {
|
|
531
536
|
case "umd":
|
532
537
|
case "umd2":
|
533
538
|
case "system":
|
534
|
-
case "jsonp":
|
539
|
+
case "jsonp": {
|
540
|
+
const id = chunkGraph.getModuleId(this);
|
535
541
|
return getSourceForAmdOrUmdExternal(
|
536
|
-
|
542
|
+
id !== null ? id : this.identifier(),
|
537
543
|
this.isOptional(moduleGraph),
|
538
544
|
request,
|
539
545
|
runtimeTemplate
|
540
546
|
);
|
547
|
+
}
|
541
548
|
case "import":
|
542
549
|
return getSourceForImportExternal(request, runtimeTemplate);
|
543
550
|
case "script":
|
544
551
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
545
|
-
case "module":
|
552
|
+
case "module": {
|
546
553
|
if (!this.buildInfo.module) {
|
547
554
|
if (!runtimeTemplate.supportsDynamicImport()) {
|
548
555
|
throw new Error(
|
@@ -559,12 +566,14 @@ class ExternalModule extends Module {
|
|
559
566
|
"The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
|
560
567
|
);
|
561
568
|
}
|
569
|
+
const id = chunkGraph.getModuleId(this);
|
562
570
|
return getSourceForModuleExternal(
|
563
|
-
|
571
|
+
id !== null ? id : this.identifier(),
|
564
572
|
request,
|
565
573
|
moduleGraph.getExportsInfo(this),
|
566
574
|
runtime
|
567
575
|
);
|
576
|
+
}
|
568
577
|
case "var":
|
569
578
|
case "promise":
|
570
579
|
case "const":
|
package/lib/FileSystemInfo.js
CHANGED
@@ -1161,9 +1161,10 @@ class FileSystemInfo {
|
|
1161
1161
|
if (cache !== undefined) {
|
1162
1162
|
const resolved = getResolvedTimestamp(cache);
|
1163
1163
|
if (resolved !== undefined) return callback(null, resolved);
|
1164
|
-
this._resolveContextTimestamp(cache, callback);
|
1164
|
+
return this._resolveContextTimestamp(cache, callback);
|
1165
1165
|
}
|
1166
1166
|
this.contextTimestampQueue.add(path, (err, entry) => {
|
1167
|
+
if (err) return callback(err);
|
1167
1168
|
const resolved = getResolvedTimestamp(entry);
|
1168
1169
|
if (resolved !== undefined) return callback(null, resolved);
|
1169
1170
|
this._resolveContextTimestamp(entry, callback);
|
@@ -1178,9 +1179,7 @@ class FileSystemInfo {
|
|
1178
1179
|
_getUnresolvedContextTimestamp(path, callback) {
|
1179
1180
|
const cache = this._contextTimestamps.get(path);
|
1180
1181
|
if (cache !== undefined) return callback(null, cache);
|
1181
|
-
this.contextTimestampQueue.add(path,
|
1182
|
-
return callback(null, entry);
|
1183
|
-
});
|
1182
|
+
this.contextTimestampQueue.add(path, callback);
|
1184
1183
|
}
|
1185
1184
|
|
1186
1185
|
/**
|
@@ -1204,9 +1203,10 @@ class FileSystemInfo {
|
|
1204
1203
|
if (cache !== undefined) {
|
1205
1204
|
const resolved = getResolvedHash(cache);
|
1206
1205
|
if (resolved !== undefined) return callback(null, resolved);
|
1207
|
-
this._resolveContextHash(cache, callback);
|
1206
|
+
return this._resolveContextHash(cache, callback);
|
1208
1207
|
}
|
1209
1208
|
this.contextHashQueue.add(path, (err, entry) => {
|
1209
|
+
if (err) return callback(err);
|
1210
1210
|
const resolved = getResolvedHash(entry);
|
1211
1211
|
if (resolved !== undefined) return callback(null, resolved);
|
1212
1212
|
this._resolveContextHash(entry, callback);
|
@@ -1221,9 +1221,7 @@ class FileSystemInfo {
|
|
1221
1221
|
_getUnresolvedContextHash(path, callback) {
|
1222
1222
|
const cache = this._contextHashes.get(path);
|
1223
1223
|
if (cache !== undefined) return callback(null, cache);
|
1224
|
-
this.contextHashQueue.add(path,
|
1225
|
-
return callback(null, entry);
|
1226
|
-
});
|
1224
|
+
this.contextHashQueue.add(path, callback);
|
1227
1225
|
}
|
1228
1226
|
|
1229
1227
|
/**
|
@@ -1236,9 +1234,10 @@ class FileSystemInfo {
|
|
1236
1234
|
if (cache !== undefined) {
|
1237
1235
|
const resolved = getResolvedTimestamp(cache);
|
1238
1236
|
if (resolved !== undefined) return callback(null, resolved);
|
1239
|
-
this._resolveContextTsh(cache, callback);
|
1237
|
+
return this._resolveContextTsh(cache, callback);
|
1240
1238
|
}
|
1241
1239
|
this.contextTshQueue.add(path, (err, entry) => {
|
1240
|
+
if (err) return callback(err);
|
1242
1241
|
const resolved = getResolvedTimestamp(entry);
|
1243
1242
|
if (resolved !== undefined) return callback(null, resolved);
|
1244
1243
|
this._resolveContextTsh(entry, callback);
|
@@ -1253,9 +1252,7 @@ class FileSystemInfo {
|
|
1253
1252
|
_getUnresolvedContextTsh(path, callback) {
|
1254
1253
|
const cache = this._contextTshs.get(path);
|
1255
1254
|
if (cache !== undefined) return callback(null, cache);
|
1256
|
-
this.contextTshQueue.add(path,
|
1257
|
-
return callback(null, entry);
|
1258
|
-
});
|
1255
|
+
this.contextTshQueue.add(path, callback);
|
1259
1256
|
}
|
1260
1257
|
|
1261
1258
|
_createBuildDependenciesResolvers() {
|
@@ -495,6 +495,7 @@ class HotModuleReplacementPlugin {
|
|
495
495
|
let newModules;
|
496
496
|
let newRuntimeModules;
|
497
497
|
let newFullHashModules;
|
498
|
+
let newDependentHashModules;
|
498
499
|
let newRuntime;
|
499
500
|
let removedFromRuntime;
|
500
501
|
const currentChunk = find(
|
@@ -521,6 +522,13 @@ class HotModuleReplacementPlugin {
|
|
521
522
|
Array.from(fullHashModules).filter(module =>
|
522
523
|
updatedModules.has(module, currentChunk)
|
523
524
|
);
|
525
|
+
const dependentHashModules =
|
526
|
+
chunkGraph.getChunkDependentHashModulesIterable(currentChunk);
|
527
|
+
newDependentHashModules =
|
528
|
+
dependentHashModules &&
|
529
|
+
Array.from(dependentHashModules).filter(module =>
|
530
|
+
updatedModules.has(module, currentChunk)
|
531
|
+
);
|
524
532
|
removedFromRuntime = subtractRuntime(oldRuntime, newRuntime);
|
525
533
|
} else {
|
526
534
|
// chunk has completely removed
|
@@ -607,6 +615,12 @@ class HotModuleReplacementPlugin {
|
|
607
615
|
newFullHashModules
|
608
616
|
);
|
609
617
|
}
|
618
|
+
if (newDependentHashModules) {
|
619
|
+
chunkGraph.attachDependentHashModules(
|
620
|
+
hotUpdateChunk,
|
621
|
+
newDependentHashModules
|
622
|
+
);
|
623
|
+
}
|
610
624
|
const renderManifest = compilation.getRenderManifest({
|
611
625
|
chunk: hotUpdateChunk,
|
612
626
|
hash: records.hash,
|
package/lib/InitFragment.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
9
|
+
const makeSerializable = require("./util/makeSerializable");
|
9
10
|
|
10
11
|
/** @typedef {import("webpack-sources").Source} Source */
|
11
12
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
@@ -123,8 +124,30 @@ class InitFragment {
|
|
123
124
|
return source;
|
124
125
|
}
|
125
126
|
}
|
127
|
+
|
128
|
+
serialize(context) {
|
129
|
+
const { write } = context;
|
130
|
+
|
131
|
+
write(this.content);
|
132
|
+
write(this.stage);
|
133
|
+
write(this.position);
|
134
|
+
write(this.key);
|
135
|
+
write(this.endContent);
|
136
|
+
}
|
137
|
+
|
138
|
+
deserialize(context) {
|
139
|
+
const { read } = context;
|
140
|
+
|
141
|
+
this.content = read();
|
142
|
+
this.stage = read();
|
143
|
+
this.position = read();
|
144
|
+
this.key = read();
|
145
|
+
this.endContent = read();
|
146
|
+
}
|
126
147
|
}
|
127
148
|
|
149
|
+
makeSerializable(InitFragment, "webpack/lib/InitFragment");
|
150
|
+
|
128
151
|
InitFragment.prototype.merge = undefined;
|
129
152
|
|
130
153
|
InitFragment.STAGE_CONSTANTS = 10;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("./WebpackError");
|
9
|
+
const makeSerializable = require("./util/makeSerializable");
|
10
|
+
|
11
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
12
|
+
|
13
|
+
class NodeStuffInWebError extends WebpackError {
|
14
|
+
/**
|
15
|
+
* @param {DependencyLocation} loc loc
|
16
|
+
* @param {string} expression expression
|
17
|
+
* @param {string} description description
|
18
|
+
*/
|
19
|
+
constructor(loc, expression, description) {
|
20
|
+
super(
|
21
|
+
`${JSON.stringify(
|
22
|
+
expression
|
23
|
+
)} has been used, it will be undefined in next major version.
|
24
|
+
${description}`
|
25
|
+
);
|
26
|
+
|
27
|
+
this.name = "NodeStuffInWebError";
|
28
|
+
this.loc = loc;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
makeSerializable(NodeStuffInWebError, "webpack/lib/NodeStuffInWebError");
|
33
|
+
|
34
|
+
module.exports = NodeStuffInWebError;
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const NodeStuffInWebError = require("./NodeStuffInWebError");
|
8
9
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
9
10
|
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
10
11
|
const ConstDependency = require("./dependencies/ConstDependency");
|
@@ -44,7 +45,8 @@ class NodeStuffPlugin {
|
|
44
45
|
localOptions = { ...localOptions, ...parserOptions.node };
|
45
46
|
}
|
46
47
|
|
47
|
-
if (localOptions.global) {
|
48
|
+
if (localOptions.global !== false) {
|
49
|
+
const withWarning = localOptions.global === "warn";
|
48
50
|
parser.hooks.expression
|
49
51
|
.for("global")
|
50
52
|
.tap("NodeStuffPlugin", expr => {
|
@@ -55,10 +57,21 @@ class NodeStuffPlugin {
|
|
55
57
|
);
|
56
58
|
dep.loc = expr.loc;
|
57
59
|
parser.state.module.addPresentationalDependency(dep);
|
60
|
+
|
61
|
+
// TODO webpack 6 remove
|
62
|
+
if (withWarning) {
|
63
|
+
parser.state.module.addWarning(
|
64
|
+
new NodeStuffInWebError(
|
65
|
+
dep.loc,
|
66
|
+
"global",
|
67
|
+
"The global namespace object is Node.js feature and doesn't present in browser."
|
68
|
+
)
|
69
|
+
);
|
70
|
+
}
|
58
71
|
});
|
59
72
|
}
|
60
73
|
|
61
|
-
const setModuleConstant = (expressionName, fn) => {
|
74
|
+
const setModuleConstant = (expressionName, fn, warning) => {
|
62
75
|
parser.hooks.expression
|
63
76
|
.for(expressionName)
|
64
77
|
.tap("NodeStuffPlugin", expr => {
|
@@ -69,22 +82,41 @@ class NodeStuffPlugin {
|
|
69
82
|
);
|
70
83
|
dep.loc = expr.loc;
|
71
84
|
parser.state.module.addPresentationalDependency(dep);
|
85
|
+
|
86
|
+
// TODO webpack 6 remove
|
87
|
+
if (warning) {
|
88
|
+
parser.state.module.addWarning(
|
89
|
+
new NodeStuffInWebError(dep.loc, expressionName, warning)
|
90
|
+
);
|
91
|
+
}
|
92
|
+
|
72
93
|
return true;
|
73
94
|
});
|
74
95
|
};
|
75
96
|
|
76
|
-
const setConstant = (expressionName, value) =>
|
77
|
-
setModuleConstant(expressionName, () => value);
|
97
|
+
const setConstant = (expressionName, value, warning) =>
|
98
|
+
setModuleConstant(expressionName, () => value, warning);
|
78
99
|
|
79
100
|
const context = compiler.context;
|
80
101
|
if (localOptions.__filename) {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
102
|
+
switch (localOptions.__filename) {
|
103
|
+
case "mock":
|
104
|
+
setConstant("__filename", "/index.js");
|
105
|
+
break;
|
106
|
+
case "warn-mock":
|
107
|
+
setConstant(
|
108
|
+
"__filename",
|
109
|
+
"/index.js",
|
110
|
+
"The __filename is Node.js feature and doesn't present in browser."
|
111
|
+
);
|
112
|
+
break;
|
113
|
+
case true:
|
114
|
+
setModuleConstant("__filename", module =>
|
115
|
+
relative(compiler.inputFileSystem, context, module.resource)
|
116
|
+
);
|
117
|
+
break;
|
87
118
|
}
|
119
|
+
|
88
120
|
parser.hooks.evaluateIdentifier
|
89
121
|
.for("__filename")
|
90
122
|
.tap("NodeStuffPlugin", expr => {
|
@@ -94,13 +126,24 @@ class NodeStuffPlugin {
|
|
94
126
|
});
|
95
127
|
}
|
96
128
|
if (localOptions.__dirname) {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
129
|
+
switch (localOptions.__dirname) {
|
130
|
+
case "mock":
|
131
|
+
setConstant("__dirname", "/");
|
132
|
+
break;
|
133
|
+
case "warn-mock":
|
134
|
+
setConstant(
|
135
|
+
"__dirname",
|
136
|
+
"/",
|
137
|
+
"The __dirname is Node.js feature and doesn't present in browser."
|
138
|
+
);
|
139
|
+
break;
|
140
|
+
case true:
|
141
|
+
setModuleConstant("__dirname", module =>
|
142
|
+
relative(compiler.inputFileSystem, context, module.context)
|
143
|
+
);
|
144
|
+
break;
|
103
145
|
}
|
146
|
+
|
104
147
|
parser.hooks.evaluateIdentifier
|
105
148
|
.for("__dirname")
|
106
149
|
.tap("NodeStuffPlugin", expr => {
|
@@ -540,15 +540,18 @@ class NormalModuleFactory extends ModuleFactory {
|
|
540
540
|
for (const loader of preLoaders) allLoaders.push(loader);
|
541
541
|
let type = settings.type;
|
542
542
|
if (!type) {
|
543
|
-
|
544
|
-
(matchResourceData && matchResourceData.resource) ||
|
545
|
-
resourceData.resource;
|
543
|
+
let resource;
|
546
544
|
let match;
|
547
545
|
if (
|
548
|
-
|
546
|
+
matchResourceData &&
|
547
|
+
typeof (resource = matchResourceData.resource) === "string" &&
|
549
548
|
(match = /\.webpack\[([^\]]+)\]$/.exec(resource))
|
550
549
|
) {
|
551
550
|
type = match[1];
|
551
|
+
matchResourceData.resource = matchResourceData.resource.slice(
|
552
|
+
0,
|
553
|
+
-type.length - 10
|
554
|
+
);
|
552
555
|
} else {
|
553
556
|
type = "javascript/auto";
|
554
557
|
}
|
package/lib/RuntimeModule.js
CHANGED
@@ -44,6 +44,7 @@ class RuntimeModule extends Module {
|
|
44
44
|
/** @type {ChunkGraph} */
|
45
45
|
this.chunkGraph = undefined;
|
46
46
|
this.fullHash = false;
|
47
|
+
this.dependentHash = false;
|
47
48
|
/** @type {string} */
|
48
49
|
this._cachedGeneratedCode = undefined;
|
49
50
|
}
|
@@ -107,7 +108,7 @@ class RuntimeModule extends Module {
|
|
107
108
|
hash.update(this.name);
|
108
109
|
hash.update(`${this.stage}`);
|
109
110
|
try {
|
110
|
-
if (this.fullHash) {
|
111
|
+
if (this.fullHash || this.dependentHash) {
|
111
112
|
// Do not use getGeneratedCode here, because i. e. compilation hash might be not
|
112
113
|
// ready at this point. We will cache it later instead.
|
113
114
|
hash.update(this.generate());
|
package/lib/Watching.js
CHANGED
@@ -419,26 +419,24 @@ class Watching {
|
|
419
419
|
this.compiler.fileTimestamps = undefined;
|
420
420
|
this.compiler.contextTimestamps = undefined;
|
421
421
|
this.compiler.fsStartTime = undefined;
|
422
|
-
const shutdown =
|
423
|
-
this.compiler.
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
for (const cb of closeCallbacks) cb(err);
|
428
|
-
});
|
422
|
+
const shutdown = err => {
|
423
|
+
this.compiler.hooks.watchClose.call();
|
424
|
+
const closeCallbacks = this._closeCallbacks;
|
425
|
+
this._closeCallbacks = undefined;
|
426
|
+
for (const cb of closeCallbacks) cb(err);
|
429
427
|
};
|
430
428
|
if (compilation) {
|
431
429
|
const logger = compilation.getLogger("webpack.Watching");
|
432
430
|
logger.time("storeBuildDependencies");
|
433
431
|
this.compiler.cache.storeBuildDependencies(
|
434
432
|
compilation.buildDependencies,
|
435
|
-
|
433
|
+
err2 => {
|
436
434
|
logger.timeEnd("storeBuildDependencies");
|
437
|
-
shutdown();
|
435
|
+
shutdown(err || err2);
|
438
436
|
}
|
439
437
|
);
|
440
438
|
} else {
|
441
|
-
shutdown();
|
439
|
+
shutdown(err);
|
442
440
|
}
|
443
441
|
};
|
444
442
|
|
@@ -305,9 +305,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
305
305
|
new RequireJsStuffPlugin().apply(compiler);
|
306
306
|
}
|
307
307
|
new CommonJsPlugin().apply(compiler);
|
308
|
-
new LoaderPlugin({
|
309
|
-
enableExecuteModule: options.experiments.executeModule
|
310
|
-
}).apply(compiler);
|
308
|
+
new LoaderPlugin({}).apply(compiler);
|
311
309
|
if (options.node !== false) {
|
312
310
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
313
311
|
new NodeStuffPlugin(options.node).apply(compiler);
|