feat: Support DENO_INSTALL in the powershell installer (#90)

This commit is contained in:
Nayeem Rahman 2019-12-14 01:17:11 +00:00 committed by Ry Dahl
parent 7bdb161ab5
commit f00e5a40a3
4 changed files with 44 additions and 21 deletions

View file

@ -83,15 +83,24 @@ scoop reset deno
## Environment Variables ## Environment Variables
- `DENO_INSTALL` - The directory in which to install Deno. On Linux, this defaults to `$HOME/.local`. - `DENO_INSTALL` - The directory in which to install Deno. This defaults to
One application of this is a system-wide Shell installation to `/usr/local`: `$HOME/.local` on Linux/macOS and `$HOME/.deno` on Windows. The executable
is placed in `$DENO_INSTALL/bin`. One application of this is a system-wide
installation:
**With Shell (`/usr/local`):**
```sh ```sh
curl -fsSL https://deno.land/x/install/install.sh | sudo DENO_INSTALL=/usr/local sh curl -fsSL https://deno.land/x/install/install.sh | sudo DENO_INSTALL=/usr/local sh
``` ```
Not yet supported in the PowerShell installer ([#76](https://github.com/denoland/deno_install/issues/76)). **With PowerShell (`C:\Program Files\deno`):**
```powershell
# Run as administrator:
$env:DENO_INSTALL = "C:\Program Files\deno"
iwr https://deno.land/x/install/install.ps1 -useb | iex
```
## Compatibility ## Compatibility

View file

@ -13,10 +13,17 @@ if ($PSVersionTable.PSEdition -ne 'Core') {
$IsMacOS = $false $IsMacOS = $false
} }
$BinDir = if ($IsWindows) { $DenoInstall = $env:DENO_INSTALL
$BinDir = if ($DenoInstall) {
if ($IsWindows) {
"$DenoInstall\bin"
} else {
"$DenoInstall/bin"
}
} elseif ($IsWindows) {
"$Home\.deno\bin" "$Home\.deno\bin"
} else { } else {
"$Home/.deno/bin" "$Home/.local/bin"
} }
$Zip = if ($IsWindows) { $Zip = if ($IsWindows) {

View file

@ -17,29 +17,34 @@ if (!(Get-Module PSScriptAnalyzer -ListAvailable)) {
# Lint. # Lint.
Invoke-ScriptAnalyzer *.ps1 -EnableExit -Exclude PSAvoidAssignmentToAutomaticVariable Invoke-ScriptAnalyzer *.ps1 -EnableExit -Exclude PSAvoidAssignmentToAutomaticVariable
$BinDir = if ($IsWindows) { # Test that we can install the latest version at the default location.
"$Home\.deno\bin" if ($IsWindows) {
Remove-Item "~\.deno" -Recurse -Force -ErrorAction SilentlyContinue
} else { } else {
"$Home/.deno/bin" Remove-Item "~/.local/bin/deno" -Force -ErrorAction SilentlyContinue
}
$env:DENO_INSTALL = ""
.\install.ps1
if ($IsWindows) {
~\.deno\bin\deno.exe --version
} else {
~/.local/bin/deno --version
} }
# Test we can install a specific version. # Test that we can install a specific version at a custom location.
Remove-Item $BinDir -Recurse -Force -ErrorAction SilentlyContinue if ($IsWindows) {
Remove-Item "~\deno-0.13.0" -Recurse -Force -ErrorAction SilentlyContinue
$env:DENO_INSTALL = "$Home\deno-0.13.0"
} else {
Remove-Item "~/deno-0.13.0" -Recurse -Force -ErrorAction SilentlyContinue
$env:DENO_INSTALL = "$Home/deno-0.13.0"
}
.\install.ps1 v0.13.0 .\install.ps1 v0.13.0
$DenoVersion = if ($IsWindows) { $DenoVersion = if ($IsWindows) {
deno --version ~\deno-0.13.0\bin\deno.exe --version
} else { } else {
~/.deno/bin/deno --version ~/deno-0.13.0/bin/deno --version
} }
if (!($DenoVersion -like '*0.13.0*')) { if (!($DenoVersion -like '*0.13.0*')) {
throw $DenoVersion throw $DenoVersion
} }
# Test we can install the latest version.
Remove-Item $BinDir -Recurse -Force -ErrorAction SilentlyContinue
.\install.ps1
if ($IsWindows) {
deno --version
} else {
~/.deno/bin/deno --version
}

View file

@ -6,11 +6,13 @@ set -e
# TODO(ry) shellcheck -s sh ./*.sh # TODO(ry) shellcheck -s sh ./*.sh
# Test that we can install the latest version at the default location. # Test that we can install the latest version at the default location.
rm -f ~/.local/bin/deno
unset DENO_INSTALL unset DENO_INSTALL
sh ./install.sh sh ./install.sh
~/.local/bin/deno --version ~/.local/bin/deno --version
# Test that we can install a specific version at a custom location. # Test that we can install a specific version at a custom location.
rm -rf ~/deno-0.13.0
export DENO_INSTALL="$HOME/deno-0.13.0" export DENO_INSTALL="$HOME/deno-0.13.0"
./install.sh v0.13.0 ./install.sh v0.13.0
~/deno-0.13.0/bin/deno --version | grep 0.13.0 ~/deno-0.13.0/bin/deno --version | grep 0.13.0