refactor(tui): extract standalone package (#31193)
This commit is contained in:
@@ -24,13 +24,15 @@ import { createStore, produce, reconcile } from "solid-js/store"
|
||||
import { useProject } from "./project"
|
||||
import { useEvent } from "./event"
|
||||
import { useSDK } from "./sdk"
|
||||
import { useTuiEnvironment } from "../runtime"
|
||||
import { useTuiStartup } from "./runtime"
|
||||
import { createSimpleContext } from "./helper"
|
||||
import { useExit } from "./exit"
|
||||
import { useRenderer } from "@opentui/solid"
|
||||
import { useArgs } from "./args"
|
||||
import { batch, onMount } from "solid-js"
|
||||
import path from "path"
|
||||
import { aggregateFailures } from "./aggregate-failures"
|
||||
import { useKV } from "./kv"
|
||||
import { destroyRenderer } from "../util/renderer"
|
||||
|
||||
const emptyConsoleState: ConsoleState = {
|
||||
consoleManagedProviders: [],
|
||||
@@ -50,19 +52,11 @@ function search<T>(items: T[], target: string, key: (item: T) => string) {
|
||||
return { found: false, index: left }
|
||||
}
|
||||
|
||||
export type SyncDependencies = {
|
||||
kv: { get(key: string, defaultValue: boolean): boolean }
|
||||
logger: { error(message: string, extra?: Record<string, unknown>): void }
|
||||
}
|
||||
|
||||
export const {
|
||||
context: SyncContext,
|
||||
use: useSync,
|
||||
provider: SyncProvider,
|
||||
} = createSimpleContext({
|
||||
export const { context: SyncContext, use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||
name: "Sync",
|
||||
init: (dependencies: SyncDependencies) => {
|
||||
const environment = useTuiEnvironment()
|
||||
init: () => {
|
||||
const startup = useTuiStartup()
|
||||
const kv = useKV()
|
||||
const [store, setStore] = createStore<{
|
||||
status: "loading" | "partial" | "complete"
|
||||
provider: Provider[]
|
||||
@@ -136,7 +130,6 @@ export const {
|
||||
const event = useEvent()
|
||||
const project = useProject()
|
||||
const sdk = useSDK()
|
||||
const kv = dependencies.kv
|
||||
|
||||
const fullSyncedSessions = new Set<string>()
|
||||
const syncingSessions = new Map<string, Promise<void>>()
|
||||
@@ -427,7 +420,7 @@ export const {
|
||||
}
|
||||
})
|
||||
|
||||
const exit = useExit()
|
||||
const renderer = useRenderer()
|
||||
const args = useArgs()
|
||||
|
||||
async function bootstrap(input: { fatal?: boolean } = {}) {
|
||||
@@ -520,13 +513,13 @@ export const {
|
||||
})
|
||||
})
|
||||
.catch(async (e) => {
|
||||
dependencies.logger.error("tui bootstrap failed", {
|
||||
console.error("tui bootstrap failed", {
|
||||
error: e instanceof Error ? e.message : String(e),
|
||||
name: e instanceof Error ? e.name : undefined,
|
||||
stack: e instanceof Error ? e.stack : undefined,
|
||||
})
|
||||
if (fatal) {
|
||||
await exit(e)
|
||||
destroyRenderer(renderer)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
@@ -544,7 +537,7 @@ export const {
|
||||
return store.status
|
||||
},
|
||||
get ready() {
|
||||
if (environment.skipInitialLoading) return true
|
||||
if (startup.skipInitialLoading) return true
|
||||
return store.status !== "loading"
|
||||
},
|
||||
get path() {
|
||||
|
||||
Reference in New Issue
Block a user