From 59a7af2c98a7204d580f2f2819c4a8accc3cd98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Fri, 2 Dec 2022 20:45:11 +0100 Subject: [PATCH] fix(core): detect angular cli workspace correctly (#13574) --- packages/nx/src/utils/find-workspace-root.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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; + } +}