Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): use cwd for locating workspace root #3998

Merged
merged 1 commit into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.