Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] projectGraphBuilder: Add module cache invalidation #612

Merged
merged 5 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
matz3 marked this conversation as resolved.
Show resolved Hide resolved
log.verbose(
`Warning - Dependency ${node.id} is available at multiple paths:` +
Expand Down
56 changes: 56 additions & 0 deletions test/lib/graph/projectGraphBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,62 @@ test("Dependencies defined through shim", async (t) => {
t.deepEqual(graph.getDependencies("project-3"), ["project-2"], "Shimmed dependency has been defined");
});

test("Define external dependency as shims in sub-module", async (t) => {
t.context.getRootNode.resolves(createNode({
id: "app",
version: "1.0.0",
path: "/app"
}));

t.context.getDependencies.onCall(0).resolves([
createNode({
id: "lib",
version: "1.0.0",
path: "/lib"
}),
{
id: "external-thirdparty",
version: "1.0.0",
path: "/app/node_modules/external-thirdparty"
},
createNode({
id: "external-thirdparty-shim",
configuration: {
kind: "extension",
type: "project-shim",
shims: {
configurations: {
"external-thirdparty": {
specVersion: "3.0",
type: "module",
metadata: {name: "external-thirdparty"},
resources: {
configuration: {
paths: {"/resources/": ""},
},
},
},
},
},
}
})
]);

t.context.getDependencies.onCall(1).resolves([
createNode({
id: "external-thirdparty",
version: "1.0.0",
path: "/app/node_modules/external-thirdparty",
optional: false
})
]);

const graph = await projectGraphBuilder(t.context.provider);

t.deepEqual(graph.getDependencies("app"), ["lib"], "'app' depends on 'lib'");
t.deepEqual(graph.getDependencies("lib"), ["external-thirdparty"], "'lib' depends on 'external-thirdparty'");
});

test("Extension in dependencies", async (t) => {
t.context.getRootNode.resolves(createNode({
id: "id1",
Expand Down