From f00e5a40a30a060761e03711e7225b65ec074888 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 14 Dec 2019 01:17:11 +0000 Subject: [PATCH] feat: Support DENO_INSTALL in the powershell installer (#90) --- README.md | 15 ++++++++++++--- install.ps1 | 11 +++++++++-- install_test.ps1 | 37 +++++++++++++++++++++---------------- install_test.sh | 2 ++ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 4e2ebee..9682b37 100644 --- a/README.md +++ b/README.md @@ -83,15 +83,24 @@ scoop reset deno ## Environment Variables -- `DENO_INSTALL` - The directory in which to install Deno. On Linux, this defaults to `$HOME/.local`. - One application of this is a system-wide Shell installation to `/usr/local`: +- `DENO_INSTALL` - The directory in which to install Deno. This defaults to + `$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 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 diff --git a/install.ps1 b/install.ps1 index 4c50d89..18d77ae 100644 --- a/install.ps1 +++ b/install.ps1 @@ -13,10 +13,17 @@ if ($PSVersionTable.PSEdition -ne 'Core') { $IsMacOS = $false } -$BinDir = if ($IsWindows) { +$DenoInstall = $env:DENO_INSTALL +$BinDir = if ($DenoInstall) { + if ($IsWindows) { + "$DenoInstall\bin" + } else { + "$DenoInstall/bin" + } +} elseif ($IsWindows) { "$Home\.deno\bin" } else { - "$Home/.deno/bin" + "$Home/.local/bin" } $Zip = if ($IsWindows) { diff --git a/install_test.ps1 b/install_test.ps1 index 10c163e..c95011e 100755 --- a/install_test.ps1 +++ b/install_test.ps1 @@ -17,29 +17,34 @@ if (!(Get-Module PSScriptAnalyzer -ListAvailable)) { # Lint. Invoke-ScriptAnalyzer *.ps1 -EnableExit -Exclude PSAvoidAssignmentToAutomaticVariable -$BinDir = if ($IsWindows) { - "$Home\.deno\bin" +# Test that we can install the latest version at the default location. +if ($IsWindows) { + Remove-Item "~\.deno" -Recurse -Force -ErrorAction SilentlyContinue } 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. -Remove-Item $BinDir -Recurse -Force -ErrorAction SilentlyContinue +# Test that we can install a specific version at a custom location. +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 $DenoVersion = if ($IsWindows) { - deno --version + ~\deno-0.13.0\bin\deno.exe --version } else { - ~/.deno/bin/deno --version + ~/deno-0.13.0/bin/deno --version } if (!($DenoVersion -like '*0.13.0*')) { 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 -} diff --git a/install_test.sh b/install_test.sh index e53543c..994827a 100755 --- a/install_test.sh +++ b/install_test.sh @@ -6,11 +6,13 @@ set -e # TODO(ry) shellcheck -s sh ./*.sh # Test that we can install the latest version at the default location. +rm -f ~/.local/bin/deno unset DENO_INSTALL sh ./install.sh ~/.local/bin/deno --version # 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" ./install.sh v0.13.0 ~/deno-0.13.0/bin/deno --version | grep 0.13.0