diff --git a/packages/nx/src/utils/find-workspace-root.ts b/packages/nx/src/utils/find-workspace-root.ts index ca6fbb6274..44dcd90d7a 100644 --- a/packages/nx/src/utils/find-workspace-root.ts +++ b/packages/nx/src/utils/find-workspace-root.ts @@ -1,5 +1,3 @@ -import { existsSync } from 'fs'; -import * as path from 'path'; import { workspaceRootInner } from './workspace-root'; /** @@ -13,7 +11,7 @@ export function findWorkspaceRoot(dir: string): WorkspaceTypeAndRoot | null { if (r === null) return null; - if (existsSync(path.join(r, 'angular.json'))) { + if (isAngularCliInstalled(r)) { return { type: 'angular', dir: r }; } else { return { type: 'nx', dir: r }; @@ -24,3 +22,14 @@ export interface WorkspaceTypeAndRoot { type: 'nx' | 'angular'; dir: string; } + +function isAngularCliInstalled(root: string): boolean { + try { + require.resolve('@angular/cli', { + paths: [root], + }); + return true; + } catch { + return false; + } +}