Skip to content

Commit

Permalink
feat(core): run createDependencies plugins concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Sep 15, 2023
1 parent a906d91 commit 6f3dd61
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ function createContext(
}

async function updateProjectGraphWithPlugins(
context: ProjectGraphProcessorContext,
projectGraphProcessorContext: ProjectGraphProcessorContext,
initProjectGraph: ProjectGraph
) {
const plugins = await loadNxPlugins(context.nxJsonConfiguration?.plugins);
const plugins = await loadNxPlugins(
projectGraphProcessorContext.nxJsonConfiguration?.plugins
);
let graph = initProjectGraph;
for (const plugin of plugins) {
try {
Expand All @@ -229,7 +231,10 @@ async function updateProjectGraphWithPlugins(
// 'Nx has recently released a v2 model for project graph plugins. The `processProjectGraph` method is deprecated. Plugins should use some combination of `createNodes` and `createDependencies` instead.',
// ],
// });
graph = await plugin.processProjectGraph(graph, context);
graph = await plugin.processProjectGraph(
graph,
projectGraphProcessorContext
);
}
} catch (e) {
let message = `Failed to process the project graph with "${plugin.name}".`;
Expand All @@ -240,40 +245,48 @@ async function updateProjectGraphWithPlugins(
throw new Error(message);
}
}
for (const plugin of plugins) {
try {
if (isNxPluginV2(plugin) && plugin.createDependencies) {
const builder = new ProjectGraphBuilder(graph, context.fileMap);
const newDependencies = await plugin.createDependencies({
externalNodes: graph.externalNodes,
fileMap: context.fileMap,
filesToProcess: context.filesToProcess,
nxJsonConfiguration: context.nxJsonConfiguration,
projects: context.projectsConfigurations.projects,
workspaceRoot: workspaceRoot,

const createDependencyPlugins = plugins.filter(
(plugin) => isNxPluginV2(plugin) && plugin.createDependencies
);
const createDependenciesContext = {
externalNodes: graph.externalNodes,
fileMap: projectGraphProcessorContext.fileMap,
filesToProcess: projectGraphProcessorContext.filesToProcess,
nxJsonConfiguration: projectGraphProcessorContext.nxJsonConfiguration,
projects: projectGraphProcessorContext.projectsConfigurations.projects,
workspaceRoot: workspaceRoot,
};
const builder = new ProjectGraphBuilder(
graph,
projectGraphProcessorContext.fileMap
);
await Promise.all(
createDependencyPlugins.map(async (plugin) => {
try {
const dependencies = await plugin.createDependencies({
...createDependenciesContext,
});
for (const targetProjectDependency of newDependencies) {

for (const dep of dependencies) {
builder.addDependency(
targetProjectDependency.source,
targetProjectDependency.target,
targetProjectDependency.type,
'sourceFile' in targetProjectDependency
? targetProjectDependency.sourceFile
: null
dep.source,
dep.target,
dep.type,
'sourceFile' in dep ? dep.sourceFile : null
);
}
graph = builder.getUpdatedProjectGraph();
}
} catch (e) {
let message = `Failed to process project dependencies with "${plugin.name}".`;
if (e instanceof Error) {
e.message = message + '\n' + e.message;
throw e;
} catch (e) {
let message = `Failed to process project dependencies with "${plugin.name}".`;
if (e instanceof Error) {
e.message = message + '\n' + e.message;
throw e;
}
throw new Error(message);
}
throw new Error(message);
}
}
return graph;
})
);
return builder.getUpdatedProjectGraph();
}

function readRootTsConfig() {
Expand Down

0 comments on commit 6f3dd61

Please sign in to comment.