Skip to content

Commit ad1d7fe

Browse files
committed
feat: use @deno/cache-dir to resolve deno dir
1 parent 7897441 commit ad1d7fe

File tree

5 files changed

+75
-22
lines changed

5 files changed

+75
-22
lines changed

deno.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"version-match": "deno run --allow-read --allow-env ./tools/version_match.ts"
1515
},
1616
"imports": {
17+
"@deno/cache-dir": "jsr:@deno/cache-dir@^0.17.0",
1718
"@std/fmt": "jsr:@std/fmt@0.217",
1819
"@std/fmt/colors": "jsr:@std/fmt@0.217/colors",
1920
"@std/path": "jsr:@std/path@0.217",

deno.lock

Lines changed: 63 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployctl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import projectsSubcommand from "./src/subcommands/projects.ts";
1717
import deploymentsSubcommand from "./src/subcommands/deployments.ts";
1818
import apiSubcommand from "./src/subcommands/api.ts";
1919
import { MINIMUM_DENO_VERSION, VERSION } from "./src/version.ts";
20-
import { fetchReleases, getConfigPaths } from "./src/utils/info.ts";
20+
import { fetchReleases, getCachePaths } from "./src/utils/info.ts";
2121
import configFile from "./src/config_file.ts";
2222
import inferConfig from "./src/config_inference.ts";
2323
import { wait } from "./src/utils/spinner.ts";
@@ -57,7 +57,7 @@ setColoring(args);
5757
if (Deno.stdin.isTerminal()) {
5858
let latestVersion;
5959
// Get the path to the update information json file.
60-
const { updatePath } = getConfigPaths();
60+
const { updatePath } = getCachePaths();
6161
// Try to read the json file.
6262
const updateInfoJson = await Deno.readTextFile(updatePath).catch((error) => {
6363
if (error.name == "NotFound") return null;

src/utils/info.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { join } from "@std/path/join";
22
import { getVersions } from "../subcommands/upgrade.ts";
3+
import { DenoDir } from "@deno/cache-dir";
34

4-
export function getConfigPaths() {
5-
const homeDir = Deno.build.os == "windows"
6-
? Deno.env.get("USERPROFILE")!
7-
: Deno.env.get("HOME")!;
8-
const xdgCacheDir = Deno.env.get("XDG_CACHE_HOME");
9-
10-
const denoDir = Deno.env.get("DENO_DIR");
5+
export function getCachePaths() {
6+
const denoCacheDir = new DenoDir().root;
117
const cacheDir = join(
12-
denoDir ||
13-
(xdgCacheDir ? join(xdgCacheDir, "deno") : join(homeDir, ".deno")),
8+
denoCacheDir,
149
"deployctl",
1510
);
1611

@@ -25,7 +20,7 @@ export async function fetchReleases() {
2520
try {
2621
const { latest } = await getVersions();
2722
const updateInfo = { lastFetched: Date.now(), latest };
28-
const { updatePath, cacheDir } = getConfigPaths();
23+
const { updatePath, cacheDir } = getCachePaths();
2924
await Deno.mkdir(cacheDir, { recursive: true });
3025
await Deno.writeFile(
3126
updatePath,

src/utils/token_storage/fs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { getConfigPaths } from "../info.ts";
1+
import { getCachePaths } from "../info.ts";
22

33
export async function get(): Promise<string | null> {
4-
const { credentialsPath } = getConfigPaths();
4+
const { credentialsPath } = getCachePaths();
55
try {
66
const info = await Deno.lstat(credentialsPath);
77
if (!info.isFile || (info.mode !== null && (info.mode & 0o777) !== 0o600)) {
@@ -27,7 +27,7 @@ export async function get(): Promise<string | null> {
2727
}
2828

2929
export async function store(token: string): Promise<void> {
30-
const { credentialsPath, cacheDir } = getConfigPaths();
30+
const { credentialsPath, cacheDir } = getCachePaths();
3131
await Deno.mkdir(cacheDir, { recursive: true });
3232
await Deno.writeTextFile(
3333
credentialsPath,
@@ -38,7 +38,7 @@ export async function store(token: string): Promise<void> {
3838
}
3939

4040
export async function remove(): Promise<void> {
41-
const { credentialsPath, cacheDir } = getConfigPaths();
41+
const { credentialsPath, cacheDir } = getCachePaths();
4242
await Deno.mkdir(cacheDir, { recursive: true });
4343
await Deno.writeTextFile(credentialsPath, "{}", { mode: 0o600 });
4444
return Promise.resolve();

0 commit comments

Comments
 (0)