diff --git a/libs/shared/workspace/src/lib/get-nx-workspace-config.ts b/libs/shared/workspace/src/lib/get-nx-workspace-config.ts index d4de89b7e3..413a6f30ad 100644 --- a/libs/shared/workspace/src/lib/get-nx-workspace-config.ts +++ b/libs/shared/workspace/src/lib/get-nx-workspace-config.ts @@ -64,10 +64,18 @@ export async function getNxWorkspaceConfig( throw 'No project graph support'; } + process.exit = function (code?: number) { + console.warn('process.exit called with code', code); + } as (code?: number) => never; + if (version < 13) { projectGraph = (nxProjectGraph as any).createProjectGraph(); } else { - projectGraph = await nxProjectGraph.createProjectGraphAsync(); + // TODO(cammisuli): Remove `any` when upgrading to Nx 14.7+ + projectGraph = await (nxProjectGraph as any).createProjectGraphAsync({ + exitOnError: false, + resetDaemonClient: true, + }); } } catch { //noop diff --git a/libs/shared/workspace/src/lib/workspace.ts b/libs/shared/workspace/src/lib/workspace.ts index 99bbb47b50..de659db83a 100644 --- a/libs/shared/workspace/src/lib/workspace.ts +++ b/libs/shared/workspace/src/lib/workspace.ts @@ -1,5 +1,6 @@ import { checkIsNxWorkspace, + formatError, toWorkspaceFormat, } from '@nx-console/shared/utils'; @@ -42,6 +43,14 @@ const enum Status { let cachedReplay = new ReplaySubject(); let status: Status = Status.not_started; +function resetStatus(workspacePath: string) { + status = Status.not_started; + cachedReplay = new ReplaySubject(); + // Clear out the workspace config path, needed for angular or older nx workspaces + clearJsonCache('angular.json', workspacePath); + clearJsonCache('workspace.json', workspacePath); +} + export async function nxWorkspace( workspacePath: string, logger: Logger = { @@ -52,11 +61,7 @@ export async function nxWorkspace( reset?: boolean ): Promise { if (reset) { - status = Status.not_started; - cachedReplay = new ReplaySubject(); - // Clear out the workspace config path, needed for angular or older nx workspaces - clearJsonCache('angular.json', workspacePath); - clearJsonCache('workspace.json', workspacePath); + resetStatus(workspacePath); } return firstValueFrom( @@ -85,16 +90,16 @@ async function _workspace( join(workspacePath, 'angular.json') ); const isNxWorkspace = await checkIsNxWorkspace(workspacePath); - const config = await getNxWorkspaceConfig( - workspacePath, - isAngularWorkspace ? 'angularCli' : 'nx', - isNxWorkspace, - logger - ); - - const isLerna = await fileExists(join(workspacePath, 'lerna.json')); try { + const config = await getNxWorkspaceConfig( + workspacePath, + isAngularWorkspace ? 'angularCli' : 'nx', + isNxWorkspace, + logger + ); + + const isLerna = await fileExists(join(workspacePath, 'lerna.json')); return { validWorkspaceJson: true, workspaceType: isAngularWorkspace ? 'ng' : 'nx', @@ -114,10 +119,7 @@ async function _workspace( workspacePath, }; } catch (e) { - const humanReadableError = 'Invalid workspace: ' + workspacePath; - logger?.log(humanReadableError); - const stringifiedError = e.toString ? e.toString() : JSON.stringify(e); - logger?.log(stringifiedError); + logger.log(formatError('Invalid workspace', e)); // Default to nx workspace return {