Replace uses of process.env.HOME with os.homedir() (#6479)

This commit is contained in:
Colen Garoutte-Carson
2020-11-10 13:10:58 -08:00
committed by GitHub
parent ec66642c60
commit 7bcbea62e9
3 changed files with 5 additions and 13 deletions
+1 -4
View File
@@ -1068,10 +1068,7 @@ function onShowRefCommand(arg?: TreeNode): void {
function reportMacCrashes(): void {
if (process.platform === "darwin") {
prevCrashFile = "";
const home: string | undefined = process.env.HOME;
if (!home) {
return;
}
const home: string = os.homedir();
const crashFolder: string = path.resolve(home, "Library/Logs/DiagnosticReports");
fs.stat(crashFolder, (err, stats) => {
const crashObject: { [key: string]: string } = {};
+2 -8
View File
@@ -126,10 +126,7 @@ export function getVcpkgPathDescriptorFile(): string {
}
return path.join(pathPrefix, "vcpkg/vcpkg.path.txt");
} else {
const pathPrefix: string | undefined = process.env.HOME;
if (!pathPrefix) {
throw new Error("Unable to read process.env.HOME");
}
const pathPrefix: string = os.homedir();
return path.join(pathPrefix, ".vcpkg/vcpkg.path.txt");
}
}
@@ -355,10 +352,7 @@ export function resolveVariables(input: string | undefined, additionalEnvironmen
// Resolve '~' at the start of the path.
regexp = () => /^\~/g;
ret = ret.replace(regexp(), (match: string, name: string) => {
const newValue: string | undefined = (process.platform === 'win32') ? process.env.USERPROFILE : process.env.HOME;
return newValue ? newValue : match;
});
ret = ret.replace(regexp(), (match: string, name: string) => os.homedir());
return ret;
}
+2 -1
View File
@@ -3,12 +3,13 @@
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as assert from "assert";
import * as os from "os";
import { envDelimiter, resolveVariables, escapeForSquiggles } from "../../src/common";
suite("Common Utility validation", () => {
suite("resolveVariables", () => {
const success: string = "success";
const home: string = process.env.HOME || process.env.USERPROFILE;
const home: string = os.homedir();
test("raw input", () => {
const input: string = "test";