Skip to content

Commit d40f7b2

Browse files
committed
cache contextify and pass associatedObjectForCache to all calls
1 parent cf71cd0 commit d40f7b2

12 files changed

+103
-53
lines changed

lib/ContextModule.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,23 @@ class ContextModule extends Module {
213213
* @returns {string | null} an identifier for library inclusion
214214
*/
215215
libIdent(options) {
216-
let identifier = contextify(options.context, this.context);
216+
let identifier = contextify(
217+
options.context,
218+
this.context,
219+
options.associatedObjectForCache
220+
);
217221
if (this.options.mode) {
218222
identifier += ` ${this.options.mode}`;
219223
}
220224
if (this.options.recursive) {
221225
identifier += " recursive";
222226
}
223227
if (this.options.addon) {
224-
identifier += ` ${contextify(options.context, this.options.addon)}`;
228+
identifier += ` ${contextify(
229+
options.context,
230+
this.options.addon,
231+
options.associatedObjectForCache
232+
)}`;
225233
}
226234
if (this.options.regExp) {
227235
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;

lib/DelegatedModuleFactoryPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const DelegatedModule = require("./DelegatedModule");
1212
// options.context
1313
// options.scope
1414
// options.content
15+
// options.associatedObjectForCache
1516
class DelegatedModuleFactoryPlugin {
1617
constructor(options) {
1718
this.options = options;

lib/DelegatedPlugin.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ class DelegatedPlugin {
3838
);
3939

4040
compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
41-
new DelegatedModuleFactoryPlugin(this.options).apply(normalModuleFactory);
41+
new DelegatedModuleFactoryPlugin(
42+
Object.assign(
43+
{
44+
associatedObjectForCache: compiler.root
45+
},
46+
this.options
47+
)
48+
).apply(normalModuleFactory);
4249
});
4350
}
4451
}

lib/DllReferencePlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class DllReferencePlugin {
122122
scope: this.options.scope,
123123
context: this.options.context || compiler.options.context,
124124
content,
125-
extensions: this.options.extensions
125+
extensions: this.options.extensions,
126+
associatedObjectForCache: compiler.root
126127
}).apply(normalModuleFactory);
127128
});
128129

lib/LibManifestPlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class LibManifestPlugin {
6767
return;
6868
}
6969
const ident = module.libIdent({
70-
context: this.options.context || compiler.options.context
70+
context: this.options.context || compiler.options.context,
71+
associatedObjectForCache: compiler.root
7172
});
7273
if (ident) {
7374
const providedExports = moduleGraph.getProvidedExports(

lib/Module.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const makeSerializable = require("./util/makeSerializable");
3737
/**
3838
* @typedef {Object} LibIdentOptions
3939
* @property {string} context absolute context path to which lib ident is relative to
40+
* @property {Object=} associatedObjectForCache object for caching
4041
*/
4142

4243
/**

lib/ids/IdHelpers.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ const shortenLongString = (string, delimiter) => {
8585
/**
8686
* @param {Module} module the module
8787
* @param {string} context context directory
88+
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
8889
* @returns {string} short module name
8990
*/
90-
const getShortModuleName = (module, context) => {
91-
return avoidNumber(module.libIdent({ context }) || "");
91+
const getShortModuleName = (module, context, associatedObjectForCache) => {
92+
return avoidNumber(
93+
module.libIdent({ context, associatedObjectForCache }) || ""
94+
);
9295
};
9396
exports.getShortModuleName = getShortModuleName;
9497

@@ -130,12 +133,19 @@ exports.getFullModuleName = getFullModuleName;
130133
* @param {ChunkGraph} chunkGraph the chunk grph
131134
* @param {string} context context directory
132135
* @param {string} delimiter delimiter for names
136+
* @param {Object=} associatedObjectForCache an object to which the cache will be attached
133137
* @returns {string} short chunk name
134138
*/
135-
const getShortChunkName = (chunk, chunkGraph, context, delimiter) => {
139+
const getShortChunkName = (
140+
chunk,
141+
chunkGraph,
142+
context,
143+
delimiter,
144+
associatedObjectForCache
145+
) => {
136146
const modules = chunkGraph.getChunkRootModules(chunk);
137147
const shortModuleNames = modules.map(m =>
138-
requestToId(getShortModuleName(m, context))
148+
requestToId(getShortModuleName(m, context, associatedObjectForCache))
139149
);
140150
chunk.idNameHints.sort();
141151
const chunkName = Array.from(chunk.idNameHints)
@@ -162,7 +172,7 @@ const getLongChunkName = (
162172
) => {
163173
const modules = chunkGraph.getChunkRootModules(chunk);
164174
const shortModuleNames = modules.map(m =>
165-
requestToId(getShortModuleName(m, context))
175+
requestToId(getShortModuleName(m, context, associatedObjectForCache))
166176
);
167177
const longModuleNames = modules.map(m =>
168178
requestToId(getLongModuleName("", m, context, associatedObjectForCache))

lib/ids/NamedChunkIdsPlugin.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ class NamedChunkIdsPlugin {
4343
}
4444
return chunk.id === null;
4545
}),
46-
chunk => getShortChunkName(chunk, chunkGraph, context, delimiter),
46+
chunk =>
47+
getShortChunkName(
48+
chunk,
49+
chunkGraph,
50+
context,
51+
delimiter,
52+
compiler.root
53+
),
4754
chunk =>
4855
getLongChunkName(
4956
chunk,

lib/ids/NamedModuleIdsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class NamedModuleIdsPlugin {
3939
if (chunkGraph.getNumberOfModuleChunks(module) === 0) return false;
4040
return chunkGraph.getModuleId(module) === null;
4141
}),
42-
m => getShortModuleName(m, context),
42+
m => getShortModuleName(m, context, compiler.root),
4343
(m, shortName) =>
4444
getLongModuleName(shortName, m, context, compiler.root),
4545
compareModulesByIdentifier,

lib/optimize/ConcatenatedModule.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class ConcatenatedModule extends Module {
468468
}
469469
}
470470
}
471-
this._identifier = this._createIdentifier();
471+
this._identifier = this._createIdentifier(compilation.compiler.root);
472472
}
473473

474474
get modules() {
@@ -595,13 +595,14 @@ class ConcatenatedModule extends Module {
595595
return list;
596596
}
597597

598-
_createIdentifier() {
598+
_createIdentifier(associatedObjectForCache) {
599599
let orderedConcatenationListIdentifiers = "";
600600
for (let i = 0; i < this._orderedConcatenationList.length; i++) {
601601
if (this._orderedConcatenationList[i].type === "concatenated") {
602602
orderedConcatenationListIdentifiers += contextify(
603603
this.rootModule.context,
604-
this._orderedConcatenationList[i].module.identifier()
604+
this._orderedConcatenationList[i].module.identifier(),
605+
associatedObjectForCache
605606
);
606607
orderedConcatenationListIdentifiers += " ";
607608
}

0 commit comments

Comments
 (0)