diff --git a/std/installer/mod.ts b/std/installer/mod.ts index 17752517c3..7751bc12e9 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 { diff --git a/std/installer/test.ts b/std/installer/test.ts index 3e6572485c..371cbdfa09 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 { assert(!thrown, "It should not throw an error"); }, true); // set true to install module in your real $HOME dir. +installerTest(async function installWithoutHOMEVar(): Promise { + 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"));