opencode-vim 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/update.ts +13 -2
package/package.json
CHANGED
package/src/update.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises"
|
|
2
|
-
import { dirname, join } from "node:path"
|
|
2
|
+
import { basename, dirname, join } from "node:path"
|
|
3
3
|
import { fileURLToPath } from "node:url"
|
|
4
4
|
import type { TuiPluginMeta } from "@opencode-ai/plugin/tui"
|
|
5
5
|
|
|
6
6
|
type PackageJson = {
|
|
7
7
|
name?: string
|
|
8
8
|
version?: string
|
|
9
|
+
dependencies?: Record<string, string>
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
type UpdateResult =
|
|
@@ -25,8 +26,9 @@ export async function checkAutoUpdate(meta: TuiPluginMeta, signal: AbortSignal):
|
|
|
25
26
|
const latest = await fetchLatestVersion(pkg.name, signal)
|
|
26
27
|
if (!latest || !isVersionNewer(latest, pkg.version)) return { updated: false }
|
|
27
28
|
|
|
29
|
+
const removeDir = await updateRemoveDir(packageDir, pkg.name)
|
|
28
30
|
try {
|
|
29
|
-
await rm(
|
|
31
|
+
await rm(removeDir, { recursive: true, force: true })
|
|
30
32
|
} catch {
|
|
31
33
|
return { updated: false, error: "remove_failed", name: pkg.name, current: pkg.version, latest }
|
|
32
34
|
}
|
|
@@ -47,6 +49,15 @@ async function findPackageDir() {
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
async function updateRemoveDir(packageDir: string, name: string) {
|
|
53
|
+
const nodeModulesDir = dirname(packageDir)
|
|
54
|
+
if (basename(nodeModulesDir) !== "node_modules") return packageDir
|
|
55
|
+
|
|
56
|
+
const wrapperDir = dirname(nodeModulesDir)
|
|
57
|
+
const wrapperPkg = await readPackageJson(join(wrapperDir, "package.json"))
|
|
58
|
+
return wrapperPkg?.dependencies?.[name] ? wrapperDir : packageDir
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
async function readPackageJson(path: string): Promise<PackageJson | undefined> {
|
|
51
62
|
try {
|
|
52
63
|
const file = Bun.file(path)
|