Revert "fix(core): add warning if running on an outdated global insta… (#15442)

This commit is contained in:
Craigory Coppola 2023-03-03 21:12:28 -05:00 committed by GitHub
parent 9cec533c52
commit 1eee5f04b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 227 deletions

View File

@ -1153,14 +1153,6 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Managing your Global Nx Installation",
"path": "/more-concepts/global-nx",
"id": "global-nx",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
@ -1325,14 +1317,6 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Managing your Global Nx Installation",
"path": "/more-concepts/global-nx",
"id": "global-nx",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "All Recipes »",
"path": "/recipes",

View File

@ -1434,16 +1434,6 @@
"isExternal": false,
"path": "/more-concepts/encapsulated-nx-and-the-wrapper",
"tags": []
},
{
"id": "global-nx",
"name": "Managing your Global Nx Installation",
"description": "",
"file": "shared/guides/global-nx",
"itemList": [],
"isExternal": false,
"path": "/more-concepts/global-nx",
"tags": []
}
],
"isExternal": false,
@ -1650,16 +1640,6 @@
"path": "/more-concepts/encapsulated-nx-and-the-wrapper",
"tags": []
},
"/more-concepts/global-nx": {
"id": "global-nx",
"name": "Managing your Global Nx Installation",
"description": "",
"file": "shared/guides/global-nx",
"itemList": [],
"isExternal": false,
"path": "/more-concepts/global-nx",
"tags": []
},
"/recipes": {
"id": "all",
"name": "All Recipes »",

View File

@ -489,11 +489,6 @@
"name": "Encapsulated Nx and the Nx Wrapper",
"id": "encapsulated-nx-and-the-wrapper",
"file": "shared/guides/encapsulated-nx-and-the-wrapper"
},
{
"name": "Managing your Global Nx Installation",
"id": "global-nx",
"file": "shared/guides/global-nx"
}
]
},

View File

@ -1,122 +0,0 @@
# Managing your Global Nx Installation
Nx can be ran in a total of 3 ways:
- Through your package manager (e.g. `npx nx`, `yarn nx`, or `pnpm exec nx`)
- Through an [encapsulated install](/more-concepts/encapsulated-nx-and-the-wrapper) (e.g. `./nx` or `./nx.bat`)
- Through a global Nx installation (e.g. `nx`)
With a global Nx installation, Nx looks for the local copy of Nx in your repo and hands off the process execution to it. This means that whichever version of Nx is installed locally in your repo is still the version of Nx that runs your code. For the most part, this can eliminate any issues that may arise from the global install being outdated.
However, there are still cases where an issue could arise. If the structure of your Nx workspace no longer matches up with what the globally installed copy of Nx expects, it may fail to hand off to your local installation properly and instead error. This commonly results in errors such as:
- Could not find Nx modules in this workspace.
- The current directory isn't part of an Nx workspace.
If you find yourself in this position, you will need to update your global install of Nx.
## Updating your global Nx installation
Exactly how you do this will depend on which package manager you originally installed Nx with.
{% tabs %}
{% tab label="npm" %}
```shell
npm install --global nx@latest
```
{% /tab %}
{% tab label="yarn" %}
```shell
yarn global add nx@latest
```
{% /tab %}
{% tab label="pnpm" %}
```shell
pnpm install --global nx@latest
```
{% /tab %}
{% /tabs %}
If you cannot remember which package manager you installed Nx globally with or are still encountering issues, you can locate other installs of Nx with these commands:
{% tabs %}
{% tab label="npm" %}
```shell
npm list --global nx
```
{% /tab %}
{% tab label="yarn" %}
```shell
yarn global list nx
```
{% /tab %}
{% tab label="pnpm" %}
```shell
pnpm list --global nx
```
{% /tab %}
{% /tabs %}
You can then remove the extra global installations by running the following commands for the duplicate installations:
{% tabs %}
{% tab label="npm" %}
```shell
npm rm --global nx
```
{% /tab %}
{% tab label="yarn" %}
```shell
yarn global remove nx
```
{% /tab %}
{% tab label="pnpm" %}
```shell
pnpm rm --global nx
```
{% /tab %}
{% /tabs %}
Finally, to complete your global installation update, simply reinstall it with the package manager of your choosing:
{% tabs %}
{% tab label="npm" %}
```shell
npm install --global nx@latest
```
{% /tab %}
{% tab label="yarn" %}
```shell
yarn global add nx@latest
```
{% /tab %}
{% tab label="pnpm" %}
```shell
pnpm install --global nx@latest
```
{% /tab %}
{% /tabs %}

View File

@ -6,13 +6,7 @@ import {
import * as chalk from 'chalk';
import { initLocal } from './init-local';
import { output } from '../src/utils/output';
import {
getNxInstallationPath,
getNxRequirePaths,
} from '../src/utils/installation-directory';
import { major } from 'semver';
import { readJsonFile } from '../src/utils/fileutils';
import { execSync } from 'child_process';
import { getNxInstallationPath } from 'nx/src/utils/installation-directory';
const workspace = findWorkspaceRoot(process.cwd());
// new is a special case because there is no local workspace to load
@ -59,8 +53,6 @@ if (
try {
localNx = resolveNx(workspace);
} catch {
// If we can't resolve a local copy of Nx, we must be global.
warnIfUsingOutdatedGlobalInstall();
output.error({
title: `Could not find Nx modules in this workspace.`,
bodyLines: [`Have you run ${chalk.bold.white(`npm/yarn install`)}?`],
@ -77,7 +69,6 @@ if (
initLocal(workspace);
} else {
// Nx is being run from globally installed CLI - hand off to the local
warnIfUsingOutdatedGlobalInstall(getLocalNxVersion(workspace));
require(localNx);
}
}
@ -102,57 +93,3 @@ function resolveNx(workspace: WorkspaceTypeAndRoot | null) {
});
}
}
/**
* Assumes currently running Nx is global install.
* Warns if out of date by 1 major version or more.
*/
function warnIfUsingOutdatedGlobalInstall(localNxVersion?: string) {
const globalVersion = require('../package.json').version;
const isOutdatedGlobalInstall =
globalVersion &&
((localNxVersion && major(globalVersion) < major(localNxVersion)) ||
(getLatestVersionOfNx() &&
major(globalVersion) < major(getLatestVersionOfNx())));
// Using a global Nx Install
if (isOutdatedGlobalInstall) {
const bodyLines = localNxVersion
? ['Its time to update Nx 🎉']
: [
'Its possible that this is causing Nx to not pick up your workspace properly.',
];
bodyLines.push(
'For more information, see https://nx.dev/more-concepts/global-nx'
);
output.warn({
title: `Its time to update Nx 🎉`,
bodyLines,
});
}
}
function getLocalNxVersion(workspace: WorkspaceTypeAndRoot): string {
return readJsonFile(
require.resolve('nx/package.json', {
paths: getNxRequirePaths(workspace.dir),
})
).version;
}
let _latest = null;
function getLatestVersionOfNx(): string {
if (!_latest) {
try {
_latest = execSync('npm view nx@latest version').toString().trim();
} catch {
try {
_latest = execSync('pnpm view nx@latest version').toString().trim();
} catch {
_latest = null;
}
}
}
return _latest;
}