Skip to content

Commit ab97fd9

Browse files
committed
feat(opencode): setup Ink dependencies for TUI rewrite (anomalyco#11763)
- Add [email protected], [email protected], ink-spinner, ink-text-input - Create custom preload.ts to exclude cli/ink/ from SolidJS transform - Add tsconfig.ink.json for React JSX configuration - Add test component verifying Ink works with React 19 Fixes anomalyco#11763
1 parent 6981429 commit ab97fd9

10 files changed

Lines changed: 358 additions & 17 deletions

File tree

‎bun.lock‎

Lines changed: 199 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
},
6565
"devDependencies": {
6666
"@actions/artifact": "5.0.1",
67+
"@babel/plugin-transform-react-jsx": "7.28.6",
68+
"@babel/preset-react": "7.28.5",
6769
"@tsconfig/bun": "catalog:",
70+
"@types/react": "19.2.10",
6871
"husky": "9.1.7",
6972
"prettier": "3.6.2",
7073
"semver": "^7.6.0",

‎packages/opencode/bunfig.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
preload = ["@opentui/solid/preload"]
1+
preload = ["./preload.ts"]
22

33
[test]
44
preload = ["./test/preload.ts"]

‎packages/opencode/global.d.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
declare module "babel-preset-solid" {
2+
import type { ConfigAPI, PluginObj } from "@babel/core"
3+
type PluginOptions = object | undefined | false
4+
5+
export default function preset(api: ConfigAPI, options?: PluginOptions): PluginObj<unknown> | void
6+
}
7+
8+
declare module "@babel/preset-typescript" {
9+
import type { ConfigAPI, PluginObj } from "@babel/core"
10+
type PluginOptions = object | undefined | false
11+
12+
export default function preset(api: ConfigAPI, options?: PluginOptions): PluginObj<unknown> | void
13+
}
14+
15+
declare module "@opentui/solid/scripts/solid-plugin" {
16+
import type { BunPlugin } from "bun"
17+
18+
const plugin: BunPlugin
19+
export default plugin
20+
}

‎packages/opencode/package.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"typecheck": "tsgo --noEmit",
1010
"test": "bun test",
11+
"test:ink": "bun run src/cli/ink/test.tsx",
1112
"build": "bun run script/build.ts",
1213
"build:lite": "bun run script/build-lite.ts",
1314
"dev": "bun run --conditions=browser ./src/index.ts",
@@ -33,12 +34,12 @@
3334
"@parcel/watcher-linux-arm64-glibc": "2.5.1",
3435
"@parcel/watcher-linux-arm64-musl": "2.5.1",
3536
"@parcel/watcher-linux-x64-glibc": "2.5.1",
36-
"@parcel/watcher-linux-x64-musl": "2.5.1",
3737
"@parcel/watcher-win32-x64": "2.5.1",
3838
"@standard-schema/spec": "1.0.0",
3939
"@tsconfig/bun": "catalog:",
4040
"@types/babel__core": "7.20.5",
4141
"@types/bun": "catalog:",
42+
"@types/react": "19.2.10",
4243
"@types/turndown": "5.0.5",
4344
"@types/yargs": "17.0.33",
4445
"@typescript/native-preview": "catalog:",
@@ -103,11 +104,15 @@
103104
"hono": "catalog:",
104105
"hono-openapi": "catalog:",
105106
"ignore": "7.0.5",
107+
"ink": "6.6.0",
108+
"ink-spinner": "5.0.0",
109+
"ink-text-input": "6.0.0",
106110
"jsonc-parser": "3.3.1",
107111
"minimatch": "10.0.3",
108112
"open": "10.1.2",
109113
"opentui-spinner": "0.0.6",
110114
"partial-json": "0.1.7",
115+
"react": "19.2.4",
111116
"remeda": "catalog:",
112117
"solid-js": "catalog:",
113118
"strip-ansi": "7.1.2",

‎packages/opencode/preload.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { plugin, type BunPlugin } from "bun"
2+
import { transformAsync } from "@babel/core"
3+
import solid from "babel-preset-solid"
4+
import ts from "@babel/preset-typescript"
5+
6+
const inkExcludedPlugin: BunPlugin = {
7+
name: "solid-with-ink-exclusion",
8+
setup(build) {
9+
build.onLoad({ filter: /[\\/]node_modules[\\/]solid-js[\\/]dist[\\/]server\.js$/ }, async (args) => {
10+
try {
11+
const path = args.path.replace(/(\.server\.js)$/, ".solid.js")
12+
const file = Bun.file(path)
13+
if (!(await file.exists())) return undefined
14+
const code = await file.text()
15+
return { contents: code, loader: "js" }
16+
} catch {
17+
return undefined
18+
}
19+
})
20+
21+
build.onLoad({ filter: /[\\/]node_modules[\\/]solid-js[\\/]store[\\/]dist[\\/]server\.js$/ }, async (args) => {
22+
try {
23+
const path = args.path.replace(/(\.server\.js)$/, ".store.js")
24+
const file = Bun.file(path)
25+
if (!(await file.exists())) return undefined
26+
const code = await file.text()
27+
return { contents: code, loader: "js" }
28+
} catch {
29+
return undefined
30+
}
31+
})
32+
33+
build.onLoad({ filter: /\.(tsx|jsx)$/ }, async (args) => {
34+
if (args.path.includes("node_modules")) {
35+
return undefined
36+
}
37+
38+
const normalized = Bun.pathToFileURL(args.path).href
39+
40+
if (normalized.includes("cli/ink/")) {
41+
const code = await Bun.file(args.path).text()
42+
return { contents: code, loader: "tsx" }
43+
}
44+
45+
try {
46+
const code = await Bun.file(args.path).text()
47+
const transforms = await transformAsync(code, {
48+
filename: args.path,
49+
presets: [
50+
[
51+
solid,
52+
{
53+
moduleName: "@opentui/solid",
54+
generate: "universal",
55+
},
56+
],
57+
[ts],
58+
],
59+
})
60+
61+
if (!transforms || !transforms.code) {
62+
throw new Error(`Transform produced no output: ${args.path}`)
63+
}
64+
65+
return {
66+
contents: transforms.code,
67+
loader: "js",
68+
}
69+
} catch (error) {
70+
const errorMessage = error instanceof Error ? error.message : String(error)
71+
const errorStack = error instanceof Error ? error.stack : undefined
72+
const fullMessage = errorStack
73+
? `SolidJS transform failed for ${args.path}: ${errorMessage}\n${errorStack}`
74+
: `SolidJS transform failed for ${args.path}: ${errorMessage}`
75+
throw new Error(fullMessage)
76+
}
77+
})
78+
},
79+
}
80+
81+
plugin(inkExcludedPlugin)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { render, Text, Box } from "ink"
2+
3+
const App = () => (
4+
<Box flexDirection="column">
5+
<Text color="green">Ink works!</Text>
6+
<Text dimColor>Testing maxFps option</Text>
7+
</Box>
8+
)
9+
10+
const instance = render(<App />, {
11+
maxFps: 30,
12+
})
13+
14+
setTimeout(() => {
15+
instance.unmount()
16+
process.exit(0)
17+
}, 2000)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @jsxImportSource react */
2+
import { render, Text, Box } from "ink"
3+
4+
const App = () => (
5+
<Box flexDirection="column">
6+
<Text color="green">Ink works with React 19!</Text>
7+
<Text dimColor>Testing maxFps option</Text>
8+
</Box>
9+
)
10+
11+
if (import.meta.main) {
12+
const instance = render(<App />, {
13+
maxFps: 30,
14+
})
15+
16+
setTimeout(() => instance.unmount(), 2000)
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "./tsconfig.json",
4+
"compilerOptions": {
5+
"jsx": "react-jsx",
6+
"jsxImportSource": "react"
7+
},
8+
"include": ["src/cli/ink/**/*"]
9+
}

‎packages/opencode/tsconfig.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
"types": [],
99
"noUncheckedIndexedAccess": false,
1010
"customConditions": ["browser"],
11+
"moduleResolution": "bundler",
12+
"esModuleInterop": true,
13+
"skipLibCheck": true,
1114
"paths": {
1215
"@/*": ["./src/*"],
1316
"@tui/*": ["./src/cli/cmd/tui/*"]
1417
}
15-
}
18+
},
19+
"include": ["src/**/*", "test/**/*", "*.d.ts"]
1620
}

0 commit comments

Comments
 (0)