Skip to content

Commit

Permalink
fix(nx-plugin): allow async project graph processors (nrwl#10026)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Apr 28, 2022
1 parent ff04dff commit 3ffa7f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ export interface ProjectGraphProcessorContext {
export type ProjectGraphProcessor = (
currentGraph: ProjectGraph,
context: ProjectGraphProcessorContext
) => ProjectGraph;
) => ProjectGraph | Promise<ProjectGraph>;
13 changes: 7 additions & 6 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async function buildProjectGraphUsingContext(
builder.setVersion(projectGraphVersion);
const initProjectGraph = builder.getUpdatedProjectGraph();

const r = updateProjectGraphWithPlugins(ctx, initProjectGraph);
const r = await updateProjectGraphWithPlugins(ctx, initProjectGraph);

performance.mark('build project graph:end');
performance.measure(
Expand Down Expand Up @@ -372,16 +372,17 @@ function createContext(
};
}

function updateProjectGraphWithPlugins(
async function updateProjectGraphWithPlugins(
context: ProjectGraphProcessorContext,
initProjectGraph: ProjectGraph
) {
const plugins = loadNxPlugins(context.workspace.plugins).filter(
(x) => !!x.processProjectGraph
);
return (plugins || []).reduce((graph, plugin) => {
let graph = initProjectGraph;
for (const plugin of plugins) {
try {
return plugin.processProjectGraph(graph, context);
graph = await plugin.processProjectGraph(graph, context);
} catch (e) {
const message = `Failed to process the project graph with "${plugin.name}". This will error in the future!`;
if (process.env.NX_VERBOSE_LOGGING === 'true') {
Expand All @@ -392,9 +393,9 @@ function updateProjectGraphWithPlugins(
logger.warn(message);
logger.warn(`Run with NX_VERBOSE_LOGGING=true to see the error.`);
}
return graph;
}
}, initProjectGraph);
}
return graph;
}

function readRootTsConfig() {
Expand Down

0 comments on commit 3ffa7f8

Please sign in to comment.