sync
This commit is contained in:
parent
b99de4118e
commit
cb5674edc7
3 changed files with 14 additions and 45 deletions
|
|
@ -88,9 +88,9 @@
|
||||||
"@clack/prompts": "1.0.0-alpha.1",
|
"@clack/prompts": "1.0.0-alpha.1",
|
||||||
"@gitlab/gitlab-ai-provider": "3.6.0",
|
"@gitlab/gitlab-ai-provider": "3.6.0",
|
||||||
"@gitlab/opencode-gitlab-auth": "1.3.3",
|
"@gitlab/opencode-gitlab-auth": "1.3.3",
|
||||||
"@hono/standard-validator": "0.1.5",
|
|
||||||
"@hono/node-server": "1.19.11",
|
"@hono/node-server": "1.19.11",
|
||||||
"@hono/node-ws": "1.3.0",
|
"@hono/node-ws": "1.3.0",
|
||||||
|
"@hono/standard-validator": "0.1.5",
|
||||||
"@hono/zod-validator": "catalog:",
|
"@hono/zod-validator": "catalog:",
|
||||||
"@modelcontextprotocol/sdk": "1.25.2",
|
"@modelcontextprotocol/sdk": "1.25.2",
|
||||||
"@npmcli/arborist": "9.4.0",
|
"@npmcli/arborist": "9.4.0",
|
||||||
|
|
|
||||||
|
|
@ -150,8 +150,7 @@ export namespace Config {
|
||||||
|
|
||||||
deps.push(
|
deps.push(
|
||||||
iife(async () => {
|
iife(async () => {
|
||||||
const shouldInstall = await needsInstall(dir)
|
await installDependencies(dir)
|
||||||
if (shouldInstall) await installDependencies(dir)
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -267,6 +266,10 @@ export namespace Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installDependencies(dir: string) {
|
export async function installDependencies(dir: string) {
|
||||||
|
if (!(await isWritable(dir))) {
|
||||||
|
log.info("config dir is not writable, skipping dependency install", { dir })
|
||||||
|
return
|
||||||
|
}
|
||||||
const pkg = path.join(dir, "package.json")
|
const pkg = path.join(dir, "package.json")
|
||||||
const targetVersion = Installation.isLocal() ? "*" : Installation.VERSION
|
const targetVersion = Installation.isLocal() ? "*" : Installation.VERSION
|
||||||
|
|
||||||
|
|
@ -280,16 +283,15 @@ export namespace Config {
|
||||||
await Filesystem.writeJson(pkg, json)
|
await Filesystem.writeJson(pkg, json)
|
||||||
|
|
||||||
const gitignore = path.join(dir, ".gitignore")
|
const gitignore = path.join(dir, ".gitignore")
|
||||||
await Filesystem.write(
|
if (!(await Filesystem.exists(gitignore)))
|
||||||
gitignore,
|
await Filesystem.write(
|
||||||
["node_modules", "plans", "package.json", "bun.lock", ".gitignore", "package-lock.json"].join("\n"),
|
gitignore,
|
||||||
)
|
["node_modules", "plans", "package.json", "bun.lock", ".gitignore", "package-lock.json"].join("\n"),
|
||||||
|
)
|
||||||
|
|
||||||
// Install any additional dependencies defined in the package.json
|
// Install any additional dependencies defined in the package.json
|
||||||
// This allows local plugins and custom tools to use external packages
|
// This allows local plugins and custom tools to use external packages
|
||||||
await Npm.install(dir).catch((err: any) => {
|
await Npm.install(dir)
|
||||||
log.warn("failed to install dependencies", { dir, error: err.message })
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isWritable(dir: string) {
|
async function isWritable(dir: string) {
|
||||||
|
|
@ -301,41 +303,6 @@ export namespace Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function needsInstall(dir: string) {
|
|
||||||
// Some config dirs may be read-only.
|
|
||||||
// Installing deps there will fail; skip installation in that case.
|
|
||||||
const writable = await isWritable(dir)
|
|
||||||
if (!writable) {
|
|
||||||
log.debug("config dir is not writable, skipping dependency install", { dir })
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeModules = path.join(dir, "node_modules")
|
|
||||||
if (!existsSync(nodeModules)) return true
|
|
||||||
|
|
||||||
const pkg = path.join(dir, "package.json")
|
|
||||||
const pkgExists = await Filesystem.exists(pkg)
|
|
||||||
if (!pkgExists) return true
|
|
||||||
|
|
||||||
const parsed = await Filesystem.readJson<{ dependencies?: Record<string, string> }>(pkg).catch(() => null)
|
|
||||||
const dependencies = parsed?.dependencies ?? {}
|
|
||||||
const depVersion = dependencies["@opencode-ai/plugin"]
|
|
||||||
if (!depVersion) return true
|
|
||||||
|
|
||||||
const targetVersion = Installation.isLocal() ? "latest" : Installation.VERSION
|
|
||||||
if (targetVersion === "latest") {
|
|
||||||
const isOutdated = await Npm.outdated("@opencode-ai/plugin", depVersion)
|
|
||||||
if (!isOutdated) return false
|
|
||||||
log.info("Cached version is outdated, proceeding with install", {
|
|
||||||
pkg: "@opencode-ai/plugin",
|
|
||||||
cachedVersion: depVersion,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if (depVersion === targetVersion) return false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
function rel(item: string, patterns: string[]) {
|
function rel(item: string, patterns: string[]) {
|
||||||
const normalizedItem = item.replaceAll("\\", "/")
|
const normalizedItem = item.replaceAll("\\", "/")
|
||||||
for (const pattern of patterns) {
|
for (const pattern of patterns) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,9 @@ export namespace Plugin {
|
||||||
directory: Instance.directory,
|
directory: Instance.directory,
|
||||||
fetch: async (...args) => Server.Default().fetch(...args),
|
fetch: async (...args) => Server.Default().fetch(...args),
|
||||||
})
|
})
|
||||||
|
log.info("loading config")
|
||||||
const config = await Config.get()
|
const config = await Config.get()
|
||||||
|
log.info("config loaded")
|
||||||
const hooks: Hooks[] = []
|
const hooks: Hooks[] = []
|
||||||
const input: PluginInput = {
|
const input: PluginInput = {
|
||||||
client,
|
client,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue