refactor: unwrap TuiPluginRuntime namespace + self-reexport (#22980)
This commit is contained in:
@@ -918,13 +918,12 @@ async function installPluginBySpec(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace TuiPluginRuntime {
|
let dir = ""
|
||||||
let dir = ""
|
let loaded: Promise<void> | undefined
|
||||||
let loaded: Promise<void> | undefined
|
let runtime: RuntimeState | undefined
|
||||||
let runtime: RuntimeState | undefined
|
export const Slot = View
|
||||||
export const Slot = View
|
|
||||||
|
|
||||||
export async function init(input: { api: HostPluginApi; config: TuiConfig.Info }) {
|
export async function init(input: { api: HostPluginApi; config: TuiConfig.Info }) {
|
||||||
const cwd = process.cwd()
|
const cwd = process.cwd()
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
if (dir !== cwd) {
|
if (dir !== cwd) {
|
||||||
@@ -936,30 +935,30 @@ export namespace TuiPluginRuntime {
|
|||||||
dir = cwd
|
dir = cwd
|
||||||
loaded = load(input)
|
loaded = load(input)
|
||||||
return loaded
|
return loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
export function list() {
|
export function list() {
|
||||||
if (!runtime) return []
|
if (!runtime) return []
|
||||||
return listPluginStatus(runtime)
|
return listPluginStatus(runtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function activatePlugin(id: string) {
|
export async function activatePlugin(id: string) {
|
||||||
return activatePluginById(runtime, id, true)
|
return activatePluginById(runtime, id, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deactivatePlugin(id: string) {
|
export async function deactivatePlugin(id: string) {
|
||||||
return deactivatePluginById(runtime, id, true)
|
return deactivatePluginById(runtime, id, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addPlugin(spec: string) {
|
export async function addPlugin(spec: string) {
|
||||||
return addPluginBySpec(runtime, spec)
|
return addPluginBySpec(runtime, spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installPlugin(spec: string, options?: { global?: boolean }) {
|
export async function installPlugin(spec: string, options?: { global?: boolean }) {
|
||||||
return installPluginBySpec(runtime, spec, options?.global)
|
return installPluginBySpec(runtime, spec, options?.global)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dispose() {
|
export async function dispose() {
|
||||||
const task = loaded
|
const task = loaded
|
||||||
loaded = undefined
|
loaded = undefined
|
||||||
dir = ""
|
dir = ""
|
||||||
@@ -971,9 +970,9 @@ export namespace TuiPluginRuntime {
|
|||||||
for (const plugin of queue) {
|
for (const plugin of queue) {
|
||||||
await deactivatePluginEntry(state, plugin, false)
|
await deactivatePluginEntry(state, plugin, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load(input: { api: Api; config: TuiConfig.Info }) {
|
async function load(input: { api: Api; config: TuiConfig.Info }) {
|
||||||
const { api, config } = input
|
const { api, config } = input
|
||||||
const cwd = process.cwd()
|
const cwd = process.cwd()
|
||||||
const slots = setupSlots(api)
|
const slots = setupSlots(api)
|
||||||
@@ -1026,5 +1025,6 @@ export namespace TuiPluginRuntime {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
fail("failed to load tui plugins", { directory: cwd, error })
|
fail("failed to load tui plugins", { directory: cwd, error })
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * as TuiPluginRuntime from "./runtime"
|
||||||
|
|||||||
Reference in New Issue
Block a user