mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
Replace env-paths with xdg-basedir for better XDG compliance and cross-platform directory handling
🤖 Generated with opencode
Co-Authored-By: opencode <noreply@opencode.ai>
This commit is contained in:
parent
9ad0477af6
commit
8e769dcac0
7 changed files with 30 additions and 22 deletions
3
bun.lock
3
bun.lock
|
@ -37,6 +37,7 @@
|
|||
"turndown": "7.2.0",
|
||||
"vscode-jsonrpc": "8.2.1",
|
||||
"vscode-languageclient": "8",
|
||||
"xdg-basedir": "5.1.0",
|
||||
"zod": "catalog:",
|
||||
"zod-openapi": "4.2.4",
|
||||
},
|
||||
|
@ -1489,6 +1490,8 @@
|
|||
|
||||
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
|
||||
|
||||
"xdg-basedir": ["xdg-basedir@5.1.0", "", {}, "sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ=="],
|
||||
|
||||
"xml2js": ["xml2js@0.6.2", "", { "dependencies": { "sax": ">=0.6.0", "xmlbuilder": "~11.0.0" } }, "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA=="],
|
||||
|
||||
"xmlbuilder": ["xmlbuilder@11.0.1", "", {}, "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="],
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
"turndown": "7.2.0",
|
||||
"vscode-jsonrpc": "8.2.1",
|
||||
"vscode-languageclient": "8",
|
||||
"xdg-basedir": "5.1.0",
|
||||
"zod": "catalog:",
|
||||
"zod-openapi": "4.2.4"
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export namespace App {
|
|||
x ? path.dirname(x) : undefined,
|
||||
)
|
||||
|
||||
const data = path.join(Global.data(), git ?? "global")
|
||||
const data = path.join(Global.Path.data, git ?? "global")
|
||||
const stateFile = Bun.file(path.join(data, APP_JSON))
|
||||
const state = (await stateFile.json().catch(() => ({}))) as {
|
||||
initialized: number
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
import envpaths from "env-paths"
|
||||
import fs from "fs/promises"
|
||||
const paths = envpaths("opencode", {
|
||||
suffix: "",
|
||||
})
|
||||
import { xdgData, xdgCache, xdgConfig } from "xdg-basedir"
|
||||
import path from "path"
|
||||
|
||||
const app = "opencode"
|
||||
|
||||
const data = path.join(xdgData!, app)
|
||||
const cache = path.join(xdgCache!, app)
|
||||
const config = path.join(xdgConfig!, app)
|
||||
|
||||
await Promise.all([
|
||||
fs.mkdir(paths.config, { recursive: true }),
|
||||
fs.mkdir(paths.cache, { recursive: true }),
|
||||
fs.mkdir(data, { recursive: true }),
|
||||
fs.mkdir(config, { recursive: true }),
|
||||
fs.mkdir(cache, { recursive: true }),
|
||||
])
|
||||
|
||||
export namespace Global {
|
||||
export function config() {
|
||||
return paths.config
|
||||
}
|
||||
|
||||
export function cache() {
|
||||
return paths.cache
|
||||
}
|
||||
|
||||
export function data() {
|
||||
return paths.data
|
||||
}
|
||||
export const Path = {
|
||||
data,
|
||||
cache,
|
||||
config,
|
||||
} as const
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ cli.command("", "Start the opencode in interactive mode").action(async () => {
|
|||
let cwd = new URL("../../tui/cmd/opencode", import.meta.url).pathname
|
||||
if (Bun.embeddedFiles.length > 0) {
|
||||
const blob = Bun.embeddedFiles[0] as File
|
||||
const binary = path.join(Global.cache(), "tui", blob.name)
|
||||
const binary = path.join(Global.Path.cache, "tui", blob.name)
|
||||
const file = Bun.file(binary)
|
||||
if (!(await file.exists())) {
|
||||
console.log("installing tui binary...")
|
||||
|
|
|
@ -95,13 +95,18 @@ export namespace Provider {
|
|||
const s = await state()
|
||||
if (s.sdk.has(providerID)) return s.sdk.get(providerID)!
|
||||
|
||||
const dir = path.join(Global.cache(), `node_modules`, `@ai-sdk`, providerID)
|
||||
const dir = path.join(
|
||||
Global.Path.cache,
|
||||
`node_modules`,
|
||||
`@ai-sdk`,
|
||||
providerID,
|
||||
)
|
||||
if (!(await Bun.file(path.join(dir, "package.json")).exists())) {
|
||||
log.info("installing", {
|
||||
providerID,
|
||||
})
|
||||
BunProc.run(["add", `@ai-sdk/${providerID}@alpha`], {
|
||||
cwd: Global.cache(),
|
||||
cwd: Global.Path.cache,
|
||||
})
|
||||
}
|
||||
const mod = await import(path.join(dir))
|
||||
|
|
|
@ -177,7 +177,7 @@ export namespace Server {
|
|||
root: app.path.root,
|
||||
data: app.path.data,
|
||||
cwd: app.path.cwd,
|
||||
config: Global.config(),
|
||||
config: Global.Path.data,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue