feat(misc): add ability to run graph in any workspace

This commit is contained in:
Victor Savkin 2022-06-08 21:19:26 -04:00
parent 99b245b08d
commit e8cfa35e82
3 changed files with 9 additions and 13 deletions

View File

@ -8,15 +8,17 @@ import { initLocal } from './init-local';
import { detectPackageManager } from '../src/utils/package-manager';
import { output } from '../src/utils/output';
const workspace = findWorkspaceRoot(process.cwd());
// new is a special case because there is no local workspace to load
if (
process.argv[2] === 'new' ||
process.argv[2] === '_migrate' ||
process.argv[2] === 'init'
process.argv[2] === 'init' ||
(process.argv[2] === 'graph' && !workspace)
) {
process.env.NX_DAEMON = 'false';
require('nx/src/command-line/nx-commands').commandsObject.argv;
} else {
const workspace = findWorkspaceRoot(process.cwd());
if (workspace && workspace.type === 'nx') {
require('v8-compile-cache');
}

View File

@ -11,19 +11,13 @@ import { workspaceRootInner } from './workspace-root';
export function findWorkspaceRoot(dir: string): WorkspaceTypeAndRoot | null {
const r = workspaceRootInner(dir, null);
if (r === null) return null;
if (existsSync(path.join(r, 'angular.json'))) {
return { type: 'angular', dir: r };
}
if (existsSync(path.join(r, 'nx.json'))) {
} else {
return { type: 'nx', dir: r };
}
if (existsSync(path.join(r, 'node_modules', 'nx', 'package.json'))) {
return { type: 'nx', dir: r };
}
return null;
}
export interface WorkspaceTypeAndRoot {

View File

@ -4,7 +4,7 @@ import { fileExists } from './fileutils';
/**
* The root of the workspace
*/
export const workspaceRoot = workspaceRootInner(__dirname, null);
export const workspaceRoot = workspaceRootInner(process.cwd(), process.cwd());
/**
* The root of the workspace.
@ -19,7 +19,7 @@ export function workspaceRootInner(
): string {
if (process.env.NX_WORKSPACE_ROOT_PATH)
return process.env.NX_WORKSPACE_ROOT_PATH;
if (path.dirname(dir) === dir) return candidateRoot || process.cwd();
if (path.dirname(dir) === dir) return candidateRoot;
if (fileExists(path.join(dir, 'nx.json'))) {
return dir;
} else if (fileExists(path.join(dir, 'node_modules', 'nx', 'package.json'))) {