Skip to content

Commit dc5c465

Browse files
committed
refactor: internalize app data path
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
1 parent 12e6f3e commit dc5c465

6 files changed

Lines changed: 27 additions & 26 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"start": "node src/cli.ts"
6969
},
7070
"dependencies": {
71-
"appdata-path": "^1.0.0",
7271
"cors": "^2.8.6",
7372
"express": "^5.2.1",
7473
"zod": "^4.5.4"

pnpm-lock.yaml

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

src/app-data-path.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os from "node:os"
2+
import path from "node:path"
3+
4+
function getAppDataPath(app?: string): string {
5+
const home = os.homedir()
6+
let appDataPath = process.env["APPDATA"]
7+
8+
if (appDataPath === undefined) {
9+
switch (os.platform()) {
10+
case "win32":
11+
appDataPath = path.join(home, "AppData", "Roaming")
12+
break
13+
case "darwin":
14+
appDataPath = path.join(home, "Library", "Application Support")
15+
break
16+
default:
17+
appDataPath = path.join(home, ".config")
18+
}
19+
}
20+
21+
if (app === undefined) return appDataPath
22+
return path.join(appDataPath, appDataPath === home ? `.${app}` : app)
23+
}
24+
25+
export { getAppDataPath }

src/certs.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import fs from "node:fs"
55
import https from "node:https"
66
import path from "node:path"
77

8-
import appDataPathPkg from "appdata-path"
9-
10-
const getAppDataPath =
11-
typeof appDataPathPkg === "function"
12-
? appDataPathPkg
13-
: (appDataPathPkg as unknown as { default: (name?: string) => string }).default
8+
import { getAppDataPath } from "./app-data-path.ts"
149

1510
const MKCERT_VERSION = "v1.4.4"
1611
const DEFAULT_CERT_PATH = getAppDataPath("https-localhost")

test/test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ import path from "node:path"
99
import { afterEach, describe, it } from "node:test"
1010
import tls from "node:tls"
1111

12-
import appDataPathPkg from "appdata-path"
13-
12+
import { getAppDataPath } from "../src/app-data-path.ts"
1413
import { generate, getCerts, remove } from "../src/certs.ts"
1514
import { getEnv } from "../src/env.ts"
1615
import createServer from "../src/index.ts"
1716
import type { HttpsLocalhostApp } from "../src/index.ts"
1817

19-
const getAppDataPath =
20-
typeof appDataPathPkg === "function"
21-
? appDataPathPkg
22-
: (appDataPathPkg as unknown as { default: (name?: string) => string }).default
23-
2418
const HTTPS_PORT = 4443
2519
const HTTP_PORT = 8080
2620
let app: HttpsLocalhostApp = createServer()

types/appdata-path.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)