@@ -6,13 +6,7 @@ import {
66import * as chalk from 'chalk' ;
77import { initLocal } from './init-local' ;
88import { output } from '../src/utils/output' ;
9- import {
10- getNxInstallationPath ,
11- getNxRequirePaths ,
12- } from '../src/utils/installation-directory' ;
13- import { major } from 'semver' ;
14- import { readJsonFile } from '../src/utils/fileutils' ;
15- import { execSync } from 'child_process' ;
9+ import { getNxInstallationPath } from 'nx/src/utils/installation-directory' ;
1610
1711const workspace = findWorkspaceRoot ( process . cwd ( ) ) ;
1812// new is a special case because there is no local workspace to load
5953 try {
6054 localNx = resolveNx ( workspace ) ;
6155 } catch {
62- // If we can't resolve a local copy of Nx, we must be global.
63- warnIfUsingOutdatedGlobalInstall ( ) ;
6456 output . error ( {
6557 title : `Could not find Nx modules in this workspace.` ,
6658 bodyLines : [ `Have you run ${ chalk . bold . white ( `npm/yarn install` ) } ?` ] ,
7769 initLocal ( workspace ) ;
7870 } else {
7971 // Nx is being run from globally installed CLI - hand off to the local
80- warnIfUsingOutdatedGlobalInstall ( getLocalNxVersion ( workspace ) ) ;
8172 require ( localNx ) ;
8273 }
8374}
@@ -102,57 +93,3 @@ function resolveNx(workspace: WorkspaceTypeAndRoot | null) {
10293 } ) ;
10394 }
10495}
105-
106- /**
107- * Assumes currently running Nx is global install.
108- * Warns if out of date by 1 major version or more.
109- */
110- function warnIfUsingOutdatedGlobalInstall ( localNxVersion ?: string ) {
111- const globalVersion = require ( '../package.json' ) . version ;
112- const isOutdatedGlobalInstall =
113- globalVersion &&
114- ( ( localNxVersion && major ( globalVersion ) < major ( localNxVersion ) ) ||
115- ( getLatestVersionOfNx ( ) &&
116- major ( globalVersion ) < major ( getLatestVersionOfNx ( ) ) ) ) ;
117-
118- // Using a global Nx Install
119- if ( isOutdatedGlobalInstall ) {
120- const bodyLines = localNxVersion
121- ? [ 'Its time to update Nx 🎉' ]
122- : [
123- 'Its possible that this is causing Nx to not pick up your workspace properly.' ,
124- ] ;
125-
126- bodyLines . push (
127- 'For more information, see https://nx.dev/more-concepts/global-nx'
128- ) ;
129- output . warn ( {
130- title : `Its time to update Nx 🎉` ,
131- bodyLines,
132- } ) ;
133- }
134- }
135-
136- function getLocalNxVersion ( workspace : WorkspaceTypeAndRoot ) : string {
137- return readJsonFile (
138- require . resolve ( 'nx/package.json' , {
139- paths : getNxRequirePaths ( workspace . dir ) ,
140- } )
141- ) . version ;
142- }
143-
144- let _latest = null ;
145- function getLatestVersionOfNx ( ) : string {
146- if ( ! _latest ) {
147- try {
148- _latest = execSync ( 'npm view nx@latest version' ) . toString ( ) . trim ( ) ;
149- } catch {
150- try {
151- _latest = execSync ( 'pnpm view nx@latest version' ) . toString ( ) . trim ( ) ;
152- } catch {
153- _latest = null ;
154- }
155- }
156- }
157- return _latest ;
158- }
0 commit comments