From 90f0c6f7d9d64e938cbce2e45cf4fe63afcbc0ba Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Mon, 20 Aug 2018 15:03:05 -0700 Subject: [PATCH 1/4] Add powershell for installed binaries RFC --- accepted/0000-powershell-bins.md | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 accepted/0000-powershell-bins.md diff --git a/accepted/0000-powershell-bins.md b/accepted/0000-powershell-bins.md new file mode 100644 index 000000000..f31fdc11b --- /dev/null +++ b/accepted/0000-powershell-bins.md @@ -0,0 +1,55 @@ +# Powershell for Installed Binaries + +AKA Terminate Terminate Batch Job + +## Summary + +Today, installing binaries using npm creates an executable bash script and a .cmd file with the same name. Unfortunately, terminating cmd scripts with SIGINT causes a useless prompt for windows users - "Terminate batch job (Y/N)". Also, Powershell is the default shell for Windows. By creating .ps1 scripts in addition to bash and .cmd, powershell users will have a better command line experience. + +## Motivation + +Windows users have three main options when it comes to shells: + +- cmd: essentially unchanged from early versions of Windows +- powershell: the default Windows shell, under active development +- unixy shell: for example git-bash, zsh via WSL + +WSL is growing in popularity, but isn't super common. Many Windows users need to use or prefer using a native shell. And for those using Powershell, we can make their experience better by creating powershell binary wrappers. + +## Detailed Explanation + +When installing binaries (e.g. `npm install -g typescript`), NPM should create `tsc.ps1` in addition to `tsc.cmd` and the executable `tsc` bash script. Powershell will prioritize `foo.ps1` over `foo.cmd` when users type `foo` on the command line. cmd users will have to continue living with it. Users of git-bash or WSL shells will be unaffected. + +## Rationale and Alternatives + +The main alternative is to maintain the status quo, but this leaves an annoying SIGINT prompt in Windows's default shell. + +Creating just .ps1 scripts isn't an option. cmd can't start treating .ps1 scripts as executables (at least not by default), and NPM can't drop support for cmd. + +## Implementation + +Here's an example of a functionally identical powershell wrapper: + +```powershell +$myPath = Split-Path $myInvocation.MyCommand.Path -Parent +$node = Join-Path $myPath "node.exe" +$binPath = Join-Path $myPath "[ path to node_module bin script, e.g. node_modules\typescript\bin\tsc]" +if (Test-Path $node) +{ + & $node $binPath $args +} +else +{ + node $binPath $args +} +``` + +The path to the bin script will have to be substituted into the right place. + +## Prior Art + +- [cmd-shim](https://www.npmjs.com/package/cmd-shim) + +## Unresolved Questions and Bikeshedding + +- impact of additional scripts on install times, node_modules size, etc. From 9363f1bd7efb597974e4c045d59da3eef2248059 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Tue, 21 Aug 2018 10:31:14 -0700 Subject: [PATCH 2/4] Change double quotes to single quotes --- accepted/0000-powershell-bins.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accepted/0000-powershell-bins.md b/accepted/0000-powershell-bins.md index f31fdc11b..eadf96e44 100644 --- a/accepted/0000-powershell-bins.md +++ b/accepted/0000-powershell-bins.md @@ -32,8 +32,8 @@ Here's an example of a functionally identical powershell wrapper: ```powershell $myPath = Split-Path $myInvocation.MyCommand.Path -Parent -$node = Join-Path $myPath "node.exe" -$binPath = Join-Path $myPath "[ path to node_module bin script, e.g. node_modules\typescript\bin\tsc]" +$node = Join-Path $myPath 'node.exe' +$binPath = Join-Path $myPath '[ path to node_module bin script, e.g. node_modules\typescript\bin\tsc]' if (Test-Path $node) { & $node $binPath $args From ab169d64c242f1b94cd5bddf187df605e4f09768 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Tue, 21 Aug 2018 10:53:32 -0700 Subject: [PATCH 3/4] Add yarn prior art --- accepted/0000-powershell-bins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/accepted/0000-powershell-bins.md b/accepted/0000-powershell-bins.md index eadf96e44..fe241b86a 100644 --- a/accepted/0000-powershell-bins.md +++ b/accepted/0000-powershell-bins.md @@ -49,6 +49,7 @@ The path to the bin script will have to be substituted into the right place. ## Prior Art - [cmd-shim](https://www.npmjs.com/package/cmd-shim) +- [yarn PR](https://github.com/yarnpkg/yarn/pull/6093) ## Unresolved Questions and Bikeshedding From 7570336ca6986f28e61bc0c5b107fcdf48baa397 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Wed, 22 Aug 2018 11:04:45 -0700 Subject: [PATCH 4/4] Add question about default PS permissions --- accepted/0000-powershell-bins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/accepted/0000-powershell-bins.md b/accepted/0000-powershell-bins.md index fe241b86a..f36020320 100644 --- a/accepted/0000-powershell-bins.md +++ b/accepted/0000-powershell-bins.md @@ -54,3 +54,4 @@ The path to the bin script will have to be substituted into the right place. ## Unresolved Questions and Bikeshedding - impact of additional scripts on install times, node_modules size, etc. +- default powershell permissions: will powershell users need to toggle some settings so this works without permissions errors? Can the errors be worked around? (This PR will need testing on a fresh Windows install)