Skip to content

Commit b1dd31d

Browse files
fix global version read
1 parent b7d0b07 commit b1dd31d

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

packages/opencode/src/cli/cmd/tui/component/dialog-status.tsx

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import { TextAttributes } from "@opentui/core"
22
import { useTheme } from "../context/theme"
33
import { useSync } from "@tui/context/sync"
4-
import { For, Match, Switch, Show, createMemo } from "solid-js"
4+
import { For, Match, Switch, Show, createMemo, createResource } from "solid-js"
55

66
export type DialogStatusProps = {}
77

8+
async function getPluginVersion(path: string): Promise<string | undefined> {
9+
try {
10+
const nodeModulesIndex = path.indexOf("/node_modules/")
11+
if (nodeModulesIndex === -1) return undefined
12+
13+
const afterNodeModules = path.substring(nodeModulesIndex + "/node_modules/".length)
14+
const parts = afterNodeModules.split("/")
15+
const isScoped = parts[0].startsWith("@")
16+
const packagePath = isScoped
17+
? path.substring(0, nodeModulesIndex) + "/node_modules/" + parts[0] + "/" + parts[1]
18+
: path.substring(0, nodeModulesIndex) + "/node_modules/" + parts[0]
19+
20+
const packageJsonPath = packagePath + "/package.json"
21+
const packageJson = await Bun.file(packageJsonPath).json()
22+
return packageJson.version
23+
} catch {
24+
return undefined
25+
}
26+
}
27+
828
export function DialogStatus() {
929
const sync = useSync()
1030
const { theme } = useTheme()
@@ -24,7 +44,7 @@ export function DialogStatus() {
2444
const parts = afterNodeModules.split("/")
2545
// Handle scoped packages (@scope/package)
2646
const name = parts[0].startsWith("@") ? `${parts[0]}/${parts[1]}` : parts[0]
27-
return { raw: plugin, name, type: "npm" as const }
47+
return { raw: plugin, name, type: "npm" as const, path }
2848
}
2949

3050
// Local file plugin
@@ -145,24 +165,31 @@ export function DialogStatus() {
145165
<box>
146166
<text fg={theme.text}>{plugins().length} Plugins</text>
147167
<For each={plugins()}>
148-
{(item) => (
149-
<box flexDirection="row" gap={1}>
150-
<text
151-
flexShrink={0}
152-
style={{
153-
fg: theme.success,
154-
}}
155-
>
156-
157-
</text>
158-
<text wrapMode="word" fg={theme.text}>
159-
<b>{item.name}</b>
160-
<Show when={item.type === "npm" && item.version}>
161-
<span style={{ fg: theme.textMuted }}> @{item.version}</span>
162-
</Show>
163-
</text>
164-
</box>
165-
)}
168+
{(item) => {
169+
const [version] =
170+
item.type === "npm" && "path" in item && item.path
171+
? createResource(() => getPluginVersion(item.path!))
172+
: [() => (item.type === "npm" && "version" in item ? item.version : undefined)]
173+
174+
return (
175+
<box flexDirection="row" gap={1}>
176+
<text
177+
flexShrink={0}
178+
style={{
179+
fg: theme.success,
180+
}}
181+
>
182+
183+
</text>
184+
<text wrapMode="word" fg={theme.text}>
185+
<b>{item.name}</b>
186+
<Show when={item.type === "npm" && version()}>
187+
<span style={{ fg: theme.textMuted }}> @{version()}</span>
188+
</Show>
189+
</text>
190+
</box>
191+
)
192+
}}
166193
</For>
167194
</box>
168195
</Show>

0 commit comments

Comments
 (0)