refactor(core): consolidate filesystem services (#30447)
This commit is contained in:
parent
b93963e462
commit
604a5f781f
153 changed files with 2542 additions and 4301 deletions
|
|
@ -4,7 +4,7 @@ import { randomUUID } from "crypto"
|
|||
import { Context, Effect, Function, Layer, Option, Schedule, Schema } from "effect"
|
||||
import type { FileSystem, Scope } from "effect"
|
||||
import type { PlatformError } from "effect/PlatformError"
|
||||
import { AppFileSystem } from "../filesystem"
|
||||
import { FSUtil } from "../fs-util"
|
||||
import { Global } from "../global"
|
||||
import { Hash } from "./hash"
|
||||
|
||||
|
|
@ -93,11 +93,11 @@ export namespace EffectFlock {
|
|||
|
||||
const isPathGone = (e: PlatformError) => e.reason._tag === "NotFound" || e.reason._tag === "Unknown"
|
||||
|
||||
export const layer: Layer.Layer<Service, never, Global.Service | AppFileSystem.Service> = Layer.effect(
|
||||
export const layer: Layer.Layer<Service, never, Global.Service | FSUtil.Service> = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const global = yield* Global.Service
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const fs = yield* FSUtil.Service
|
||||
const lockRoot = path.join(global.state, "locks")
|
||||
const hostname = os.hostname()
|
||||
const ensuredDirs = new Set<string>()
|
||||
|
|
@ -279,5 +279,5 @@ export namespace EffectFlock {
|
|||
}),
|
||||
)
|
||||
|
||||
export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer), Layer.provide(Global.layer))
|
||||
export const defaultLayer = layer.pipe(Layer.provide(FSUtil.defaultLayer), Layer.provide(Global.layer))
|
||||
}
|
||||
|
|
|
|||
14
packages/core/src/util/which.ts
Normal file
14
packages/core/src/util/which.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import whichPkg from "which"
|
||||
import path from "path"
|
||||
import { Global } from "../global"
|
||||
|
||||
export function which(cmd: string, env?: NodeJS.ProcessEnv) {
|
||||
const base = env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path ?? ""
|
||||
const full = base ? base + path.delimiter + Global.Path.bin : Global.Path.bin
|
||||
const result = whichPkg.sync(cmd, {
|
||||
nothrow: true,
|
||||
path: full,
|
||||
pathExt: env?.PATHEXT ?? env?.PathExt ?? process.env.PATHEXT ?? process.env.PathExt,
|
||||
})
|
||||
return typeof result === "string" ? result : null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue