Skip to content

Conversation

dgp1130
Copy link
Collaborator

@dgp1130 dgp1130 commented May 3, 2022

Autocompletion tests were failing on Windows due to a missing $HOME variable, presumably Windows wasn't inheriting the $HOME variable like Linux does?

Also fixing a semi-related typo I happened to notice around the same time.

Not sure exactly how to test this on Windows before merging, just hope for the best I guess?

@dgp1130 dgp1130 added the target: major This PR is targeted for the next major release label May 3, 2022
@dgp1130 dgp1130 added this to the v14 milestone May 3, 2022
@dgp1130 dgp1130 requested a review from clydin May 3, 2022 23:20
@dgp1130 dgp1130 force-pushed the auto-completion-windows branch 2 times, most recently from 20d1520 to 37c667c Compare May 4, 2022 01:01
@dgp1130 dgp1130 removed the request for review from clydin May 4, 2022 01:05
export async function initializeAutocomplete(): Promise<string> {
// Windows doesn't support autocompletion, give a clear error message.
if (process.platform === 'win32') {
throw new Error(`Windows does not support shell autocompletion.`);
Copy link
Collaborator

@alan-agius4 alan-agius4 May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto complete should work on Windows as long as the user has bash or zsh installed, example through git bash, cmder etc..

The configs typically located in the user's profile directory
C:\Users\<username>\...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about git bash but WSL 1/2 should have a platform of linux so that will be covered with that check.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am referring to usages outside of WSL.

On native Windows, zsh and bash can still be installed and available and autocompletion is still possible using;

Example using;

  • cygwin
  • cmder
  • git bash

Considering a large set of our users are on Windows OS, I think we should support this case better. Alternatively, for the time being we can say that the automated setup doesn't support Windows but explain how this can be done by modifying the zsh and bash profiles manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also check the OSTYPE environment variable when on Windows. I believe it should be msys or cygwin for those cases but would need to confirm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was going to check Git Bash today, as I suspect that will be win32. I forgot about Cygwin, but I could test that too. Cmder I thought was just a terminal which still used cmd under the hood and would be win32 (it's not a Linux emulator IIRC)? WSL should definitely be detected as Linux.

I'm wondering if a better approach might be to check $SHELL for cmd.exe or powershell.exe and print an error message on that case? Not sure if there are other Windows shells which might come up there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked my personal machine and process.platform + $SHELL for each environment is:

  • Cmd has platform win32 and $SHELL is unset - should fail with a useful error message.
  • Powershell has platform win32 and $SHELL is unset - should fail with a useful error message.
  • WSL2 has platform linux and shell /usr/bin/zsh - "just works".
  • Git Bash has platform win32 and shell C:\Program files\Git\usr\bin\bash.exe - NVM autocompletion works, so I suspect we should too, but I wasn't able to get it to use a local CLI build to confirm.
  • Cmder has platform win32 and $SHELL is unset, but I do see $CMDER_SHELL="cmd" - I suspect this shouldn't work and we should fail with a useful error message.
  • Cygwin couldn't install Node in a reasonable time frame, so I gave up there - I suspect this is similar to Git Bash and probably falls into that case.

All the unsupported systems have an unset $SHELL, so I think that is the best way of detecting the failure. Unfortunately there is no good way to disambiguate between the environments (Powershell doesn't seem to have any good environment variable to identify itself for instance). I'm inclined to fail with a more generic message on missing $SHELL along the lines of:

$SHELL environment variable not set. Only Bash and Zsh are supported. If you're on Windows, Cmd and Powershell don't support command autocompletion, but Git Bash or Windows Subsystem for Linux should work, so make sure to run the command from there.

https://angular.io/cli/some-doc-about-autocompletion

(Sidebar: We should have a more directed/"goal-oriented" doc for setting up autocompletion which can explain the supported shells and link to relevant pieces.)

@dgp1130 dgp1130 force-pushed the auto-completion-windows branch 2 times, most recently from 4857b17 to 9f201e5 Compare May 4, 2022 20:08
@dgp1130 dgp1130 changed the title ci: fix Windows CI for autocompletion tests fix(@angular/cli): improve error message for Windows autocompletion use cases May 4, 2022
@dgp1130 dgp1130 requested a review from clydin May 4, 2022 20:09
clydin
clydin previously approved these changes May 4, 2022
export default async function () {
if (process.platform === 'win32') {
await windowsTests();
return; // Windows should never prompt for autocompletion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fail if the test was run on Windows with git-bash?
CircleCI is setup to use powershell so CI would be fine. maybe expand the comment to note that.

Copy link
Collaborator Author

@dgp1130 dgp1130 May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this would fail for Git Bash, I wasn't too concerned since CI isn't doing that.

It kinda sucks since any contributors using Git Bash will run the wrong set of tests and possibly get false negatives. I'm not too worried about it right now though, and I think we can figure that out when someone actually tries to do it, resolves all the other issues they'd run into with Git Bash in our setup (no idea how it plays with Bazel for instance), and can more easily find the right detection mechanism.

Updated the comment for now to be clear that only Cmd and Powershell shouldn't prompt.

…se cases

Windows Cmd and Powershell don't support autocompletion, but it can be done with utilities like Windows Subsystem for Linux and Git Bash, which should "just work" due to emulating a Linux environment. This clarifies the error message most users will see to call out the state of the world with regard to autocompletion on Windows platforms.
@dgp1130 dgp1130 added action: merge The PR is ready for merge by the caretaker target: rc This PR is targeted for the next release-candidate and removed target: major This PR is targeted for the next major release labels May 4, 2022
@dgp1130 dgp1130 merged commit 3ab1142 into angular:main May 5, 2022
@dgp1130 dgp1130 deleted the auto-completion-windows branch May 5, 2022 00:04
@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 5, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants