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] Properly resolve dependent shimmed modules #611

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
23 changes: 22 additions & 1 deletion lib/graph/projectGraphBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ 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];
let fromCache = true;
if (!ui5Module) {
log.silly(`Visiting Module ${node.id} as a dependency of ${parentProject.getName()}`);
log.verbose(`Creating module ${node.id}...`);
validateNode(node);
fromCache = false;
ui5Module = moduleCollection[node.id] = new Module({
id: node.id,
version: node.version,
Expand All @@ -184,7 +186,26 @@ async function projectGraphBuilder(nodeProvider, workspace) {
}
}

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

// Try again this module with an eventual Shim resolution
if (
fromCache &&
!project &&
!!shimCollection.getProjectConfigurationShims(node.id)
) {
ui5Module = moduleCollection[node.id] = new Module({
id: node.id,
version: node.version,
modulePath: node.path,
configPath: node.configPath,
configuration: node.configuration,
shimCollection,
});

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

return {
node,
project,
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