core: prevent UI imports compiling TSX source · argszero/opencode@eeb5b1d · GitHub
Skip to content

Commit eeb5b1d

Browse files
committed
core: prevent UI imports compiling TSX source
1 parent f8ceb30 commit eeb5b1d

4 files changed

Lines changed: 58 additions & 2 deletions

File tree

packages/ui/package.json

Lines changed: 2 additions & 0 deletions

packages/ui/script/pack.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bun
2+
3+
import { $ } from "bun"
4+
import { rm } from "node:fs/promises"
5+
import path from "node:path"
6+
7+
export async function pack() {
8+
const original = await Bun.file("package.json").text()
9+
const pkg = JSON.parse(original) as {
10+
name: string
11+
version: string
12+
exports: Record<string, string | { types: string; import: string }>
13+
}
14+
const tarball = path.resolve(`${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`)
15+
16+
await $`bun run build`
17+
pkg.exports = Object.fromEntries(
18+
Object.entries(pkg.exports).map(([key, value]) => {
19+
if (typeof value !== "string" || (!value.endsWith(".ts") && !value.endsWith(".tsx"))) return [key, value]
20+
return [
21+
key,
22+
{
23+
types: value.replace("./src/", "./dist/").replace(/\.tsx?$/, ".d.ts"),
24+
import: value,
25+
},
26+
]
27+
}),
28+
)
29+
30+
await rm(tarball, { force: true })
31+
await Bun.write("package.json", JSON.stringify(pkg, null, 2) + "\n")
32+
try {
33+
await $`bun pm pack`
34+
return tarball
35+
} finally {
36+
await Bun.write("package.json", original)
37+
}
38+
}
39+
40+
if (import.meta.main) console.log(await pack())

packages/ui/script/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Script } from "@opencode-ai/script"
44
import { $ } from "bun"
55
import { rm } from "node:fs/promises"
66
import { fileURLToPath } from "node:url"
7+
import { pack } from "./pack"
78

89
process.chdir(fileURLToPath(new URL("..", import.meta.url)))
910

@@ -18,8 +19,7 @@ if ((await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode ==
1819
try {
1920
await $`bun run typecheck`
2021
await $`bun run test`
21-
await rm(tarball, { force: true })
22-
await $`bun pm pack`
22+
await pack()
2323
await $`npm publish ${tarball} --access public --tag ${Script.channel}`
2424
} finally {
2525
await rm(tarball, { force: true })

packages/ui/tsconfig.build.json

Lines changed: 14 additions & 0 deletions

0 commit comments

Comments
 (0)