summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-07-11 17:50:26 -0400
committerDax Raad <[email protected]>2025-07-11 17:50:49 -0400
commit4bb8536d342f4f1bf8c0698516ec7121ba352a24 (patch)
tree3071a01edb90a3412dca8be7564ae9e4e4c8b06a
parentc73d4a137e92d4c2f31485d06e3dd41a1c251032 (diff)
downloadopencode-4bb8536d342f4f1bf8c0698516ec7121ba352a24.tar.gz
opencode-4bb8536d342f4f1bf8c0698516ec7121ba352a24.zip
introduce cache version concept for auto cleanup when breaking cache changes happen
-rw-r--r--packages/opencode/src/bun/index.ts10
-rw-r--r--packages/opencode/src/global/index.ts12
2 files changed, 17 insertions, 5 deletions
diff --git a/packages/opencode/src/bun/index.ts b/packages/opencode/src/bun/index.ts
index 23180e316..fa9cb6e35 100644
--- a/packages/opencode/src/bun/index.ts
+++ b/packages/opencode/src/bun/index.ts
@@ -65,10 +65,12 @@ export namespace BunProc {
}))
if (parsed.dependencies[pkg] === version) return mod
parsed.dependencies[pkg] = version
- await Bun.write(pkgjson, JSON.stringify(parsed, null, 2))
- await BunProc.run(["install", "--cwd", Global.Path.cache, "--registry=https://registry.npmjs.org"], {
- cwd: Global.Path.cache,
- }).catch((e) => {
+ await BunProc.run(
+ ["add", "--exact", "--cwd", Global.Path.cache, "--registry=https://registry.npmjs.org", pkg + "@" + version],
+ {
+ cwd: Global.Path.cache,
+ },
+ ).catch((e) => {
throw new InstallFailedError(
{ pkg, version },
{
diff --git a/packages/opencode/src/global/index.ts b/packages/opencode/src/global/index.ts
index 24e9b6ddb..f4d92be7c 100644
--- a/packages/opencode/src/global/index.ts
+++ b/packages/opencode/src/global/index.ts
@@ -23,7 +23,17 @@ export namespace Global {
await Promise.all([
fs.mkdir(Global.Path.data, { recursive: true }),
fs.mkdir(Global.Path.config, { recursive: true }),
- fs.mkdir(Global.Path.cache, { recursive: true }),
fs.mkdir(Global.Path.providers, { recursive: true }),
fs.mkdir(Global.Path.state, { recursive: true }),
])
+
+const CACHE_VERSION = "1"
+
+const version = await Bun.file(path.join(Global.Path.cache, "version"))
+ .text()
+ .catch(() => "0")
+
+if (version !== CACHE_VERSION) {
+ await fs.rm(Global.Path.cache, { recursive: true, force: true })
+ await Bun.file(path.join(Global.Path.cache, "version")).write(CACHE_VERSION)
+}