webpack 5.54.0 → 5.55.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/Compilation.js +363 -149
- package/lib/Compiler.js +5 -5
- package/lib/Dependency.js +11 -0
- package/lib/FlagDependencyExportsPlugin.js +9 -27
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +90 -21
- package/lib/NormalModuleFactory.js +8 -43
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
- package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
- package/lib/dependencies/ContextDependency.js +8 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
- package/lib/dependencies/HarmonyImportDependency.js +4 -1
- package/lib/dependencies/ModuleDependency.js +8 -0
- package/lib/dependencies/NullDependency.js +8 -4
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
- package/lib/util/WeakTupleMap.js +95 -92
- package/package.json +1 -1
- package/types.d.ts +52 -18
- package/lib/MemCache.js +0 -45
package/lib/Compiler.js
CHANGED
@@ -41,8 +41,8 @@ const { isSourceEqual } = require("./util/source");
|
|
41
41
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
42
42
|
/** @typedef {import("./Chunk")} Chunk */
|
43
43
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
44
|
-
/** @typedef {import("./MemCache")} MemCache */
|
45
44
|
/** @typedef {import("./Module")} Module */
|
45
|
+
/** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
|
46
46
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
47
47
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
48
48
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
@@ -248,7 +248,7 @@ class Compiler {
|
|
248
248
|
|
249
249
|
this.cache = new Cache();
|
250
250
|
|
251
|
-
/** @type {WeakMap<Module, { hash: string, memCache:
|
251
|
+
/** @type {WeakMap<Module, { hash: string, memCache: WeakTupleMap }> | undefined} */
|
252
252
|
this.moduleMemCaches = undefined;
|
253
253
|
|
254
254
|
this.compilerPath = "";
|
@@ -1035,9 +1035,9 @@ ${other}`);
|
|
1035
1035
|
return !!this.parentCompilation;
|
1036
1036
|
}
|
1037
1037
|
|
1038
|
-
createCompilation() {
|
1038
|
+
createCompilation(params) {
|
1039
1039
|
this._cleanupLastCompilation();
|
1040
|
-
return (this._lastCompilation = new Compilation(this));
|
1040
|
+
return (this._lastCompilation = new Compilation(this, params));
|
1041
1041
|
}
|
1042
1042
|
|
1043
1043
|
/**
|
@@ -1045,7 +1045,7 @@ ${other}`);
|
|
1045
1045
|
* @returns {Compilation} the created compilation
|
1046
1046
|
*/
|
1047
1047
|
newCompilation(params) {
|
1048
|
-
const compilation = this.createCompilation();
|
1048
|
+
const compilation = this.createCompilation(params);
|
1049
1049
|
compilation.name = this.name;
|
1050
1050
|
compilation.records = this.records;
|
1051
1051
|
this.hooks.thisCompilation.call(compilation, params);
|
package/lib/Dependency.js
CHANGED
@@ -78,6 +78,8 @@ const memoize = require("./util/memoize");
|
|
78
78
|
* @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
|
79
79
|
*/
|
80
80
|
|
81
|
+
const TRANSITIVE = Symbol("transitive");
|
82
|
+
|
81
83
|
const getIgnoredModule = memoize(() => {
|
82
84
|
const RawModule = require("./RawModule");
|
83
85
|
return new RawModule("/* (ignored) */", `ignored`, `(ignored)`);
|
@@ -175,6 +177,13 @@ class Dependency {
|
|
175
177
|
return null;
|
176
178
|
}
|
177
179
|
|
180
|
+
/**
|
181
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
182
|
+
*/
|
183
|
+
couldAffectReferencingModule() {
|
184
|
+
return TRANSITIVE;
|
185
|
+
}
|
186
|
+
|
178
187
|
/**
|
179
188
|
* Returns the referenced module and export
|
180
189
|
* @deprecated
|
@@ -322,4 +331,6 @@ Object.defineProperty(Dependency.prototype, "disconnect", {
|
|
322
331
|
}
|
323
332
|
});
|
324
333
|
|
334
|
+
Dependency.TRANSITIVE = TRANSITIVE;
|
335
|
+
|
325
336
|
module.exports = Dependency;
|
@@ -28,7 +28,6 @@ class FlagDependencyExportsPlugin {
|
|
28
28
|
compilation => {
|
29
29
|
const moduleGraph = compilation.moduleGraph;
|
30
30
|
const cache = compilation.getCache("FlagDependencyExportsPlugin");
|
31
|
-
const { moduleMemCaches } = compilation;
|
32
31
|
compilation.hooks.finishModules.tapAsync(
|
33
32
|
"FlagDependencyExportsPlugin",
|
34
33
|
(modules, callback) => {
|
@@ -42,6 +41,8 @@ class FlagDependencyExportsPlugin {
|
|
42
41
|
let statNotCached = 0;
|
43
42
|
let statQueueItemsProcessed = 0;
|
44
43
|
|
44
|
+
const { moduleMemCaches } = compilation;
|
45
|
+
|
45
46
|
/** @type {Queue<Module>} */
|
46
47
|
const queue = new Queue();
|
47
48
|
|
@@ -68,12 +69,10 @@ class FlagDependencyExportsPlugin {
|
|
68
69
|
return callback();
|
69
70
|
}
|
70
71
|
const memCache = moduleMemCaches && moduleMemCaches.get(module);
|
71
|
-
const memCacheValue = memCache && memCache.get(this
|
72
|
+
const memCacheValue = memCache && memCache.get(this);
|
72
73
|
if (memCacheValue !== undefined) {
|
73
74
|
statRestoredFromMemCache++;
|
74
|
-
|
75
|
-
.getExportsInfo(module)
|
76
|
-
.restoreProvided(memCacheValue);
|
75
|
+
exportsInfo.restoreProvided(memCacheValue);
|
77
76
|
return callback();
|
78
77
|
}
|
79
78
|
cache.get(
|
@@ -84,9 +83,7 @@ class FlagDependencyExportsPlugin {
|
|
84
83
|
|
85
84
|
if (result !== undefined) {
|
86
85
|
statRestoredFromCache++;
|
87
|
-
|
88
|
-
.getExportsInfo(module)
|
89
|
-
.restoreProvided(result);
|
86
|
+
exportsInfo.restoreProvided(result);
|
90
87
|
} else {
|
91
88
|
statNotCached++;
|
92
89
|
// Without cached info enqueue module for determining the exports
|
@@ -102,9 +99,7 @@ class FlagDependencyExportsPlugin {
|
|
102
99
|
if (err) return callback(err);
|
103
100
|
|
104
101
|
/** @type {Set<Module>} */
|
105
|
-
const
|
106
|
-
/** @type {Set<Module>} */
|
107
|
-
const modulesToStoreTransient = new Set();
|
102
|
+
const modulesToStore = new Set();
|
108
103
|
|
109
104
|
/** @type {Map<Module, Set<Module>>} */
|
110
105
|
const dependencies = new Map();
|
@@ -338,9 +333,7 @@ class FlagDependencyExportsPlugin {
|
|
338
333
|
}
|
339
334
|
|
340
335
|
if (cacheable) {
|
341
|
-
|
342
|
-
} else {
|
343
|
-
modulesToStoreTransient.add(module);
|
336
|
+
modulesToStore.add(module);
|
344
337
|
}
|
345
338
|
|
346
339
|
if (changed) {
|
@@ -366,7 +359,7 @@ class FlagDependencyExportsPlugin {
|
|
366
359
|
|
367
360
|
logger.time("store provided exports into cache");
|
368
361
|
asyncLib.each(
|
369
|
-
|
362
|
+
modulesToStore,
|
370
363
|
(module, callback) => {
|
371
364
|
if (typeof module.buildInfo.hash !== "string") {
|
372
365
|
// not cacheable
|
@@ -378,7 +371,7 @@ class FlagDependencyExportsPlugin {
|
|
378
371
|
const memCache =
|
379
372
|
moduleMemCaches && moduleMemCaches.get(module);
|
380
373
|
if (memCache) {
|
381
|
-
memCache.set(this,
|
374
|
+
memCache.set(this, cachedData);
|
382
375
|
}
|
383
376
|
cache.store(
|
384
377
|
module.identifier(),
|
@@ -389,17 +382,6 @@ class FlagDependencyExportsPlugin {
|
|
389
382
|
},
|
390
383
|
err => {
|
391
384
|
logger.timeEnd("store provided exports into cache");
|
392
|
-
if (moduleMemCaches) {
|
393
|
-
for (const module of modulesToStoreTransient) {
|
394
|
-
const memCache = moduleMemCaches.get(module);
|
395
|
-
if (memCache) {
|
396
|
-
const cachedData = moduleGraph
|
397
|
-
.getExportsInfo(module)
|
398
|
-
.getRestoreProvidedData();
|
399
|
-
memCache.set(this, module, cachedData);
|
400
|
-
}
|
401
|
-
}
|
402
|
-
}
|
403
385
|
callback(err);
|
404
386
|
}
|
405
387
|
);
|
package/lib/ModuleFactory.js
CHANGED
package/lib/ModuleGraph.js
CHANGED
@@ -79,19 +79,19 @@ class ModuleGraphModule {
|
|
79
79
|
this.profile = undefined;
|
80
80
|
/** @type {boolean} */
|
81
81
|
this.async = false;
|
82
|
+
/** @type {ModuleGraphConnection[]} */
|
83
|
+
this._unassignedConnections = undefined;
|
82
84
|
}
|
83
85
|
}
|
84
86
|
|
85
87
|
class ModuleGraph {
|
86
88
|
constructor() {
|
87
|
-
/** @type {
|
88
|
-
this._dependencyMap = new
|
89
|
+
/** @type {WeakMap<Dependency, ModuleGraphConnection>} */
|
90
|
+
this._dependencyMap = new WeakMap();
|
89
91
|
/** @type {Map<Module, ModuleGraphModule>} */
|
90
92
|
this._moduleMap = new Map();
|
91
|
-
/** @type {
|
92
|
-
this.
|
93
|
-
/** @type {Map<any, Object>} */
|
94
|
-
this._metaMap = new Map();
|
93
|
+
/** @type {WeakMap<any, Object>} */
|
94
|
+
this._metaMap = new WeakMap();
|
95
95
|
|
96
96
|
// Caching
|
97
97
|
this._cacheModuleGraphModuleKey1 = undefined;
|
@@ -103,6 +103,9 @@ class ModuleGraph {
|
|
103
103
|
|
104
104
|
/** @type {WeakTupleMap<any[], any>} */
|
105
105
|
this._cache = undefined;
|
106
|
+
|
107
|
+
/** @type {WeakMap<Module, WeakTupleMap<any, any>>} */
|
108
|
+
this._moduleMemCaches = undefined;
|
106
109
|
}
|
107
110
|
|
108
111
|
/**
|
@@ -168,14 +171,21 @@ class ModuleGraph {
|
|
168
171
|
dependency.weak,
|
169
172
|
dependency.getCondition(this)
|
170
173
|
);
|
171
|
-
this._dependencyMap.set(dependency, connection);
|
172
174
|
const connections = this._getModuleGraphModule(module).incomingConnections;
|
173
175
|
connections.add(connection);
|
174
|
-
|
175
|
-
|
176
|
-
mgm.
|
176
|
+
if (originModule) {
|
177
|
+
const mgm = this._getModuleGraphModule(originModule);
|
178
|
+
if (mgm._unassignedConnections === undefined) {
|
179
|
+
mgm._unassignedConnections = [];
|
180
|
+
}
|
181
|
+
mgm._unassignedConnections.push(connection);
|
182
|
+
if (mgm.outgoingConnections === undefined) {
|
183
|
+
mgm.outgoingConnections = new Set();
|
184
|
+
}
|
185
|
+
mgm.outgoingConnections.add(connection);
|
186
|
+
} else {
|
187
|
+
this._dependencyMap.set(dependency, connection);
|
177
188
|
}
|
178
|
-
mgm.outgoingConnections.add(connection);
|
179
189
|
}
|
180
190
|
|
181
191
|
/**
|
@@ -184,7 +194,7 @@ class ModuleGraph {
|
|
184
194
|
* @returns {void}
|
185
195
|
*/
|
186
196
|
updateModule(dependency, module) {
|
187
|
-
const connection = this.
|
197
|
+
const connection = this.getConnection(dependency);
|
188
198
|
if (connection.module === module) return;
|
189
199
|
const newConnection = connection.clone();
|
190
200
|
newConnection.module = module;
|
@@ -201,12 +211,12 @@ class ModuleGraph {
|
|
201
211
|
* @returns {void}
|
202
212
|
*/
|
203
213
|
removeConnection(dependency) {
|
204
|
-
const connection = this.
|
214
|
+
const connection = this.getConnection(dependency);
|
205
215
|
const targetMgm = this._getModuleGraphModule(connection.module);
|
206
216
|
targetMgm.incomingConnections.delete(connection);
|
207
217
|
const originMgm = this._getModuleGraphModule(connection.originModule);
|
208
218
|
originMgm.outgoingConnections.delete(connection);
|
209
|
-
this._dependencyMap.
|
219
|
+
this._dependencyMap.set(dependency, null);
|
210
220
|
}
|
211
221
|
|
212
222
|
/**
|
@@ -215,7 +225,7 @@ class ModuleGraph {
|
|
215
225
|
* @returns {void}
|
216
226
|
*/
|
217
227
|
addExplanation(dependency, explanation) {
|
218
|
-
const connection = this.
|
228
|
+
const connection = this.getConnection(dependency);
|
219
229
|
connection.addExplanation(explanation);
|
220
230
|
}
|
221
231
|
|
@@ -341,7 +351,7 @@ class ModuleGraph {
|
|
341
351
|
* @returns {Module} the referenced module
|
342
352
|
*/
|
343
353
|
getResolvedModule(dependency) {
|
344
|
-
const connection = this.
|
354
|
+
const connection = this.getConnection(dependency);
|
345
355
|
return connection !== undefined ? connection.resolvedModule : null;
|
346
356
|
}
|
347
357
|
|
@@ -351,7 +361,30 @@ class ModuleGraph {
|
|
351
361
|
*/
|
352
362
|
getConnection(dependency) {
|
353
363
|
const connection = this._dependencyMap.get(dependency);
|
354
|
-
|
364
|
+
if (connection === undefined) {
|
365
|
+
const module = this.getParentModule(dependency);
|
366
|
+
if (module !== undefined) {
|
367
|
+
const mgm = this._getModuleGraphModule(module);
|
368
|
+
if (
|
369
|
+
mgm._unassignedConnections &&
|
370
|
+
mgm._unassignedConnections.length !== 0
|
371
|
+
) {
|
372
|
+
let foundConnection;
|
373
|
+
for (const connection of mgm._unassignedConnections) {
|
374
|
+
this._dependencyMap.set(connection.dependency, connection);
|
375
|
+
if (connection.dependency === dependency)
|
376
|
+
foundConnection = connection;
|
377
|
+
}
|
378
|
+
mgm._unassignedConnections.length = 0;
|
379
|
+
if (foundConnection !== undefined) {
|
380
|
+
return foundConnection;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
this._dependencyMap.set(dependency, null);
|
385
|
+
return undefined;
|
386
|
+
}
|
387
|
+
return connection === null ? undefined : connection;
|
355
388
|
}
|
356
389
|
|
357
390
|
/**
|
@@ -359,7 +392,7 @@ class ModuleGraph {
|
|
359
392
|
* @returns {Module} the referenced module
|
360
393
|
*/
|
361
394
|
getModule(dependency) {
|
362
|
-
const connection = this.
|
395
|
+
const connection = this.getConnection(dependency);
|
363
396
|
return connection !== undefined ? connection.module : null;
|
364
397
|
}
|
365
398
|
|
@@ -368,7 +401,7 @@ class ModuleGraph {
|
|
368
401
|
* @returns {Module} the referencing module
|
369
402
|
*/
|
370
403
|
getOrigin(dependency) {
|
371
|
-
const connection = this.
|
404
|
+
const connection = this.getConnection(dependency);
|
372
405
|
return connection !== undefined ? connection.originModule : null;
|
373
406
|
}
|
374
407
|
|
@@ -377,7 +410,7 @@ class ModuleGraph {
|
|
377
410
|
* @returns {Module} the original referencing module
|
378
411
|
*/
|
379
412
|
getResolvedOrigin(dependency) {
|
380
|
-
const connection = this.
|
413
|
+
const connection = this.getConnection(dependency);
|
381
414
|
return connection !== undefined ? connection.resolvedOriginModule : null;
|
382
415
|
}
|
383
416
|
|
@@ -669,12 +702,17 @@ class ModuleGraph {
|
|
669
702
|
return this._metaMap.get(thing);
|
670
703
|
}
|
671
704
|
|
672
|
-
|
705
|
+
/**
|
706
|
+
* @param {string=} cacheStage a persistent stage name for caching
|
707
|
+
*/
|
708
|
+
freeze(cacheStage) {
|
673
709
|
this._cache = new WeakTupleMap();
|
710
|
+
this._cacheStage = cacheStage;
|
674
711
|
}
|
675
712
|
|
676
713
|
unfreeze() {
|
677
714
|
this._cache = undefined;
|
715
|
+
this._cacheStage = undefined;
|
678
716
|
}
|
679
717
|
|
680
718
|
/**
|
@@ -689,6 +727,37 @@ class ModuleGraph {
|
|
689
727
|
return this._cache.provide(fn, ...args, () => fn(this, ...args));
|
690
728
|
}
|
691
729
|
|
730
|
+
/**
|
731
|
+
* @param {WeakMap<Module, WeakTupleMap<any, any>>} moduleMemCaches mem caches for modules for better caching
|
732
|
+
*/
|
733
|
+
setModuleMemCaches(moduleMemCaches) {
|
734
|
+
this._moduleMemCaches = moduleMemCaches;
|
735
|
+
}
|
736
|
+
|
737
|
+
/**
|
738
|
+
* @param {Dependency} dependency dependency
|
739
|
+
* @param {...any} args arguments, last argument is a function called with moduleGraph, dependency, ...args
|
740
|
+
* @returns {any} computed value or cached
|
741
|
+
*/
|
742
|
+
dependencyCacheProvide(dependency, ...args) {
|
743
|
+
/** @type {(moduleGraph: ModuleGraph, dependency: Dependency, ...args: any[]) => any} */
|
744
|
+
const fn = args.pop();
|
745
|
+
if (this._moduleMemCaches && this._cacheStage) {
|
746
|
+
const memCache = this._moduleMemCaches.get(
|
747
|
+
this.getParentModule(dependency)
|
748
|
+
);
|
749
|
+
if (memCache !== undefined) {
|
750
|
+
return memCache.provide(dependency, this._cacheStage, ...args, () =>
|
751
|
+
fn(this, dependency, ...args)
|
752
|
+
);
|
753
|
+
}
|
754
|
+
}
|
755
|
+
if (this._cache === undefined) return fn(this, dependency, ...args);
|
756
|
+
return this._cache.provide(dependency, ...args, () =>
|
757
|
+
fn(this, dependency, ...args)
|
758
|
+
);
|
759
|
+
}
|
760
|
+
|
692
761
|
// TODO remove in webpack 6
|
693
762
|
/**
|
694
763
|
* @param {Module} module the module
|
@@ -167,12 +167,6 @@ const deprecationChangedHookMessage = (name, hook) => {
|
|
167
167
|
);
|
168
168
|
};
|
169
169
|
|
170
|
-
/** @type {WeakMap<ModuleDependency, ModuleFactoryResult & { module: { restoreFromUnsafeCache: Function }}>} */
|
171
|
-
const unsafeCacheDependencies = new WeakMap();
|
172
|
-
|
173
|
-
/** @type {WeakMap<Module, object>} */
|
174
|
-
const unsafeCacheData = new WeakMap();
|
175
|
-
|
176
170
|
const ruleSetCompiler = new RuleSetCompiler([
|
177
171
|
new BasicMatcherRulePlugin("test", "resource"),
|
178
172
|
new BasicMatcherRulePlugin("scheme"),
|
@@ -256,11 +250,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
256
250
|
rules: options.rules
|
257
251
|
}
|
258
252
|
]);
|
259
|
-
this.unsafeCache = !!options.unsafeCache;
|
260
|
-
this.cachePredicate =
|
261
|
-
typeof options.unsafeCache === "function"
|
262
|
-
? options.unsafeCache
|
263
|
-
: () => true;
|
264
253
|
this.context = context || "";
|
265
254
|
this.fs = fs;
|
266
255
|
this._globalParserOptions = options.parser;
|
@@ -745,18 +734,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
745
734
|
*/
|
746
735
|
create(data, callback) {
|
747
736
|
const dependencies = /** @type {ModuleDependency[]} */ (data.dependencies);
|
748
|
-
if (this.unsafeCache) {
|
749
|
-
const cacheEntry = unsafeCacheDependencies.get(dependencies[0]);
|
750
|
-
if (cacheEntry) {
|
751
|
-
const { module } = cacheEntry;
|
752
|
-
if (!this._restoredUnsafeCacheEntries.has(module)) {
|
753
|
-
const data = unsafeCacheData.get(module);
|
754
|
-
module.restoreFromUnsafeCache(data, this);
|
755
|
-
this._restoredUnsafeCacheEntries.add(module);
|
756
|
-
}
|
757
|
-
return callback(null, cacheEntry);
|
758
|
-
}
|
759
|
-
}
|
760
737
|
const context = data.context || this.context;
|
761
738
|
const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
|
762
739
|
const dependency = dependencies[0];
|
@@ -788,7 +765,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
788
765
|
return callback(err, {
|
789
766
|
fileDependencies,
|
790
767
|
missingDependencies,
|
791
|
-
contextDependencies
|
768
|
+
contextDependencies,
|
769
|
+
cacheable: false
|
792
770
|
});
|
793
771
|
}
|
794
772
|
|
@@ -797,7 +775,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
797
775
|
return callback(null, {
|
798
776
|
fileDependencies,
|
799
777
|
missingDependencies,
|
800
|
-
contextDependencies
|
778
|
+
contextDependencies,
|
779
|
+
cacheable: resolveData.cacheable
|
801
780
|
});
|
802
781
|
}
|
803
782
|
|
@@ -814,7 +793,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
814
793
|
return callback(err, {
|
815
794
|
fileDependencies,
|
816
795
|
missingDependencies,
|
817
|
-
contextDependencies
|
796
|
+
contextDependencies,
|
797
|
+
cacheable: false
|
818
798
|
});
|
819
799
|
}
|
820
800
|
|
@@ -822,25 +802,10 @@ class NormalModuleFactory extends ModuleFactory {
|
|
822
802
|
module,
|
823
803
|
fileDependencies,
|
824
804
|
missingDependencies,
|
825
|
-
contextDependencies
|
805
|
+
contextDependencies,
|
806
|
+
cacheable: resolveData.cacheable
|
826
807
|
};
|
827
808
|
|
828
|
-
if (
|
829
|
-
this.unsafeCache &&
|
830
|
-
resolveData.cacheable &&
|
831
|
-
module &&
|
832
|
-
module.restoreFromUnsafeCache &&
|
833
|
-
this.cachePredicate(module)
|
834
|
-
) {
|
835
|
-
for (const d of dependencies) {
|
836
|
-
unsafeCacheDependencies.set(d, factoryResult);
|
837
|
-
}
|
838
|
-
if (!unsafeCacheData.has(module)) {
|
839
|
-
unsafeCacheData.set(module, module.getUnsafeCacheData());
|
840
|
-
}
|
841
|
-
this._restoredUnsafeCacheEntries.add(module);
|
842
|
-
}
|
843
|
-
|
844
809
|
callback(null, factoryResult);
|
845
810
|
});
|
846
811
|
});
|
@@ -18,6 +18,7 @@ const processExportInfo = require("./processExportInfo");
|
|
18
18
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
19
19
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
20
20
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
21
|
+
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
21
22
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
22
23
|
/** @typedef {import("../Module")} Module */
|
23
24
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
@@ -43,6 +44,13 @@ class CommonJsExportRequireDependency extends ModuleDependency {
|
|
43
44
|
return "cjs export require";
|
44
45
|
}
|
45
46
|
|
47
|
+
/**
|
48
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
49
|
+
*/
|
50
|
+
couldAffectReferencingModule() {
|
51
|
+
return Dependency.TRANSITIVE;
|
52
|
+
}
|
53
|
+
|
46
54
|
/**
|
47
55
|
* @param {ModuleGraph} moduleGraph the module graph
|
48
56
|
* @returns {string[]} the imported id
|
@@ -332,15 +340,17 @@ CommonJsExportRequireDependency.Template = class CommonJsExportRequireDependency
|
|
332
340
|
weak: dep.weak,
|
333
341
|
runtimeRequirements
|
334
342
|
});
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
343
|
+
if (importedModule) {
|
344
|
+
const ids = dep.getIds(moduleGraph);
|
345
|
+
const usedImported = moduleGraph
|
346
|
+
.getExportsInfo(importedModule)
|
347
|
+
.getUsedName(ids, runtime);
|
348
|
+
if (usedImported) {
|
349
|
+
const comment = equals(usedImported, ids)
|
350
|
+
? ""
|
351
|
+
: Template.toNormalComment(propertyAccess(ids)) + " ";
|
352
|
+
requireExpr += `${comment}${propertyAccess(usedImported)}`;
|
353
|
+
}
|
344
354
|
}
|
345
355
|
|
346
356
|
switch (type) {
|
@@ -108,15 +108,17 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
108
108
|
weak: dep.weak,
|
109
109
|
runtimeRequirements
|
110
110
|
});
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
111
|
+
if (importedModule) {
|
112
|
+
const ids = dep.names;
|
113
|
+
const usedImported = moduleGraph
|
114
|
+
.getExportsInfo(importedModule)
|
115
|
+
.getUsedName(ids, runtime);
|
116
|
+
if (usedImported) {
|
117
|
+
const comment = equals(usedImported, ids)
|
118
|
+
? ""
|
119
|
+
: Template.toNormalComment(propertyAccess(ids)) + " ";
|
120
|
+
requireExpr += `${comment}${propertyAccess(usedImported)}`;
|
121
|
+
}
|
120
122
|
}
|
121
123
|
source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
|
122
124
|
}
|
@@ -11,6 +11,7 @@ const makeSerializable = require("../util/makeSerializable");
|
|
11
11
|
const memoize = require("../util/memoize");
|
12
12
|
|
13
13
|
/** @typedef {import("../ContextModule").ContextOptions} ContextOptions */
|
14
|
+
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
14
15
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
15
16
|
/** @typedef {import("../WebpackError")} WebpackError */
|
16
17
|
|
@@ -54,6 +55,13 @@ class ContextDependency extends Dependency {
|
|
54
55
|
return "commonjs";
|
55
56
|
}
|
56
57
|
|
58
|
+
/**
|
59
|
+
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
60
|
+
*/
|
61
|
+
couldAffectReferencingModule() {
|
62
|
+
return true;
|
63
|
+
}
|
64
|
+
|
57
65
|
/**
|
58
66
|
* @returns {string | null} an identifier to merge equal requests
|
59
67
|
*/
|