diff options
author | 木杉 <zhmushan@qq.com> | 2019-12-08 21:59:27 +0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2019-12-08 14:59:27 +0100 |
commit | 90c5aadbca8b47fc43bd3ece80e007b1b546c402 (patch) | |
tree | 6ecb65a3e213d1d7e08a264214b9b14e39a3fafe | |
parent | 50b6907bc332315eeb13c05bf687b990bc8dd936 (diff) |
fix(installer): installs to the wrong directory on Windows (#3462)
Close: #3443
-rw-r--r-- | std/installer/mod.ts | 8 | ||||
-rw-r--r-- | std/installer/test.ts | 62 |
2 files changed, 66 insertions, 4 deletions
diff --git a/std/installer/mod.ts b/std/installer/mod.ts index 17752517c..7751bc12e 100644 --- a/std/installer/mod.ts +++ b/std/installer/mod.ts @@ -78,16 +78,16 @@ function getFlagFromPermission(perm: Permission): string { function getInstallerDir(): string { // In Windows's Powershell $HOME environmental variable maybe null - // if so use $HOMEPATH instead. - const { HOME, HOMEPATH } = env(); + // if so use $USERPROFILE instead. + const { HOME, USERPROFILE } = env(); - const HOME_PATH = HOME || HOMEPATH; + const HOME_PATH = HOME || USERPROFILE; if (!HOME_PATH) { throw new Error("$HOME is not defined."); } - return path.join(HOME_PATH, ".deno", "bin"); + return path.resolve(HOME_PATH, ".deno", "bin"); } async function readCharacter(): Promise<string> { diff --git a/std/installer/test.ts b/std/installer/test.ts index 3e6572485..371cbdfa0 100644 --- a/std/installer/test.ts +++ b/std/installer/test.ts @@ -42,8 +42,10 @@ function installerTest(t: TestFunction, useOriginHomeDir = false): void { const tempDir = await makeTempDir(); const envVars = env(); const originalHomeDir = envVars["HOME"]; + const originalUserProfile = envVars["USERPROFILE"]; if (!useOriginHomeDir) { envVars["HOME"] = tempDir; + envVars["USERPROFILE"] = tempDir; } try { @@ -54,6 +56,9 @@ function installerTest(t: TestFunction, useOriginHomeDir = false): void { if (originalHomeDir) { envVars["HOME"] = originalHomeDir; } + if (originalUserProfile) { + envVars["USERPROFILE"] = originalUserProfile; + } } }; @@ -400,6 +405,63 @@ installerTest(async function installAndMakesureArgsRight(): Promise<void> { assert(!thrown, "It should not throw an error"); }, true); // set true to install module in your real $HOME dir. +installerTest(async function installWithoutHOMEVar(): Promise<void> { + const { HOME } = env(); + env()["HOME"] = ""; + + await install( + "echo_test", + "http://localhost:4500/installer/testdata/echo.ts", + [] + ); + + env()["HOME"] = HOME; + + const filePath = path.resolve(HOME, ".deno/bin/echo_test"); + const fileInfo = await stat(filePath); + assert(fileInfo.isFile()); + + if (path.isWindows) { + assertEquals( + await fs.readFileStr(filePath + ".cmd"), + /* eslint-disable max-len */ + `% This executable is generated by Deno. Please don't modify it unless you know what it means. % +@IF EXIST "%~dp0\deno.exe" ( + "%~dp0\deno.exe" "run" "http://localhost:4500/installer/testdata/echo.ts" %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.TS;=;% + "deno" "run" "http://localhost:4500/installer/testdata/echo.ts" %* +) +` + /* eslint-enable max-len */ + ); + } + + assertEquals( + await fs.readFileStr(filePath), + /* eslint-disable max-len */ + `#!/bin/sh +# This executable is generated by Deno. Please don't modify it unless you know what it means. +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/deno" ]; then + "$basedir/deno" "run" "http://localhost:4500/installer/testdata/echo.ts" "$@" + ret=$? +else + "deno" "run" "http://localhost:4500/installer/testdata/echo.ts" "$@" + ret=$? +fi +exit $ret +` + /* eslint-enable max-len */ + ); +}); + test(function testIsRemoteUrl(): void { assert(isRemoteUrl("https://deno.land/std/http/file_server.ts")); assert(isRemoteUrl("http://deno.land/std/http/file_server.ts")); |