webpack 5.56.1 → 5.58.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.
- package/lib/AsyncDependenciesBlock.js +3 -4
- package/lib/Chunk.js +4 -6
- package/lib/ChunkGraph.js +1 -28
- package/lib/Compilation.js +215 -57
- package/lib/Compiler.js +1 -1
- package/lib/DependenciesBlock.js +9 -0
- package/lib/Dependency.js +2 -0
- package/lib/DependencyTemplates.js +1 -2
- package/lib/DllModule.js +1 -2
- package/lib/ExportsInfo.js +5 -4
- package/lib/ExternalModule.js +8 -3
- package/lib/FlagDependencyUsagePlugin.js +6 -1
- package/lib/Module.js +4 -0
- package/lib/ModuleGraph.js +60 -25
- package/lib/NormalModule.js +33 -16
- package/lib/NormalModuleFactory.js +57 -55
- package/lib/WebpackOptionsApply.js +2 -2
- package/lib/buildChunkGraph.js +157 -100
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -5
- package/lib/logging/Logger.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -0
- package/lib/optimize/MangleExportsPlugin.js +5 -0
- package/lib/schemes/FileUriPlugin.js +9 -0
- package/lib/util/StringXor.js +28 -22
- package/package.json +1 -1
- package/types.d.ts +21 -7
package/lib/ModuleGraph.js
CHANGED
@@ -29,7 +29,7 @@ const EMPTY_SET = new Set();
|
|
29
29
|
|
30
30
|
/**
|
31
31
|
* @param {SortableSet<ModuleGraphConnection>} set input
|
32
|
-
* @returns {readonly Map<Module, readonly ModuleGraphConnection[]>} mapped by origin module
|
32
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} mapped by origin module
|
33
33
|
*/
|
34
34
|
const getConnectionsByOriginModule = set => {
|
35
35
|
const map = new Map();
|
@@ -57,11 +57,41 @@ const getConnectionsByOriginModule = set => {
|
|
57
57
|
return map;
|
58
58
|
};
|
59
59
|
|
60
|
+
/**
|
61
|
+
* @param {SortableSet<ModuleGraphConnection>} set input
|
62
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} mapped by module
|
63
|
+
*/
|
64
|
+
const getConnectionsByModule = set => {
|
65
|
+
const map = new Map();
|
66
|
+
/** @type {Module | 0} */
|
67
|
+
let lastModule = 0;
|
68
|
+
/** @type {ModuleGraphConnection[]} */
|
69
|
+
let lastList = undefined;
|
70
|
+
for (const connection of set) {
|
71
|
+
const { module } = connection;
|
72
|
+
if (lastModule === module) {
|
73
|
+
lastList.push(connection);
|
74
|
+
} else {
|
75
|
+
lastModule = module;
|
76
|
+
const list = map.get(module);
|
77
|
+
if (list !== undefined) {
|
78
|
+
lastList = list;
|
79
|
+
list.push(connection);
|
80
|
+
} else {
|
81
|
+
const list = [connection];
|
82
|
+
lastList = list;
|
83
|
+
map.set(module, list);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return map;
|
88
|
+
};
|
89
|
+
|
60
90
|
class ModuleGraphModule {
|
61
91
|
constructor() {
|
62
92
|
/** @type {SortableSet<ModuleGraphConnection>} */
|
63
93
|
this.incomingConnections = new SortableSet();
|
64
|
-
/** @type {
|
94
|
+
/** @type {SortableSet<ModuleGraphConnection> | undefined} */
|
65
95
|
this.outgoingConnections = undefined;
|
66
96
|
/** @type {Module | null} */
|
67
97
|
this.issuer = undefined;
|
@@ -93,18 +123,10 @@ class ModuleGraph {
|
|
93
123
|
/** @type {WeakMap<any, Object>} */
|
94
124
|
this._metaMap = new WeakMap();
|
95
125
|
|
96
|
-
// Caching
|
97
|
-
this._cacheModuleGraphModuleKey1 = undefined;
|
98
|
-
this._cacheModuleGraphModuleValue1 = undefined;
|
99
|
-
this._cacheModuleGraphModuleKey2 = undefined;
|
100
|
-
this._cacheModuleGraphModuleValue2 = undefined;
|
101
|
-
this._cacheModuleGraphDependencyKey = undefined;
|
102
|
-
this._cacheModuleGraphDependencyValue = undefined;
|
103
|
-
|
104
126
|
/** @type {WeakTupleMap<any[], any>} */
|
105
127
|
this._cache = undefined;
|
106
128
|
|
107
|
-
/** @type {
|
129
|
+
/** @type {Map<Module, WeakTupleMap<any, any>>} */
|
108
130
|
this._moduleMemCaches = undefined;
|
109
131
|
}
|
110
132
|
|
@@ -113,19 +135,11 @@ class ModuleGraph {
|
|
113
135
|
* @returns {ModuleGraphModule} the internal module
|
114
136
|
*/
|
115
137
|
_getModuleGraphModule(module) {
|
116
|
-
if (this._cacheModuleGraphModuleKey1 === module)
|
117
|
-
return this._cacheModuleGraphModuleValue1;
|
118
|
-
if (this._cacheModuleGraphModuleKey2 === module)
|
119
|
-
return this._cacheModuleGraphModuleValue2;
|
120
138
|
let mgm = this._moduleMap.get(module);
|
121
139
|
if (mgm === undefined) {
|
122
140
|
mgm = new ModuleGraphModule();
|
123
141
|
this._moduleMap.set(module, mgm);
|
124
142
|
}
|
125
|
-
this._cacheModuleGraphModuleKey2 = this._cacheModuleGraphModuleKey1;
|
126
|
-
this._cacheModuleGraphModuleValue2 = this._cacheModuleGraphModuleValue1;
|
127
|
-
this._cacheModuleGraphModuleKey1 = module;
|
128
|
-
this._cacheModuleGraphModuleValue1 = mgm;
|
129
143
|
return mgm;
|
130
144
|
}
|
131
145
|
|
@@ -133,9 +147,11 @@ class ModuleGraph {
|
|
133
147
|
* @param {Dependency} dependency the dependency
|
134
148
|
* @param {DependenciesBlock} block parent block
|
135
149
|
* @param {Module} module parent module
|
150
|
+
* @param {number=} indexInBlock position in block
|
136
151
|
* @returns {void}
|
137
152
|
*/
|
138
|
-
setParents(dependency, block, module) {
|
153
|
+
setParents(dependency, block, module, indexInBlock = -1) {
|
154
|
+
dependency._parentDependenciesBlockIndex = indexInBlock;
|
139
155
|
dependency._parentDependenciesBlock = block;
|
140
156
|
dependency._parentModule = module;
|
141
157
|
}
|
@@ -156,6 +172,14 @@ class ModuleGraph {
|
|
156
172
|
return dependency._parentDependenciesBlock;
|
157
173
|
}
|
158
174
|
|
175
|
+
/**
|
176
|
+
* @param {Dependency} dependency the dependency
|
177
|
+
* @returns {number} index
|
178
|
+
*/
|
179
|
+
getParentBlockIndex(dependency) {
|
180
|
+
return dependency._parentDependenciesBlockIndex;
|
181
|
+
}
|
182
|
+
|
159
183
|
/**
|
160
184
|
* @param {Module} originModule the referencing module
|
161
185
|
* @param {Dependency} dependency the referencing dependency
|
@@ -180,7 +204,7 @@ class ModuleGraph {
|
|
180
204
|
}
|
181
205
|
mgm._unassignedConnections.push(connection);
|
182
206
|
if (mgm.outgoingConnections === undefined) {
|
183
|
-
mgm.outgoingConnections = new
|
207
|
+
mgm.outgoingConnections = new SortableSet();
|
184
208
|
}
|
185
209
|
mgm.outgoingConnections.add(connection);
|
186
210
|
} else {
|
@@ -282,7 +306,7 @@ class ModuleGraph {
|
|
282
306
|
const oldConnections = oldMgm.outgoingConnections;
|
283
307
|
if (oldConnections !== undefined) {
|
284
308
|
if (newMgm.outgoingConnections === undefined) {
|
285
|
-
newMgm.outgoingConnections = new
|
309
|
+
newMgm.outgoingConnections = new SortableSet();
|
286
310
|
}
|
287
311
|
const newConnections = newMgm.outgoingConnections;
|
288
312
|
for (const connection of oldConnections) {
|
@@ -319,7 +343,7 @@ class ModuleGraph {
|
|
319
343
|
const oldConnections = oldMgm.outgoingConnections;
|
320
344
|
if (oldConnections !== undefined) {
|
321
345
|
if (newMgm.outgoingConnections === undefined) {
|
322
|
-
newMgm.outgoingConnections = new
|
346
|
+
newMgm.outgoingConnections = new SortableSet();
|
323
347
|
}
|
324
348
|
const newConnections = newMgm.outgoingConnections;
|
325
349
|
for (const connection of oldConnections) {
|
@@ -434,13 +458,24 @@ class ModuleGraph {
|
|
434
458
|
|
435
459
|
/**
|
436
460
|
* @param {Module} module the module
|
437
|
-
* @returns {readonly Map<Module, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
|
461
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
|
438
462
|
*/
|
439
463
|
getIncomingConnectionsByOriginModule(module) {
|
440
464
|
const connections = this._getModuleGraphModule(module).incomingConnections;
|
441
465
|
return connections.getFromUnorderedCache(getConnectionsByOriginModule);
|
442
466
|
}
|
443
467
|
|
468
|
+
/**
|
469
|
+
* @param {Module} module the module
|
470
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]> | undefined} connections to modules, in a map by module
|
471
|
+
*/
|
472
|
+
getOutgoingConnectionsByModule(module) {
|
473
|
+
const connections = this._getModuleGraphModule(module).outgoingConnections;
|
474
|
+
return connections === undefined
|
475
|
+
? undefined
|
476
|
+
: connections.getFromUnorderedCache(getConnectionsByModule);
|
477
|
+
}
|
478
|
+
|
444
479
|
/**
|
445
480
|
* @param {Module} module the module
|
446
481
|
* @returns {ModuleProfile | null} the module profile
|
@@ -728,7 +763,7 @@ class ModuleGraph {
|
|
728
763
|
}
|
729
764
|
|
730
765
|
/**
|
731
|
-
* @param {
|
766
|
+
* @param {Map<Module, WeakTupleMap<any, any>>} moduleMemCaches mem caches for modules for better caching
|
732
767
|
*/
|
733
768
|
setModuleMemCaches(moduleMemCaches) {
|
734
769
|
this._moduleMemCaches = moduleMemCaches;
|
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,
|
@@ -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
|
-
|
213
|
-
|
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
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
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
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
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) {
|
@@ -550,7 +550,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
550
550
|
"'cache.cacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
551
551
|
);
|
552
552
|
}
|
553
|
-
compiler.moduleMemCaches = new
|
553
|
+
compiler.moduleMemCaches = new Map();
|
554
554
|
}
|
555
555
|
break;
|
556
556
|
}
|
@@ -577,7 +577,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
577
577
|
"'cache.memoryCacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
578
578
|
);
|
579
579
|
}
|
580
|
-
compiler.moduleMemCaches = new
|
580
|
+
compiler.moduleMemCaches = new Map();
|
581
581
|
}
|
582
582
|
switch (cacheOptions.store) {
|
583
583
|
case "pack": {
|