feat: add runtime to getEnvPaths

This commit is contained in:
Joe Previte 2021-05-10 16:17:30 -07:00
parent adc4463507
commit a57ee69822
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
1 changed files with 10 additions and 4 deletions

View File

@ -7,10 +7,12 @@ import * as os from "os"
import * as path from "path" import * as path from "path"
import * as util from "util" import * as util from "util"
import xdgBasedir from "xdg-basedir" import xdgBasedir from "xdg-basedir"
import { tmpdir } from "./constants"
interface Paths { interface Paths {
data: string data: string
config: string config: string
runtime: string
} }
export const paths = getEnvPaths() export const paths = getEnvPaths()
@ -20,12 +22,15 @@ export const paths = getEnvPaths()
* On MacOS this function gets the standard XDG directories instead of using the native macOS * On MacOS this function gets the standard XDG directories instead of using the native macOS
* ones. Most CLIs do this as in practice only GUI apps use the standard macOS directories. * ones. Most CLIs do this as in practice only GUI apps use the standard macOS directories.
*/ */
function getEnvPaths(): Paths { export function getEnvPaths(): Paths {
let paths: Paths let paths: Paths
if (process.platform === "win32") { if (process.platform === "win32") {
paths = envPaths("code-server", { paths = {
...envPaths("code-server", {
suffix: "", suffix: "",
}) }),
runtime: tmpdir,
}
} else { } else {
if (xdgBasedir.data === undefined || xdgBasedir.config === undefined) { if (xdgBasedir.data === undefined || xdgBasedir.config === undefined) {
throw new Error("No home folder?") throw new Error("No home folder?")
@ -33,6 +38,7 @@ function getEnvPaths(): Paths {
paths = { paths = {
data: path.join(xdgBasedir.data, "code-server"), data: path.join(xdgBasedir.data, "code-server"),
config: path.join(xdgBasedir.config, "code-server"), config: path.join(xdgBasedir.config, "code-server"),
runtime: xdgBasedir.runtime ? path.join(xdgBasedir.runtime, "code-server") : tmpdir,
} }
} }