Skip to content

Commit

Permalink
use XDG base directory compatible cache location (#12676)
Browse files Browse the repository at this point in the history
* use XDG base directory compatible cache location

* use ~/Library/Caches on darwin
  • Loading branch information
vladima authored Dec 5, 2016
1 parent 5c71de1 commit 225d6d6
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,41 @@ namespace ts.server {
} = require("os");

function getGlobalTypingsCacheLocation() {
let basePath: string;
switch (process.platform) {
case "win32":
basePath = process.env.LOCALAPPDATA ||
case "win32": {
const basePath = process.env.LOCALAPPDATA ||
process.env.APPDATA ||
(os.homedir && os.homedir()) ||
process.env.USERPROFILE ||
(process.env.HOMEDRIVE && process.env.HOMEPATH && normalizeSlashes(process.env.HOMEDRIVE + process.env.HOMEPATH)) ||
os.tmpdir();
break;
case "linux":
case "android":
basePath = (os.homedir && os.homedir()) ||
process.env.HOME ||
((process.env.LOGNAME || process.env.USER) && `/home/${process.env.LOGNAME || process.env.USER}`) ||
os.tmpdir();
break;
return combinePaths(normalizeSlashes(basePath), "Microsoft/TypeScript");
}
case "darwin":
const homeDir = (os.homedir && os.homedir()) ||
process.env.HOME ||
((process.env.LOGNAME || process.env.USER) && `/Users/${process.env.LOGNAME || process.env.USER}`) ||
os.tmpdir();
basePath = combinePaths(homeDir, "Library/Application Support/");
break;
case "linux":
case "android": {
const cacheLocation = getNonWindowsCacheLocation(process.platform === "darwin");
return combinePaths(cacheLocation, "typescript");
}
default:
Debug.fail(`unsupported platform '${process.platform}'`);
return;
}
}

Debug.assert(basePath !== undefined);
return combinePaths(normalizeSlashes(basePath), "Microsoft/TypeScript");
function getNonWindowsCacheLocation(platformIsDarwin: boolean) {
if (process.env.XDG_CACHE_HOME) {
return process.env.XDG_CACHE_HOME;
}
const usersDir = platformIsDarwin ? "Users" : "home"
const homePath = (os.homedir && os.homedir()) ||
process.env.HOME ||
((process.env.LOGNAME || process.env.USER) && `/${usersDir}/${process.env.LOGNAME || process.env.USER}`) ||
os.tmpdir();
const cacheFolder = platformIsDarwin
? "Library/Caches"
: ".cache"
return combinePaths(normalizeSlashes(homePath), cacheFolder);
}

interface NodeChildProcess {
Expand Down

0 comments on commit 225d6d6

Please sign in to comment.