Skip to content

Commit

Permalink
[FIX] projectGraphBuilder: Add module cache invalidation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RandomByte committed May 17, 2023
1 parent 9278d76 commit ba260a8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/graph/projectGraphBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ async function projectGraphBuilder(nodeProvider, workspace) {
const {nodes, parentProject} = queue.shift(); // Get and remove first entry from queue
const res = await Promise.all(nodes.map(async (node) => {
let ui5Module = moduleCollection[node.id];

if (ui5Module) {
log.silly(
`Re-visiting module ${node.id} as a dependency of ${parentProject.getName()}`);

const {project, extensions} = await ui5Module.getSpecifications();
if (!project && !extensions.length) {
// Invalidate cache if the cached module is visited through another parent project and did not
// resolve to anything useful (project or extension(s)) before.
// The module being visited now might be a different version where it contains UI5 Tooling
// configuration, or one of the parent projects could have defined a shim extension meanwhile
log.silly(
`Cached module ${node.id} did not resolve to any projects or extensions. ` +
`Recreating module as a dependency of ${parentProject.getName()}...`);
ui5Module = null;
}
}

if (!ui5Module) {
log.silly(`Visiting Module ${node.id} as a dependency of ${parentProject.getName()}`);
log.verbose(`Creating module ${node.id}...`);
Expand All @@ -174,8 +192,6 @@ async function projectGraphBuilder(nodeProvider, workspace) {
shimCollection
});
} else {
log.silly(
`Re-visiting module ${node.id} as a dependency of ${parentProject.getName()}`);
if (ui5Module.getPath() !== node.path) {
log.verbose(
`Warning - Dependency ${node.id} is available at multiple paths:` +
Expand Down

0 comments on commit ba260a8

Please sign in to comment.