Skip to content

Commit

Permalink
[INTERNAL] helpers/ui5Framework: Enhance test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Dec 8, 2022
1 parent ef010a9 commit 7847b89
Show file tree
Hide file tree
Showing 2 changed files with 403 additions and 28 deletions.
39 changes: 21 additions & 18 deletions lib/graph/helpers/ui5Framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@ import logger from "@ui5/logger";
const log = logger.getLogger("graph:helpers:ui5Framework");

class ProjectProcessor {
constructor({libraryMetadata, workspace}) {
constructor({libraryMetadata, graph, workspace}) {
this._libraryMetadata = libraryMetadata;
this._graph = graph;
this._workspace = workspace;
this._projectGraphPromises = Object.create(null);
}
async addProjectToGraph(libName, projectGraph) {
async addProjectToGraph(libName) {
if (this._projectGraphPromises[libName]) {
return this._projectGraphPromises[libName];
}
return this._projectGraphPromises[libName] = this._addProjectToGraph(libName, projectGraph);
return this._projectGraphPromises[libName] = this._addProjectToGraph(libName);
}
async _addProjectToGraph(libName, projectGraph) {
async _addProjectToGraph(libName) {
log.verbose(`Creating project for library ${libName}...`);


if (!this._libraryMetadata[libName]) {
throw new Error(`Failed to find library ${libName} in dist packages metadata.json`);
}

const depMetadata = this._libraryMetadata[libName];
const graph = this._graph;

if (projectGraph.getProject(depMetadata.id)) {
if (graph.getProject(libName)) {
// Already added
return;
}

const dependencies = await Promise.all(depMetadata.dependencies.map(async (depName) => {
await this.addProjectToGraph(depName, projectGraph);
await this.addProjectToGraph(depName, graph);
return depName;
}));

if (depMetadata.optionalDependencies) {
const resolvedOptionals = await Promise.all(depMetadata.optionalDependencies.map(async (depName) => {
if (this._libraryMetadata[depName]) {
log.verbose(`Resolving optional dependency ${depName} for project ${libName}...`);
await this.addProjectToGraph(depName, projectGraph);
await this.addProjectToGraph(depName, graph);
return depName;
}
}));
Expand All @@ -65,9 +66,9 @@ class ProjectProcessor {
});
}
const {project} = await ui5Module.getSpecifications();
projectGraph.addProject(project);
graph.addProject(project);
dependencies.forEach((dependency) => {
projectGraph.declareDependency(libName, dependency);
graph.declareDependency(libName, dependency);
});
if (projectIsFromWorkspace) {
// Add any dependencies that are only declared in the workspace resolved project
Expand All @@ -83,13 +84,13 @@ class ProjectProcessor {
throw new Error(
`Unable to find dependency ${name}, required by project ${project.getName()} ` +
`(resolved via ${this._workspace.getName()} workspace) in current set of libraries. ` +
`Try adding it temporarily to the root project's dependencies.`);
`Try adding it temporarily to the root project's dependencies`);
}

// TODO: If a cyclic dependency is declared, this will empty the event loop.
// I guess this is a general issue and not limited to projects resolved via workspaces
await this.addProjectToGraph(name, projectGraph);
projectGraph.declareDependency(libName, name);
await this.addProjectToGraph(name, graph);
graph.declareDependency(libName, name);
}));
}
}
Expand Down Expand Up @@ -166,7 +167,7 @@ export default {
* @param {@ui5/project/graph/ProjectGraph} projectGraph
* @param {object} [options]
* @param {string} [options.versionOverride] Framework version to use instead of the root projects framework
* version from the provided <code>tree</code>
* version
* @param {@ui5/project/graph/Workspace} [options.workspace]
* Optional workspace instance to use for overriding node resolutions
* @returns {Promise<@ui5/project/graph/ProjectGraph>}
Expand Down Expand Up @@ -249,16 +250,18 @@ export default {
`resolved in ${prettyHrtime(timeDiff)}`);
}

const frameworkGraph = new ProjectGraph({
rootProjectName: `fake-root-of-${rootProject.getName()}-framework-dependency-graph`
});

const projectProcessor = new utils.ProjectProcessor({
libraryMetadata,
graph: frameworkGraph,
workspace: options.workspace
});

const frameworkGraph = new ProjectGraph({
rootProjectName: `fake-root-of-${rootProject.getName()}-framework-dependency-graph`
});
await Promise.all(referencedLibraries.map(async (libName) => {
await projectProcessor.addProjectToGraph(libName, frameworkGraph);
await projectProcessor.addProjectToGraph(libName);
}));

log.verbose("Joining framework graph into project graph...");
Expand Down
Loading

0 comments on commit 7847b89

Please sign in to comment.