Skip to content

Commit eca3df8

Browse files
bterlsonisaacs
authored andcommitted
Add powershell for installed binaries RFC
PR-URL: #20 Credit: @bterlson Close: #20 Reviewed-by: @isaacs
1 parent 430cc0f commit eca3df8

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

accepted/0000-powershell-bins.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Powershell for Installed Binaries
2+
3+
AKA Terminate Terminate Batch Job
4+
5+
## Summary
6+
7+
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.
8+
9+
## Motivation
10+
11+
Windows users have three main options when it comes to shells:
12+
13+
- cmd: essentially unchanged from early versions of Windows
14+
- powershell: the default Windows shell, under active development
15+
- unixy shell: for example git-bash, zsh via WSL
16+
17+
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.
18+
19+
## Detailed Explanation
20+
21+
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.
22+
23+
## Rationale and Alternatives
24+
25+
The main alternative is to maintain the status quo, but this leaves an annoying SIGINT prompt in Windows's default shell.
26+
27+
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.
28+
29+
## Implementation
30+
31+
Here's an example of a functionally identical powershell wrapper:
32+
33+
```powershell
34+
$myPath = Split-Path $myInvocation.MyCommand.Path -Parent
35+
$node = Join-Path $myPath 'node.exe'
36+
$binPath = Join-Path $myPath '[ path to node_module bin script, e.g. node_modules\typescript\bin\tsc]'
37+
if (Test-Path $node)
38+
{
39+
& $node $binPath $args
40+
}
41+
else
42+
{
43+
node $binPath $args
44+
}
45+
```
46+
47+
The path to the bin script will have to be substituted into the right place.
48+
49+
## Prior Art
50+
51+
- [cmd-shim](https://www.npmjs.com/package/cmd-shim)
52+
- [yarn PR](https://github.com/yarnpkg/yarn/pull/6093)
53+
54+
## Unresolved Questions and Bikeshedding
55+
56+
- impact of additional scripts on install times, node_modules size, etc.
57+
- 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)

0 commit comments

Comments
 (0)