Skip to content

Problems installing ng14 cli completion on macOS #23135

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

Closed
1 of 15 tasks
moniuch opened this issue May 14, 2022 · 7 comments · Fixed by #23145
Closed
1 of 15 tasks

Problems installing ng14 cli completion on macOS #23135

moniuch opened this issue May 14, 2022 · 7 comments · Fixed by #23145
Assignees
Labels
area: @angular/cli area: docs Related to the documentation freq1: low Only reported by a handful of users who observe it rarely severity1: confusing
Milestone

Comments

@moniuch
Copy link

moniuch commented May 14, 2022

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

No, a new feature

Description

I went to play with 14rc1 but since I don't have ng installed globally, I issued the following command npx @angular/cli new ng14
(from the WebStorm embedded terminal).

Once the new cli got installed, I was asked if I want the cli completion to be enabled. Answered yes.
The result in the terminal was something like: source<(ng completion script)

The completion did not work OOTB or even in a new terminal tab, decided to restart.
After the restart saw this in the reopened terminal:

image 2022-05-14 20-11-29

Then I realized the embedded terminal in WebStorm might have not been elevated so I repeated the entire ng new process from macOS Terminal. Unfortunately, I couldn't force the completion prompt to appear again. Now ng new proceeds now straight to the routing question. Don't really know how to mitigate this.

A clear and concise description of the problem...

🔬 Minimal Reproduction

🔥 Exception or Error

ng g c my-comp [tab] doesn't produce any output as expected, just a void macOS sound

🌍 Your Environment

I don't have ng installed globally so ng version results in ng command not found.



macOS Monterey 12.3.1
nvm
node -v 18.1


Anything else relevant?

@moniuch
Copy link
Author

moniuch commented May 14, 2022

Tried to follow what's inside the completion utility
https://github.com/angular/angular-cli/blob/14.0.x/packages/angular/cli/src/utilities/completion.ts

Seems like the completion feature requires global installation of ng command
which I haven't seen mentioned anywhere

@alan-agius4 alan-agius4 added area: docs Related to the documentation area: @angular/cli labels May 16, 2022
@ngbot ngbot bot modified the milestone: Backlog May 16, 2022
@alan-agius4
Copy link
Collaborator

//cc @dgp1130, since you are working on the docs it might be worth mentioning this.

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely severity1: confusing labels May 16, 2022
@dgp1130
Copy link
Collaborator

dgp1130 commented May 16, 2022

Thanks for mentioning this. Yes we do need a global install of the CLI (npm install -g @angular/cli) since your terminal needs to invoke it on startup to configure autocompletion, without a global install your terminal doesn't know where the CLI is. I'll add this to our docs on the feature in angular/angular#45995.

I wonder if we can also update ng completion to check for ng on the user's $PATH and fail/warn if it's missing? I'm not sure if we would inherit node_modules/.bin/ on the $PATH from the npm / npx runner, but worth investigating.

@moniuch
Copy link
Author

moniuch commented May 16, 2022

@dgp1130 Thanks for your effort! Since the arrival of npx, I started to avoid -g installations, still expecting everything to work, my bad. ;-)

Yes, please try to determine during installation, whether ng completion can be offered, and in case like mine, maybe output an educational message that due to missing global ng it was not possible to offer/install ng completion

For successful installations, it would be awesome to have the paths of added/altered files (eg full path to .bashrc) listed.

@dgp1130 dgp1130 self-assigned this May 17, 2022
dgp1130 added a commit to dgp1130/angular-cli that referenced this issue May 17, 2022
… 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.
@dgp1130
Copy link
Collaborator

dgp1130 commented May 17, 2022

#23145 should skip the prompt / warn when a global install of the Angular CLI can't be found, which should more gracefully handle npm run ng and npx @angular/cli use cases.

#23146 is also adding some documentation and includes a section about the requirement for a global install.

For successful installations, it would be awesome to have the paths of added/altered files (eg full path to .bashrc) listed.

I'm pretty sure it already does that, it should print:

$ ng completion
Appended `source <(ng completion script)` to `/path/to/home/.bashrc`. Restart your terminal or run the following to autocomplete `ng` commands:

    source <(ng completion script)

dgp1130 added a commit to dgp1130/angular-cli that referenced this issue May 17, 2022
… 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.
@moniuch
Copy link
Author

moniuch commented May 17, 2022

@dgp1130 Thank you!

dgp1130 added a commit to dgp1130/angular-cli that referenced this issue May 17, 2022
… 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.
dgp1130 added a commit to dgp1130/angular-cli that referenced this issue May 18, 2022
… 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.
dgp1130 added a commit to dgp1130/angular-cli that referenced this issue May 18, 2022
… 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.
dgp1130 added a commit that referenced this issue May 18, 2022
… 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 #23135.
dgp1130 added a commit that referenced this issue May 18, 2022
… 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 #23135.

(cherry picked from commit b79b0f0)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli area: docs Related to the documentation freq1: low Only reported by a handful of users who observe it rarely severity1: confusing
Projects
None yet
3 participants