fix(core): detect angular cli workspace correctly (#13574)

This commit is contained in:
Leosvel Pérez Espinosa 2022-12-02 20:45:11 +01:00 committed by GitHub
parent 2eb8650df8
commit 59a7af2c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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