@@ -14,71 +14,73 @@ import { major } from 'semver';
14
14
import { readJsonFile } from '../src/utils/fileutils' ;
15
15
import { execSync } from 'child_process' ;
16
16
17
- const workspace = findWorkspaceRoot ( process . cwd ( ) ) ;
18
- // new is a special case because there is no local workspace to load
19
- if (
20
- process . argv [ 2 ] === 'new' ||
21
- process . argv [ 2 ] === '_migrate' ||
22
- process . argv [ 2 ] === 'init' ||
23
- ( process . argv [ 2 ] === 'graph' && ! workspace )
24
- ) {
25
- process . env . NX_DAEMON = 'false' ;
26
- require ( 'nx/src/command-line/nx-commands' ) . commandsObject . argv ;
27
- } else {
28
- if ( workspace && workspace . type === 'nx' ) {
29
- require ( 'v8-compile-cache' ) ;
30
- }
31
- // polyfill rxjs observable to avoid issues with multiple version of Observable installed in node_modules
32
- // https://twitter.com/BenLesh/status/1192478226385428483?s=20
33
- if ( ! ( Symbol as any ) . observable )
34
- ( Symbol as any ) . observable = Symbol ( 'observable polyfill' ) ;
17
+ function main ( ) {
18
+ const workspace = findWorkspaceRoot ( process . cwd ( ) ) ;
19
+ // new is a special case because there is no local workspace to load
20
+ if (
21
+ process . argv [ 2 ] === 'new' ||
22
+ process . argv [ 2 ] === '_migrate' ||
23
+ process . argv [ 2 ] === 'init' ||
24
+ ( process . argv [ 2 ] === 'graph' && ! workspace )
25
+ ) {
26
+ process . env . NX_DAEMON = 'false' ;
27
+ require ( 'nx/src/command-line/nx-commands' ) . commandsObject . argv ;
28
+ } else {
29
+ if ( workspace && workspace . type === 'nx' ) {
30
+ require ( 'v8-compile-cache' ) ;
31
+ }
32
+ // polyfill rxjs observable to avoid issues with multiple version of Observable installed in node_modules
33
+ // https://twitter.com/BenLesh/status/1192478226385428483?s=20
34
+ if ( ! ( Symbol as any ) . observable )
35
+ ( Symbol as any ) . observable = Symbol ( 'observable polyfill' ) ;
35
36
36
- if ( ! workspace ) {
37
- output . log ( {
38
- title : `The current directory isn't part of an Nx workspace.` ,
39
- bodyLines : [
40
- `To create a workspace run:` ,
41
- chalk . bold . white ( `npx create-nx-workspace@latest <workspace name>` ) ,
42
- '' ,
43
- `To add Nx to existing workspace run with a workspace-specific nx.json:` ,
44
- chalk . bold . white ( `npx add-nx-to-monorepo@latest` ) ,
45
- '' ,
46
- `To add the default nx.json file run:` ,
47
- chalk . bold . white ( `nx init` ) ,
48
- ] ,
49
- } ) ;
37
+ if ( ! workspace ) {
38
+ output . log ( {
39
+ title : `The current directory isn't part of an Nx workspace.` ,
40
+ bodyLines : [
41
+ `To create a workspace run:` ,
42
+ chalk . bold . white ( `npx create-nx-workspace@latest <workspace name>` ) ,
43
+ '' ,
44
+ `To add Nx to existing workspace run with a workspace-specific nx.json:` ,
45
+ chalk . bold . white ( `npx add-nx-to-monorepo@latest` ) ,
46
+ '' ,
47
+ `To add the default nx.json file run:` ,
48
+ chalk . bold . white ( `nx init` ) ,
49
+ ] ,
50
+ } ) ;
50
51
51
- output . note ( {
52
- title : `For more information please visit https://nx.dev/` ,
53
- } ) ;
54
- process . exit ( 1 ) ;
55
- }
52
+ output . note ( {
53
+ title : `For more information please visit https://nx.dev/` ,
54
+ } ) ;
55
+ process . exit ( 1 ) ;
56
+ }
56
57
57
- // Make sure that a local copy of Nx exists in workspace
58
- let localNx : string ;
59
- try {
60
- localNx = resolveNx ( workspace ) ;
61
- } catch {
62
- // If we can't resolve a local copy of Nx, we must be global.
63
- warnIfUsingOutdatedGlobalInstall ( ) ;
64
- output . error ( {
65
- title : `Could not find Nx modules in this workspace.` ,
66
- bodyLines : [ `Have you run ${ chalk . bold . white ( `npm/yarn install` ) } ?` ] ,
67
- } ) ;
68
- process . exit ( 1 ) ;
69
- }
58
+ // Make sure that a local copy of Nx exists in workspace
59
+ let localNx : string ;
60
+ try {
61
+ localNx = resolveNx ( workspace ) ;
62
+ } catch {
63
+ // If we can't resolve a local copy of Nx, we must be global.
64
+ warnIfUsingOutdatedGlobalInstall ( ) ;
65
+ output . error ( {
66
+ title : `Could not find Nx modules in this workspace.` ,
67
+ bodyLines : [ `Have you run ${ chalk . bold . white ( `npm/yarn install` ) } ?` ] ,
68
+ } ) ;
69
+ process . exit ( 1 ) ;
70
+ }
70
71
71
- // this file is already in the local workspace
72
- if ( localNx === resolveNx ( null ) ) {
73
- initLocal ( workspace ) ;
74
- } else {
75
- // Nx is being run from globally installed CLI - hand off to the local
76
- warnIfUsingOutdatedGlobalInstall ( getLocalNxVersion ( workspace ) ) ;
77
- if ( localNx . includes ( '.nx' ) ) {
78
- const nxWrapperPath = localNx . replace ( / \. n x .* / , '.nx/' ) + 'nxw.js' ;
79
- require ( nxWrapperPath ) ;
72
+ // this file is already in the local workspace
73
+ if ( localNx === resolveNx ( null ) ) {
74
+ initLocal ( workspace ) ;
80
75
} else {
81
- require ( localNx ) ;
76
+ // Nx is being run from globally installed CLI - hand off to the local
77
+ warnIfUsingOutdatedGlobalInstall ( getLocalNxVersion ( workspace ) ) ;
78
+ if ( localNx . includes ( '.nx' ) ) {
79
+ const nxWrapperPath = localNx . replace ( / \. n x .* / , '.nx/' ) + 'nxw.js' ;
80
+ require ( nxWrapperPath ) ;
81
+ } else {
82
+ require ( localNx ) ;
83
+ }
82
84
}
83
85
}
84
86
}
@@ -159,3 +161,5 @@ const getLatestVersionOfNx = ((fn: () => string) => {
159
161
let cache : string = null ;
160
162
return ( ) => cache || ( cache = fn ( ) ) ;
161
163
} ) ( _getLatestVersionOfNx ) ;
164
+
165
+ main ( ) ;
1 commit comments
vercel[bot] commentedon Mar 21, 2023
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app