Skip to content

Commit 65496ea

Browse files
[FIX] projectGraphBuilder: Add module cache invalidation (#612)
If a visited module did not resolve to any specification (project or extensions), try recreating the module when visiting it again from a different parent. Resolves SAP/ui5-tooling#807 This is an alternative to #611 This change might have a greater impact on performance since er might recreate modules that are not relevant to UI5 Tooling more than once if they are listed multiple times in the dependency tree. Before this change, such modules where only visited once. --------- Co-authored-by: Yavor Ivanov <[email protected]>
1 parent 4b0f68a commit 65496ea

File tree

2 files changed

+80
-9
lines changed

2 files changed

+80
-9
lines changed

lib/graph/projectGraphBuilder.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ async function projectGraphBuilder(nodeProvider, workspace) {
161161
const {nodes, parentProject} = queue.shift(); // Get and remove first entry from queue
162162
const res = await Promise.all(nodes.map(async (node) => {
163163
let ui5Module = moduleCollection[node.id];
164+
165+
if (ui5Module) {
166+
log.silly(
167+
`Re-visiting module ${node.id} as a dependency of ${parentProject.getName()}`);
168+
169+
const {project, extensions} = await ui5Module.getSpecifications();
170+
if (!project && !extensions.length) {
171+
// Invalidate cache if the cached module is visited through another parent project and did not
172+
// resolve to a project or extension(s) before.
173+
// The module being visited now might be a different version containing for example
174+
// UI5 Tooling configuration, or one of the parent projects could have defined a
175+
// relevant configuration shim meanwhile
176+
log.silly(
177+
`Cached module ${node.id} did not resolve to any projects or extensions. ` +
178+
`Recreating module as a dependency of ${parentProject.getName()}...`);
179+
ui5Module = null;
180+
}
181+
}
182+
164183
if (!ui5Module) {
165184
log.silly(`Visiting Module ${node.id} as a dependency of ${parentProject.getName()}`);
166185
log.verbose(`Creating module ${node.id}...`);
@@ -173,15 +192,11 @@ async function projectGraphBuilder(nodeProvider, workspace) {
173192
configuration: node.configuration,
174193
shimCollection
175194
});
176-
} else {
177-
log.silly(
178-
`Re-visiting module ${node.id} as a dependency of ${parentProject.getName()}`);
179-
if (ui5Module.getPath() !== node.path) {
180-
log.verbose(
181-
`Warning - Dependency ${node.id} is available at multiple paths:` +
182-
`\n Location of the already processed module (this one will be used): ${ui5Module.getPath()}` +
183-
`\n Additional location (this one will be ignored): ${node.path}`);
184-
}
195+
} else if (ui5Module.getPath() !== node.path) {
196+
log.verbose(
197+
`Warning - Dependency ${node.id} is available at multiple paths:` +
198+
`\n Location of the already processed module (this one will be used): ${ui5Module.getPath()}` +
199+
`\n Additional location (this one will be ignored): ${node.path}`);
185200
}
186201

187202
const {project, extensions} = await ui5Module.getSpecifications();

test/lib/graph/projectGraphBuilder.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,62 @@ test("Dependencies defined through shim", async (t) => {
674674
t.deepEqual(graph.getDependencies("project-3"), ["project-2"], "Shimmed dependency has been defined");
675675
});
676676

677+
test("Define external dependency as shims in sub-module", async (t) => {
678+
t.context.getRootNode.resolves(createNode({
679+
id: "app",
680+
version: "1.0.0",
681+
path: "/app"
682+
}));
683+
684+
t.context.getDependencies.onCall(0).resolves([
685+
createNode({
686+
id: "lib",
687+
version: "1.0.0",
688+
path: "/lib"
689+
}),
690+
{
691+
id: "external-thirdparty",
692+
version: "1.0.0",
693+
path: "/app/node_modules/external-thirdparty"
694+
},
695+
createNode({
696+
id: "external-thirdparty-shim",
697+
configuration: {
698+
kind: "extension",
699+
type: "project-shim",
700+
shims: {
701+
configurations: {
702+
"external-thirdparty": {
703+
specVersion: "3.0",
704+
type: "module",
705+
metadata: {name: "external-thirdparty"},
706+
resources: {
707+
configuration: {
708+
paths: {"/resources/": ""},
709+
},
710+
},
711+
},
712+
},
713+
},
714+
}
715+
})
716+
]);
717+
718+
t.context.getDependencies.onCall(1).resolves([
719+
createNode({
720+
id: "external-thirdparty",
721+
version: "1.0.0",
722+
path: "/app/node_modules/external-thirdparty",
723+
optional: false
724+
})
725+
]);
726+
727+
const graph = await projectGraphBuilder(t.context.provider);
728+
729+
t.deepEqual(graph.getDependencies("app"), ["lib"], "'app' depends on 'lib'");
730+
t.deepEqual(graph.getDependencies("lib"), ["external-thirdparty"], "'lib' depends on 'external-thirdparty'");
731+
});
732+
677733
test("Extension in dependencies", async (t) => {
678734
t.context.getRootNode.resolves(createNode({
679735
id: "id1",

0 commit comments

Comments
 (0)