@@ -81,7 +81,7 @@ Appended \`source <(ng completion script)\` to \`${rcFile}\`. Restart your termi
81
81
` . trim ( ) ,
82
82
) ;
83
83
84
- if ( ( await hasGlobalCliInstall ( ) ) === false ) {
84
+ if ( ! ( await hasGlobalCliInstall ( ) ) ) {
85
85
logger . warn (
86
86
'Setup completed successfully, but there does not seem to be a global install of the' +
87
87
' Angular CLI. For autocompletion to work, the CLI will need to be on your `$PATH`, which' +
@@ -268,27 +268,30 @@ function getShellRunCommandCandidates(shell: string, home: string): string[] | u
268
268
}
269
269
270
270
/**
271
- * Returns whether the user has a global CLI install or `undefined` if this can't be determined .
271
+ * Returns whether the user has a global CLI install.
272
272
* Execution from `npx` is *not* considered a global CLI install.
273
273
*
274
274
* This does *not* mean the current execution is from a global CLI install, only that a global
275
275
* install exists on the system.
276
276
*/
277
- export async function hasGlobalCliInstall ( ) : Promise < boolean | undefined > {
277
+ export function hasGlobalCliInstall ( ) : Promise < boolean > {
278
278
// List all binaries with the `ng` name on the user's `$PATH`.
279
- const proc = execFile ( 'which' , [ '-a' , 'ng' ] ) ;
280
- let stdout = '' ;
281
- proc . stdout ?. addListener ( 'data' , ( content ) => {
282
- stdout += content ;
283
- } ) ;
284
- const exitCode = await new Promise < number | null > ( ( resolve ) => {
285
- proc . addListener ( 'exit' , ( exitCode ) => {
286
- resolve ( exitCode ) ;
287
- } ) ;
288
- } ) ;
279
+ return new Promise < boolean > ( ( resolve ) => {
280
+ execFile ( 'which' , [ '-a' , 'ng' ] , ( error , stdout ) => {
281
+ if ( error ) {
282
+ // No instances of `ng` on the user's `$PATH`
283
+
284
+ // `which` returns exit code 2 if an invalid option is specified and `-a` doesn't appear to be
285
+ // supported on all systems. Other exit codes mean unknown errors occurred. Can't tell whether
286
+ // CLI is globally installed, so treat this as inconclusive.
287
+
288
+ // `which` was killed by a signal and did not exit gracefully. Maybe it hung or something else
289
+ // went very wrong, so treat this as inconclusive.
290
+ resolve ( false ) ;
291
+
292
+ return ;
293
+ }
289
294
290
- switch ( exitCode ) {
291
- case 0 :
292
295
// Successfully listed all `ng` binaries on the `$PATH`. Look for at least one line which is a
293
296
// global install. We can't easily identify global installs, but local installs are typically
294
297
// placed in `node_modules/.bin` by NPM / Yarn. `npx` also currently caches files at
@@ -303,18 +306,7 @@ export async function hasGlobalCliInstall(): Promise<boolean | undefined> {
303
306
return ! localInstall ;
304
307
} ) ;
305
308
306
- return hasGlobalInstall ;
307
- case 1 :
308
- // No instances of `ng` on the user's `$PATH`.
309
- return false ;
310
- case null :
311
- // `which` was killed by a signal and did not exit gracefully. Maybe it hung or something else
312
- // went very wrong, so treat this as inconclusive.
313
- return undefined ;
314
- default :
315
- // `which` returns exit code 2 if an invalid option is specified and `-a` doesn't appear to be
316
- // supported on all systems. Other exit codes mean unknown errors occurred. Can't tell whether
317
- // CLI is globally installed, so treat this as inconclusive.
318
- return undefined ;
319
- }
309
+ return resolve ( hasGlobalInstall ) ;
310
+ } ) ;
311
+ } ) ;
320
312
}
0 commit comments