webpack 5.50.0 → 5.52.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/README.md +4 -16
- package/lib/ChunkGraph.js +75 -1
- package/lib/Compilation.js +10 -1
- package/lib/Compiler.js +7 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExternalModule.js +25 -16
- package/lib/FileSystemInfo.js +660 -191
- package/lib/HotModuleReplacementPlugin.js +14 -0
- package/lib/InitFragment.js +23 -0
- package/lib/NormalModule.js +10 -2
- package/lib/NormalModuleFactory.js +7 -4
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +2 -1
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/Watching.js +8 -10
- package/lib/WebpackOptionsApply.js +1 -3
- package/lib/config/defaults.js +0 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -2
- package/lib/dependencies/LoaderPlugin.js +94 -98
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -1
- package/lib/library/ModuleLibraryPlugin.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -1
- package/lib/optimize/ConcatenatedModule.js +3 -3
- package/lib/optimize/MangleExportsPlugin.js +21 -4
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -0
- package/lib/util/fs.js +40 -0
- package/lib/util/identifier.js +26 -8
- package/lib/util/internalSerializables.js +1 -0
- package/lib/util/propertyAccess.js +54 -1
- package/lib/wasm-async/{AsyncWasmChunkLoadingRuntimeModule.js → AsyncWasmLoadingRuntimeModule.js} +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -2
- package/lib/web/FetchCompileWasmPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +7 -1
- package/package.json +3 -2
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +0 -4
- package/types.d.ts +62 -12
package/README.md
CHANGED
@@ -138,25 +138,13 @@ or are automatically applied via regex from your webpack configuration.
|
|
138
138
|
|
139
139
|
#### Files
|
140
140
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
145
|
-
| [url-loader][url] | ![url-npm] | ![url-size] | Works like the file loader, but can return a Data Url if the file is smaller than a limit |
|
146
|
-
| [file-loader][file] | ![file-npm] | ![file-size] | Emits the file into the output folder and returns the (relative) url |
|
147
|
-
|
148
|
-
[raw]: https://github.com/webpack-contrib/raw-loader
|
149
|
-
[raw-npm]: https://img.shields.io/npm/v/raw-loader.svg
|
150
|
-
[raw-size]: https://packagephobia.com/badge?p=raw-loader
|
141
|
+
| Name | Status | Install Size | Description |
|
142
|
+
| :---------------: | :--------: | :----------: | :------------------------------------------------------- |
|
143
|
+
| [val-loader][val] | ![val-npm] | ![val-size] | Executes code as module and considers exports as JS code |
|
144
|
+
|
151
145
|
[val]: https://github.com/webpack-contrib/val-loader
|
152
146
|
[val-npm]: https://img.shields.io/npm/v/val-loader.svg
|
153
147
|
[val-size]: https://packagephobia.com/badge?p=val-loader
|
154
|
-
[url]: https://github.com/webpack-contrib/url-loader
|
155
|
-
[url-npm]: https://img.shields.io/npm/v/url-loader.svg
|
156
|
-
[url-size]: https://packagephobia.com/badge?p=url-loader
|
157
|
-
[file]: https://github.com/webpack-contrib/file-loader
|
158
|
-
[file-npm]: https://img.shields.io/npm/v/file-loader.svg
|
159
|
-
[file-size]: https://packagephobia.com/badge?p=file-loader
|
160
148
|
|
161
149
|
#### JSON
|
162
150
|
|
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
@@ -1839,13 +1839,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1839
1839
|
contextInfo,
|
1840
1840
|
context
|
1841
1841
|
},
|
1842
|
-
err => {
|
1842
|
+
(err, result) => {
|
1843
1843
|
if (err && this.bail) {
|
1844
1844
|
callback(err);
|
1845
1845
|
this.buildQueue.stop();
|
1846
1846
|
this.rebuildQueue.stop();
|
1847
1847
|
this.processDependenciesQueue.stop();
|
1848
1848
|
this.factorizeQueue.stop();
|
1849
|
+
} else if (!err && result) {
|
1850
|
+
callback(null, result);
|
1849
1851
|
} else {
|
1850
1852
|
callback();
|
1851
1853
|
}
|
@@ -2877,6 +2879,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2877
2879
|
chunkGraph.connectChunkAndRuntimeModule(chunk, module);
|
2878
2880
|
if (module.fullHash) {
|
2879
2881
|
chunkGraph.addFullHashModuleToChunk(chunk, module);
|
2882
|
+
} else if (module.dependentHash) {
|
2883
|
+
chunkGraph.addDependentHashModuleToChunk(chunk, module);
|
2880
2884
|
}
|
2881
2885
|
|
2882
2886
|
// attach runtime module
|
@@ -3342,8 +3346,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3342
3346
|
if (remaining > 0) {
|
3343
3347
|
const readyChunks = [];
|
3344
3348
|
for (const chunk of runtimeChunks) {
|
3349
|
+
const hasFullHashModules =
|
3350
|
+
chunkGraph.getNumberOfChunkFullHashModules(chunk) !== 0;
|
3345
3351
|
const info = runtimeChunksMap.get(chunk);
|
3346
3352
|
for (const otherInfo of info.referencedBy) {
|
3353
|
+
if (hasFullHashModules) {
|
3354
|
+
chunkGraph.upgradeDependentToFullHashModules(otherInfo.chunk);
|
3355
|
+
}
|
3347
3356
|
remaining--;
|
3348
3357
|
if (--otherInfo.remaining === 0) {
|
3349
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
|
@@ -11,7 +11,7 @@ const NormalModule = require("./NormalModule");
|
|
11
11
|
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
12
12
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
13
13
|
const ConcatenatedModule = require("./optimize/ConcatenatedModule");
|
14
|
-
const {
|
14
|
+
const { makePathsAbsolute } = require("./util/identifier");
|
15
15
|
|
16
16
|
/** @typedef {import("webpack-sources").Source} Source */
|
17
17
|
/** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */
|
@@ -125,7 +125,7 @@ class EvalSourceMapDevToolPlugin {
|
|
125
125
|
const root = compiler.root;
|
126
126
|
const modules = sourceMap.sources.map(source => {
|
127
127
|
if (!source.startsWith("webpack://")) return source;
|
128
|
-
source =
|
128
|
+
source = makePathsAbsolute(context, source.slice(10), root);
|
129
129
|
const module = compilation.findModule(source);
|
130
130
|
return module || source;
|
131
131
|
});
|
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":
|