MCPcopy
hub / github.com/anomalyco/opencode / load

Function load

packages/opencode/test/cli/tui/plugin-loader.test.ts:142–581  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140}
141
142async function load(): Promise<Data> {
143 const stamp = Date.now()
144 const globalConfigPath = path.join(Global.Path.config, "tui.json")
145 const backup = await Bun.file(globalConfigPath)
146 .text()
147 .catch(() => undefined)
148
149 await using tmp = await tmpdir({
150 init: async (dir) => {
151 const localPluginPath = path.join(dir, "local-plugin.ts")
152 const invalidPluginPath = path.join(dir, "invalid-plugin.ts")
153 const preloadedPluginPath = path.join(dir, "preloaded-plugin.ts")
154 const globalPluginPath = path.join(dir, "global-plugin.ts")
155 const localSpec = pathToFileURL(localPluginPath).href
156 const invalidSpec = pathToFileURL(invalidPluginPath).href
157 const preloadedSpec = pathToFileURL(preloadedPluginPath).href
158 const globalSpec = pathToFileURL(globalPluginPath).href
159 const localThemeFile = `local-theme-${stamp}.json`
160 const invalidThemeFile = `invalid-theme-${stamp}.json`
161 const globalThemeFile = `global-theme-${stamp}.json`
162 const preloadedThemeFile = `preloaded-theme-${stamp}.json`
163 const localThemeName = localThemeFile.replace(/\.json$/, "")
164 const invalidThemeName = invalidThemeFile.replace(/\.json$/, "")
165 const globalThemeName = globalThemeFile.replace(/\.json$/, "")
166 const preloadedThemeName = preloadedThemeFile.replace(/\.json$/, "")
167 const localThemePath = path.join(dir, localThemeFile)
168 const invalidThemePath = path.join(dir, invalidThemeFile)
169 const globalThemePath = path.join(dir, globalThemeFile)
170 const preloadedThemePath = path.join(dir, preloadedThemeFile)
171 const localDest = path.join(dir, ".opencode", "themes", localThemeFile)
172 const globalDest = path.join(Global.Path.config, "themes", globalThemeFile)
173 const preloadedDest = path.join(dir, ".opencode", "themes", preloadedThemeFile)
174 const fnMarker = path.join(dir, "function-called.txt")
175 const localMarker = path.join(dir, "local-called.json")
176 const invalidMarker = path.join(dir, "invalid-called.json")
177 const globalMarker = path.join(dir, "global-called.json")
178 const preloadedMarker = path.join(dir, "preloaded-called.json")
179 const localConfigPath = path.join(dir, "tui.json")
180
181 await Bun.write(localThemePath, JSON.stringify({ theme: { primary: "#101010" } }, null, 2))
182 await Bun.write(invalidThemePath, "{ invalid json }")
183 await Bun.write(globalThemePath, JSON.stringify({ theme: { primary: "#202020" } }, null, 2))
184 await Bun.write(preloadedThemePath, JSON.stringify({ theme: { primary: "#f0f0f0" } }, null, 2))
185 await Bun.write(preloadedDest, JSON.stringify({ theme: { primary: "#303030" } }, null, 2))
186
187 await Bun.write(
188 localPluginPath,
189 `import { createBindingLookup } from "@opentui/keymap/extras"
190import { useBindings } from "@opentui/keymap/solid"
191
192export const ignored = async (_input, options) => {
193 if (!options?.fn_marker) return
194 await Bun.write(options.fn_marker, "called")
195}
196
197export default {
198 id: "demo.local",
199 tui: async (api, options) => {

Callers 1

Calls 10

tmpdirFunction · 0.90
createTuiResolvedConfigFunction · 0.90
createTuiPluginApiFunction · 0.90
addThemeFunction · 0.85
fileMethod · 0.80
writeMethod · 0.80
rowFunction · 0.70
textMethod · 0.65
initMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected