-
Notifications
You must be signed in to change notification settings - Fork 15
/
dirs.ts
36 lines (33 loc) · 1.02 KB
/
dirs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2018-2024 the Deno authors. MIT license.
import { join } from "@std/path";
export function cacheDir(): string | undefined {
if (Deno.build.os === "darwin") {
const home = homeDir();
if (home) {
return join(home, "Library/Caches");
}
} else if (Deno.build.os === "windows") {
Deno.permissions.request({ name: "env", variable: "LOCALAPPDATA" });
return Deno.env.get("LOCALAPPDATA");
} else {
Deno.permissions.request({ name: "env", variable: "XDG_CACHE_HOME" });
const cacheHome = Deno.env.get("XDG_CACHE_HOME");
if (cacheHome) {
return cacheHome;
} else {
const home = homeDir();
if (home) {
return join(home, ".cache");
}
}
}
}
export function homeDir(): string | undefined {
if (Deno.build.os === "windows") {
Deno.permissions.request({ name: "env", variable: "USERPROFILE" });
return Deno.env.get("USERPROFILE");
} else {
Deno.permissions.request({ name: "env", variable: "HOME" });
return Deno.env.get("HOME");
}
}