mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 23:23:45 +00:00
bedrock loader
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { z } from "zod"
|
||||
import { Global } from "../global"
|
||||
import { Log } from "../util/log"
|
||||
import path from "path"
|
||||
import { NamedError } from "../util/error"
|
||||
|
||||
export namespace BunProc {
|
||||
const log = Log.create({ service: "bun" })
|
||||
|
||||
@@ -30,4 +35,24 @@ export namespace BunProc {
|
||||
export function which() {
|
||||
return process.execPath
|
||||
}
|
||||
|
||||
export const InstallFailedError = NamedError.create(
|
||||
"BunInstallFailedError",
|
||||
z.object({
|
||||
pkg: z.string(),
|
||||
version: z.string(),
|
||||
}),
|
||||
)
|
||||
export async function install(pkg: string, version = "latest") {
|
||||
const dir = path.join(Global.Path.cache, `node_modules`, pkg)
|
||||
if (!(await Bun.file(path.join(dir, "package.json")).exists())) {
|
||||
log.info("installing", { pkg })
|
||||
await BunProc.run(["add", `${pkg}@${version}`], {
|
||||
cwd: Global.Path.cache,
|
||||
}).catch(() => {
|
||||
throw new InstallFailedError({ pkg, version })
|
||||
})
|
||||
}
|
||||
return dir
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user