@@ -12,11 +12,9 @@ const isWarningEnabled = require('../utilities/config').isWarningEnabled;
12
12
const fs = require ( 'fs' ) ;
13
13
const packageJson = require ( '../package.json' ) ;
14
14
const path = require ( 'path' ) ;
15
- const resolve = require ( 'resolve' ) ;
16
15
const stripIndents = require ( '@angular-devkit/core' ) . tags . stripIndents ;
17
16
const yellow = require ( '@angular-devkit/core' ) . terminal . yellow ;
18
17
const SemVer = require ( 'semver' ) . SemVer ;
19
- const events = require ( 'events' ) ;
20
18
21
19
function _fromPackageJson ( cwd ?: string ) {
22
20
cwd = cwd || process . cwd ( ) ;
@@ -62,75 +60,62 @@ if (process.env['NG_CLI_PROFILING']) {
62
60
process . on ( 'uncaughtException' , exitHandler . bind ( null , { exit : true } ) ) ;
63
61
}
64
62
65
- resolve ( '@angular/cli' , { basedir : process . cwd ( ) } ,
66
- function ( error : Error , projectLocalCli : string ) {
67
- let cli ;
68
- if ( error ) {
69
- // If there is an error, resolve could not find the ng-cli
70
- // library from a package.json. Instead, include it from a relative
71
- // path to this script file (which is likely a globally installed
72
- // npm package). Most common cause for hitting this is `ng new`
73
- cli = require ( './cli' ) ;
74
- } else {
75
- // This was run from a global, check local version.
76
- const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
77
- let localVersion ;
78
- let shouldWarn = false ;
79
-
80
- try {
81
- localVersion = _fromPackageJson ( ) ;
82
- shouldWarn = localVersion && globalVersion . compare ( localVersion ) > 0 ;
83
- } catch ( e ) {
84
- // eslint-disable-next-line no-console
85
- console . error ( e ) ;
86
- shouldWarn = true ;
87
- }
63
+ let cli ;
64
+ try {
65
+ const projectLocalCli = require . resolve ( '@angular/cli' , { paths : [ process . cwd ( ) ] } ) ;
66
+
67
+ // This was run from a global, check local version.
68
+ const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
69
+ let localVersion ;
70
+ let shouldWarn = false ;
71
+
72
+ try {
73
+ localVersion = _fromPackageJson ( ) ;
74
+ shouldWarn = localVersion && globalVersion . compare ( localVersion ) > 0 ;
75
+ } catch ( e ) {
76
+ // eslint-disable-next-line no-console
77
+ console . error ( e ) ;
78
+ shouldWarn = true ;
79
+ }
88
80
89
- if ( shouldWarn && isWarningEnabled ( 'versionMismatch' ) ) {
90
- let warning = yellow ( stripIndents `
91
- Your global Angular CLI version (${ globalVersion } ) is greater than your local
92
- version (${ localVersion } ). The local Angular CLI version is used.
93
-
94
- To disable this warning use "ng config -g cli.warnings.versionMismatch false".
95
- ` ) ;
96
- // Don't show warning colorised on `ng completion`
97
- if ( process . argv [ 2 ] !== 'completion' ) {
98
- // eslint-disable-next-line no-console
99
- console . log ( warning ) ;
100
- } else {
101
- // eslint-disable-next-line no-console
102
- console . error ( warning ) ;
103
- process . exit ( 1 ) ;
104
- }
105
- }
81
+ if ( shouldWarn && isWarningEnabled ( 'versionMismatch' ) ) {
82
+ let warning = yellow ( stripIndents `
83
+ Your global Angular CLI version (${ globalVersion } ) is greater than your local
84
+ version (${ localVersion } ). The local Angular CLI version is used.
106
85
107
- // No error implies a projectLocalCli, which will load whatever
108
- // version of ng-cli you have installed in a local package.json
109
- cli = require ( projectLocalCli ) ;
86
+ To disable this warning use "ng config -g cli.warnings.versionMismatch false".
87
+ ` ) ;
88
+ // Don't show warning colorised on `ng completion`
89
+ if ( process . argv [ 2 ] !== 'completion' ) {
90
+ // eslint-disable-next-line no-console
91
+ console . log ( warning ) ;
92
+ } else {
93
+ // eslint-disable-next-line no-console
94
+ console . error ( warning ) ;
95
+ process . exit ( 1 ) ;
110
96
}
97
+ }
111
98
112
- if ( 'default' in cli ) {
113
- cli = cli [ 'default' ] ;
114
- }
99
+ // No error implies a projectLocalCli, which will load whatever
100
+ // version of ng-cli you have installed in a local package.json
101
+ cli = require ( projectLocalCli ) ;
102
+ } catch {
103
+ // If there is an error, resolve could not find the ng-cli
104
+ // library from a package.json. Instead, include it from a relative
105
+ // path to this script file (which is likely a globally installed
106
+ // npm package). Most common cause for hitting this is `ng new`
107
+ cli = require ( './cli' ) ;
108
+ }
115
109
116
- let standardInput ;
117
- try {
118
- standardInput = process . stdin ;
119
- } catch ( e ) {
120
- delete process . stdin ;
121
- process . stdin = new events . EventEmitter ( ) ;
122
- standardInput = process . stdin ;
123
- }
110
+ if ( 'default' in cli ) {
111
+ cli = cli [ 'default' ] ;
112
+ }
124
113
125
- cli ( {
126
- cliArgs : process . argv . slice ( 2 ) ,
127
- inputStream : standardInput ,
128
- outputStream : process . stdout
129
- } ) . then ( function ( exitCode : number ) {
130
- process . exit ( exitCode ) ;
131
- } ) . catch ( function ( err : Error ) {
132
- console . log ( 'Unknown error: ' + err . toString ( ) ) ;
133
- process . exit ( 127 ) ;
134
- } ) ;
135
- }
136
- ) ;
114
+ cli ( { cliArgs : process . argv . slice ( 2 ) } )
115
+ . then ( ( exitCode : number ) => {
116
+ process . exit ( exitCode ) ;
117
+ } )
118
+ . catch ( ( err : Error ) => {
119
+ console . log ( 'Unknown error: ' + err . toString ( ) ) ;
120
+ process . exit ( 127 ) ;
121
+ } ) ;
0 commit comments