Skip to content

Commit

Permalink
fix(core): properly cleanup when the project-graph creation fails (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Mar 8, 2024
1 parent 650dcf3 commit 235ca8c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
13 changes: 8 additions & 5 deletions packages/nx/bin/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { readNxJson } from '../src/config/nx-json';
import { setupWorkspaceContext } from '../src/utils/workspace-context';

(async () => {
const start = new Date();
try {
setupWorkspaceContext(workspaceRoot);
if (isMainNxPackage() && fileExists(join(workspaceRoot, 'nx.json'))) {
const b = new Date();
assertSupportedPlatform();

try {
Expand All @@ -35,15 +35,18 @@ import { setupWorkspaceContext } from '../src/utils/workspace-context';
});
})
);
if (process.env.NX_VERBOSE_LOGGING === 'true') {
const a = new Date();
console.log(`Nx postinstall steps took ${a.getTime() - b.getTime()}ms`);
}
}
} catch (e) {
if (process.env.NX_VERBOSE_LOGGING === 'true') {
console.log(e);
}
} finally {
if (process.env.NX_VERBOSE_LOGGING === 'true') {
const end = new Date();
console.log(
`Nx postinstall steps took ${end.getTime() - start.getTime()}ms`
);
}
}
})();

Expand Down
60 changes: 31 additions & 29 deletions packages/nx/src/project-graph/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,37 @@ export async function buildProjectGraphAndSourceMapsWithoutDaemon() {
const nxJson = readNxJson();

const [plugins, cleanup] = await loadNxPluginsInIsolation(nxJson.plugins);

performance.mark('retrieve-project-configurations:start');
const { projects, externalNodes, sourceMaps, projectRootMap } =
await retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
performance.mark('retrieve-project-configurations:end');

performance.mark('retrieve-workspace-files:start');
const { allWorkspaceFiles, fileMap, rustReferences } =
await retrieveWorkspaceFiles(workspaceRoot, projectRootMap);
performance.mark('retrieve-workspace-files:end');

const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
performance.mark('build-project-graph-using-project-file-map:start');
const projectGraph = (
await buildProjectGraphUsingProjectFileMap(
projects,
externalNodes,
fileMap,
allWorkspaceFiles,
rustReferences,
cacheEnabled ? readFileMapCache() : null,
cacheEnabled,
plugins
)
).projectGraph;
performance.mark('build-project-graph-using-project-file-map:end');
delete global.NX_GRAPH_CREATION;
cleanup();
return { projectGraph, sourceMaps };
try {
performance.mark('retrieve-project-configurations:start');
const { projects, externalNodes, sourceMaps, projectRootMap } =
await retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
performance.mark('retrieve-project-configurations:end');

performance.mark('retrieve-workspace-files:start');
const { allWorkspaceFiles, fileMap, rustReferences } =
await retrieveWorkspaceFiles(workspaceRoot, projectRootMap);
performance.mark('retrieve-workspace-files:end');

const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
performance.mark('build-project-graph-using-project-file-map:start');
const projectGraph = (
await buildProjectGraphUsingProjectFileMap(
projects,
externalNodes,
fileMap,
allWorkspaceFiles,
rustReferences,
cacheEnabled ? readFileMapCache() : null,
cacheEnabled,
plugins
)
).projectGraph;
performance.mark('build-project-graph-using-project-file-map:end');
delete global.NX_GRAPH_CREATION;
return { projectGraph, sourceMaps };
} finally {
cleanup();
}
}

function handleProjectGraphError(opts: { exitOnError: boolean }, e) {
Expand Down

0 comments on commit 235ca8c

Please sign in to comment.