-
Notifications
You must be signed in to change notification settings - Fork 12k
fix(@angular/cli): skip prompt or warn when setting up autocompletion without a global CLI install #23145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3664b1e
to
ede4315
Compare
15 tasks
ede4315
to
5203a38
Compare
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
alan-agius4
reviewed
May 17, 2022
f34715f
to
cdb0fb2
Compare
… 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. Closes angular#23135.
cdb0fb2
to
33ca5c9
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
action: merge
The PR is ready for merge by the caretaker
target: rc
This PR is targeted for the next release-candidate
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatsource <(ng completion script)
won't work withoutng
on the$PATH
, which is only really viable with a global install. Local executions likegit clone ... && npm install && npm start
or ephemeral executions likenpx @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 allng
commands on the$PATH
. We then look over all binaries in the list and exclude anything which is a directo child of anode_modules/.bin/
directory. These include local executions andnpx
, 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, butwhich
needs to be available (so we can't clobber the whole$PATH
) andnode
exists in the same directory as the globalng
command (so we can't remove that directory anyways). There's also no good way of testing the case wherewhich
fails to run.Closes #23135.
/cc @alan-agius4