Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset the daemon client when getting the project graph #1363

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion libs/shared/workspace/src/lib/get-nx-workspace-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 19 additions & 17 deletions libs/shared/workspace/src/lib/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
checkIsNxWorkspace,
formatError,
toWorkspaceFormat,
} from '@nx-console/shared/utils';

Expand Down Expand Up @@ -42,6 +43,14 @@ const enum Status {
let cachedReplay = new ReplaySubject<NxWorkspace>();
let status: Status = Status.not_started;

function resetStatus(workspacePath: string) {
status = Status.not_started;
cachedReplay = new ReplaySubject<NxWorkspace>();
// 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 = {
Expand All @@ -52,11 +61,7 @@ export async function nxWorkspace(
reset?: boolean
): Promise<NxWorkspace> {
if (reset) {
status = Status.not_started;
cachedReplay = new ReplaySubject<NxWorkspace>();
// 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(
Expand Down Expand Up @@ -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',
Expand All @@ -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 {
Expand Down