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 #3484
Closes #3909
  • Loading branch information
bekos committed Oct 30, 2020
1 parent 34d156d commit d7a51d5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
40 changes: 36 additions & 4 deletions packages/cli/bin/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,46 @@
// 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);
}

// Find local Nx of workspace
let localNx: string;
try {
localNx = require.resolve('@nrwl/cli/bin/nx.js', {
paths: [workspace.dir],
});
require(localNx);
} 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 d7a51d5

Please sign in to comment.