mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 06:45:22 +00:00
refactor
This commit is contained in:
@@ -529,8 +529,8 @@ const Screen = (props: {
|
||||
<text fg={skin.text}>Route: {props.route.screen}</text>
|
||||
<text fg={skin.muted}>plugin state: {props.meta.state}</text>
|
||||
<text fg={skin.muted}>
|
||||
first: {props.meta.first ? "yes" : "no"} · updated: {props.meta.updated ? "yes" : "no"} · loads:{" "}
|
||||
{props.meta.entry.load_count}
|
||||
first: {props.meta.state === "first" ? "yes" : "no"} · updated:{" "}
|
||||
{props.meta.state === "updated" ? "yes" : "no"} · loads: {props.meta.entry.load_count}
|
||||
</text>
|
||||
<text fg={skin.muted}>plugin source: {props.meta.entry.source}</text>
|
||||
<text fg={skin.muted}>source: {value.source}</text>
|
||||
|
||||
@@ -220,14 +220,10 @@ export namespace TuiPlugin {
|
||||
const init: TuiPluginInit = meta
|
||||
? {
|
||||
state: meta.state,
|
||||
first: meta.state === "new",
|
||||
updated: meta.state === "changed",
|
||||
entry: meta.entry,
|
||||
}
|
||||
: {
|
||||
state: "new",
|
||||
first: true,
|
||||
updated: false,
|
||||
state: "first",
|
||||
entry: {
|
||||
name: spec,
|
||||
source: spec.startsWith("file://") ? "file" : "npm",
|
||||
|
||||
@@ -25,7 +25,7 @@ export namespace PluginMeta {
|
||||
fingerprint: string
|
||||
}
|
||||
|
||||
export type State = "new" | "changed" | "same"
|
||||
export type State = "first" | "updated" | "same"
|
||||
|
||||
type Store = Record<string, Entry>
|
||||
type Core = Omit<Entry, "first_time" | "last_time" | "time_changed" | "load_count" | "fingerprint">
|
||||
@@ -135,8 +135,8 @@ export namespace PluginMeta {
|
||||
fingerprint: fingerprint(core),
|
||||
}
|
||||
|
||||
const state: State = !prev ? "new" : prev.fingerprint === entry.fingerprint ? "same" : "changed"
|
||||
if (state === "changed") entry.time_changed = now
|
||||
const state: State = !prev ? "first" : prev.fingerprint === entry.fingerprint ? "same" : "updated"
|
||||
if (state === "updated") entry.time_changed = now
|
||||
|
||||
cache.store[id] = entry
|
||||
cache.dirty = true
|
||||
|
||||
@@ -118,11 +118,9 @@ export const object_plugin = {
|
||||
await Bun.write(options.source, JSON.stringify({ theme: { primary: "#fefefe" } }, null, 2))
|
||||
await input.api.theme.install(options.theme_path)
|
||||
const second = await Bun.file(options.dest).text()
|
||||
const init_state = init?.state ?? null
|
||||
const init_first = init?.first ?? null
|
||||
const init_updated = init?.updated ?? null
|
||||
const init_source = init?.entry?.source ?? null
|
||||
const init_load_count = init?.entry?.load_count ?? null
|
||||
const init_state = init.state
|
||||
const init_source = init.entry.source
|
||||
const init_load_count = init.entry.load_count
|
||||
await Bun.write(
|
||||
options.marker,
|
||||
JSON.stringify({
|
||||
@@ -144,8 +142,6 @@ export const object_plugin = {
|
||||
open_after,
|
||||
open_clear,
|
||||
init_state,
|
||||
init_first,
|
||||
init_updated,
|
||||
init_source,
|
||||
init_load_count,
|
||||
}),
|
||||
@@ -170,11 +166,9 @@ export const object_plugin = {
|
||||
before,
|
||||
after,
|
||||
text,
|
||||
init_state: init?.state ?? null,
|
||||
init_first: init?.first ?? null,
|
||||
init_updated: init?.updated ?? null,
|
||||
init_source: init?.entry?.source ?? null,
|
||||
init_load_count: init?.entry?.load_count ?? null,
|
||||
init_state: init.state,
|
||||
init_source: init.entry.source,
|
||||
init_load_count: init.entry.load_count,
|
||||
}),
|
||||
)
|
||||
},
|
||||
@@ -196,11 +190,9 @@ export const object_plugin = {
|
||||
has,
|
||||
set_installed,
|
||||
selected: input.api.theme.selected,
|
||||
init_state: init?.state ?? null,
|
||||
init_first: init?.first ?? null,
|
||||
init_updated: init?.updated ?? null,
|
||||
init_source: init?.entry?.source ?? null,
|
||||
init_load_count: init?.entry?.load_count ?? null,
|
||||
init_state: init.state,
|
||||
init_source: init.entry.source,
|
||||
init_load_count: init.entry.load_count,
|
||||
}),
|
||||
)
|
||||
},
|
||||
@@ -418,8 +410,6 @@ export const object_plugin = {
|
||||
expect(local.open_after).toBe(true)
|
||||
expect(local.open_clear).toBe(false)
|
||||
expect(local.init_state).toBe("same")
|
||||
expect(local.init_first).toBe(false)
|
||||
expect(local.init_updated).toBe(false)
|
||||
expect(local.init_source).toBe("file")
|
||||
expect(local.init_load_count).toBe(2)
|
||||
|
||||
@@ -427,9 +417,7 @@ export const object_plugin = {
|
||||
expect(global.has).toBe(true)
|
||||
expect(global.set_installed).toBe(true)
|
||||
expect(global.selected).toBe(tmp.extra.globalThemeName)
|
||||
expect(global.init_state).toBe("changed")
|
||||
expect(global.init_first).toBe(false)
|
||||
expect(global.init_updated).toBe(true)
|
||||
expect(global.init_state).toBe("updated")
|
||||
expect(global.init_source).toBe("file")
|
||||
expect(global.init_load_count).toBe(2)
|
||||
|
||||
@@ -438,9 +426,7 @@ export const object_plugin = {
|
||||
expect(preloaded.after).toBe(true)
|
||||
expect(preloaded.text).toContain("#303030")
|
||||
expect(preloaded.text).not.toContain("#f0f0f0")
|
||||
expect(preloaded.init_state).toBe("new")
|
||||
expect(preloaded.init_first).toBe(true)
|
||||
expect(preloaded.init_updated).toBe(false)
|
||||
expect(preloaded.init_state).toBe("first")
|
||||
expect(preloaded.init_source).toBe("file")
|
||||
expect(preloaded.init_load_count).toBe(1)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ describe("plugin.meta", () => {
|
||||
const spec = pathToFileURL(tmp.extra.file).href
|
||||
|
||||
const one = await PluginMeta.touch(spec, spec)
|
||||
expect(one.state).toBe("new")
|
||||
expect(one.state).toBe("first")
|
||||
expect(one.entry.source).toBe("file")
|
||||
expect(one.entry.modified).toBeDefined()
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("plugin.meta", () => {
|
||||
await Bun.write(tmp.extra.file, "export default async () => ({ ok: true })\n")
|
||||
|
||||
const three = await PluginMeta.touch(spec, spec)
|
||||
expect(three.state).toBe("changed")
|
||||
expect(three.state).toBe("updated")
|
||||
expect(three.entry.load_count).toBe(3)
|
||||
expect((three.entry.modified ?? 0) >= (one.entry.modified ?? 0)).toBe(true)
|
||||
|
||||
@@ -66,7 +66,7 @@ describe("plugin.meta", () => {
|
||||
const file = process.env.OPENCODE_PLUGIN_META_FILE!
|
||||
|
||||
const one = await PluginMeta.touch("acme-plugin@latest", tmp.extra.mod)
|
||||
expect(one.state).toBe("new")
|
||||
expect(one.state).toBe("first")
|
||||
expect(one.entry.source).toBe("npm")
|
||||
expect(one.entry.requested).toBe("latest")
|
||||
expect(one.entry.version).toBe("1.0.0")
|
||||
@@ -74,7 +74,7 @@ describe("plugin.meta", () => {
|
||||
await Bun.write(tmp.extra.pkg, JSON.stringify({ name: "acme-plugin", version: "1.1.0" }, null, 2))
|
||||
|
||||
const two = await PluginMeta.touch("acme-plugin@latest", tmp.extra.mod)
|
||||
expect(two.state).toBe("changed")
|
||||
expect(two.state).toBe("updated")
|
||||
expect(two.entry.version).toBe("1.1.0")
|
||||
expect(two.entry.load_count).toBe(2)
|
||||
await PluginMeta.persist()
|
||||
|
||||
@@ -189,7 +189,7 @@ export type TuiEventBus = {
|
||||
) => () => void
|
||||
}
|
||||
|
||||
export type TuiPluginState = "new" | "changed" | "same"
|
||||
export type TuiPluginState = "first" | "updated" | "same"
|
||||
|
||||
export type TuiPluginMeta = {
|
||||
name: string
|
||||
@@ -208,8 +208,6 @@ export type TuiPluginMeta = {
|
||||
|
||||
export type TuiPluginInit = {
|
||||
state: TuiPluginState
|
||||
first: boolean
|
||||
updated: boolean
|
||||
entry: TuiPluginMeta
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user