1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(installer): installs to the wrong directory on Windows (#3462)

Close: #3443
This commit is contained in:
木杉 2019-12-08 21:59:27 +08:00 committed by Bert Belder
parent 50b6907bc3
commit 90c5aadbca
2 changed files with 66 additions and 4 deletions

View file

@ -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> {

View file

@ -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"));