opencode/packages/ui/script/publish.ts
Filip Hejmowski a26b0a73e4 fix(ci): keep dev previews and published libraries working with pack-npm
- when pack-npm fails on a non-release run, publish builds the libraries
  in place as before, so the CLI dev preview still ships after client
- library scripts skip versions already on npm in pack mode too, and
  NpmLibraries.verify accepts a missing tarball only for a published
  version, so a re-dispatched release does not rerun every check
- trim comments that restated code and correct inaccurate ones
2026-10-19 15:15:48 +02:00

34 lines
903 B
TypeScript

#!/usr/bin/env bun
import { NpmLibraries } from "@opencode/script/npm"
import { $ } from "bun"
import { rm } from "node:fs/promises"
import { fileURLToPath } from "node:url"
import { pack } from "./pack"
process.chdir(fileURLToPath(new URL("..", import.meta.url)))
const pkg = (await Bun.file("package.json").json()) as { name: string; version: string }
const tarball = `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`
if ((await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode === 0) {
console.log(`already published ${pkg.name}@${pkg.version}`)
process.exit(0)
}
const carried = await NpmLibraries.carried(tarball)
if (carried) {
await NpmLibraries.publish(carried)
process.exit(0)
}
try {
await $`bun run typecheck`
await $`bun run test`
await pack()
await NpmLibraries.publish(tarball)
} finally {
await rm(tarball, { force: true })
}