You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(@angular/cli): skip prompt or warn when setting up autocompletion without a global CLI install
If the user does not have a global install of the Angular CLI, the autocompletion prompt is skipped and `ng completion` emits a warning. The reasoning for this is that `source <(ng completion script)` won't work without `ng` on the `$PATH`, which is only really viable with a global install. Local executions like `git clone ... && npm install && npm start` or ephemeral executions like `npx @angular/cli` don't benefit from autocompletion and unnecessarily impede users.
A global install of the Angular CLI is detected by running `which -a ng`, which appears to be a cross-platform means of listing all `ng` commands on the `$PATH`. We then look over all binaries in the list and exclude anything which is a directo child of a `node_modules/.bin/` directory. These include local executions and `npx`, so the only remaining locations should be global installs (`/usr/bin/ng`, NVM, etc.).
The tests are a little awkward since `ng` is installed globally by helper functions before tests start. These tests uninstall the global CLI and install a local, project-specific version to verify behavior, before restoring the global version. Hypothetically this could be emulated by manipulating the `$PATH` variable, but `which` needs to be available (so we can't clobber the whole `$PATH`) and `node` exists in the same directory as the global `ng` command (so we can't remove that directory anyways). There's also no good way of testing the case where `which` fails to run.
Closesangular#23135.
@@ -44,6 +44,16 @@ Appended \`source <(ng completion script)\` to \`${rcFile}\`. Restart your termi
44
44
`.trim(),
45
45
);
46
46
47
+
if((awaithasGlobalCliInstall())===false){
48
+
this.context.logger.warn(
49
+
`
50
+
Setup completed successfully, but there does not seem to be a global install of the Angular CLI. For autocompletion to work, the CLI will need to be on your \`$PATH\`, which is typically done with the \`-g\` flag in \`npm install -g @angular/cli\`.
51
+
52
+
See https://angular.io/cli/completion#global-install for more info.
@@ -78,6 +79,16 @@ Appended \`source <(ng completion script)\` to \`${rcFile}\`. Restart your termi
78
79
`.trim(),
79
80
);
80
81
82
+
if((awaithasGlobalCliInstall())===false){
83
+
logger.warn(
84
+
`
85
+
Setup completed successfully, but there does not seem to be a global install of the Angular CLI. For autocompletion to work, the CLI will need to be on your \`$PATH\`, which is typically done with the \`-g\` flag in \`npm install -g @angular/cli\`.
86
+
87
+
See https://angular.io/cli/completion#global-install for more info.
88
+
`.trim(),
89
+
);
90
+
}
91
+
81
92
// Save configuration to remember that the user was prompted.
0 commit comments