Skip to content

Commit

Permalink
fix(core): use cwd for locating workspace root
Browse files Browse the repository at this point in the history
Closes nrwl#3484
Closes nrwl#3909
  • Loading branch information
bekos authored and tinesoft committed Nov 1, 2020
1 parent e420b8a commit d6657ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 45 deletions.
39 changes: 35 additions & 4 deletions packages/cli/bin/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,45 @@
// polyfill rxjs observable to avoid issues with multiple version fo Observable installed in node_modules
// https://twitter.com/BenLesh/status/1192478226385428483?s=20
(Symbol as any).observable = Symbol('observable polyfill');
import chalk from 'chalk';
import { findWorkspaceRoot } from '../lib/find-workspace-root';
import { initGlobal } from '../lib/init-global';
import { initLocal } from '../lib/init-local';
import { output } from '../lib/output';

const workspace = findWorkspaceRoot(__dirname);
const workspace = findWorkspaceRoot(process.cwd());

if (workspace) {
if (!workspace) {
output.log({
title: `The current directory isn't part of an Nx workspace.`,
bodyLines: [
`To create a workspace run:`,
chalk.bold.white(`npx create-nx-workspace@latest <workspace name>`),
],
});

output.note({
title: `For more information please visit https://nx.dev/`,
});
process.exit(1);
}

// Make sure that a local copy of Nx exists in workspace
let localNx: string;
try {
localNx = require.resolve('@nrwl/cli/bin/nx.js', {
paths: [workspace.dir],
});
} catch (e) {
output.error({
title: `Could not find Nx modules in this workspace.`,
bodyLines: [`Have you run ${chalk.bold.white(`npm/yarn install`)}?`],
});
process.exit(1);
}

if (localNx === require.resolve('@nrwl/cli/bin/nx.js')) {
initLocal(workspace);
} else {
initGlobal();
// Nx is being run from globally installed CLI - hand off to the local
require(localNx);
}
41 changes: 0 additions & 41 deletions packages/cli/lib/init-global.ts

This file was deleted.

0 comments on commit d6657ad

Please sign in to comment.