Skip to content

Commit

Permalink
feat(misc): add ability to run graph in any workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jun 9, 2022
1 parent 99b245b commit e8cfa35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 4 additions & 2 deletions packages/nx/bin/nx.ts
Expand Up @@ -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');
}
Expand Down
12 changes: 3 additions & 9 deletions packages/nx/src/utils/find-workspace-root.ts
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/utils/workspace-root.ts
Expand Up @@ -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.
Expand All @@ -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'))) {
Expand Down

0 comments on commit e8cfa35

Please sign in to comment.