summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/global.ts70
1 files changed, 42 insertions, 28 deletions
diff --git a/packages/core/src/global.ts b/packages/core/src/global.ts
index bf605618f..0c83e3a1f 100644
--- a/packages/core/src/global.ts
+++ b/packages/core/src/global.ts
@@ -1,7 +1,9 @@
import path from "path"
+import fs from "fs/promises"
import { xdgData, xdgCache, xdgConfig, xdgState } from "xdg-basedir"
import os from "os"
import { Context, Effect, Layer } from "effect"
+import { Flock } from "./util/flock"
const app = "opencode"
const data = path.join(xdgData!, app)
@@ -9,7 +11,7 @@ const cache = path.join(xdgCache!, app)
const config = path.join(xdgConfig!, app)
const state = path.join(xdgState!, app)
-export const Path = {
+const paths = {
get home() {
return process.env.OPENCODE_TEST_HOME ?? os.homedir()
},
@@ -21,31 +23,43 @@ export const Path = {
state,
}
-export namespace Global {
- export class Service extends Context.Service<Service, Interface>()("@opencode/Global") {}
-
- export interface Interface {
- readonly home: string
- readonly data: string
- readonly cache: string
- readonly config: string
- readonly state: string
- readonly bin: string
- readonly log: string
- }
-
- export const layer = Layer.effect(
- Service,
- Effect.gen(function* () {
- return Service.of({
- home: Path.home,
- data: Path.data,
- cache: Path.cache,
- config: Path.config,
- state: Path.state,
- bin: Path.bin,
- log: Path.log,
- })
- }),
- )
+export const Path = paths
+
+Flock.setGlobal({ state })
+
+await Promise.all([
+ fs.mkdir(Path.data, { recursive: true }),
+ fs.mkdir(Path.config, { recursive: true }),
+ fs.mkdir(Path.state, { recursive: true }),
+ fs.mkdir(Path.log, { recursive: true }),
+ fs.mkdir(Path.bin, { recursive: true }),
+])
+
+export class Service extends Context.Service<Service, Interface>()("@opencode/Global") {}
+
+export interface Interface {
+ readonly home: string
+ readonly data: string
+ readonly cache: string
+ readonly config: string
+ readonly state: string
+ readonly bin: string
+ readonly log: string
}
+
+export const layer = Layer.effect(
+ Service,
+ Effect.gen(function* () {
+ return Service.of({
+ home: Path.home,
+ data: Path.data,
+ cache: Path.cache,
+ config: Path.config,
+ state: Path.state,
+ bin: Path.bin,
+ log: Path.log,
+ })
+ }),
+)
+
+export * as Global from "./global"