refactor(release): rewrite publish scripts with Effect

Refactor the detached release flow and retry-safe package publishers into Effect.gen pipelines while preserving the stacked branch behavior from the release-fix PR.
This commit is contained in:
Kit Langton 2026-04-17 22:54:35 -04:00
commit 7f4dc4a249
5 changed files with 321 additions and 231 deletions

View file

@ -1,32 +1,46 @@
#!/usr/bin/env bun
import { Script } from "@opencode-ai/script"
import { $ } from "bun"
import { Effect } from "effect"
import { fileURLToPath } from "url"
const dir = fileURLToPath(new URL("..", import.meta.url))
process.chdir(dir)
async function published(name: string, version: string) {
return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0
type PackageJson = {
name: string
version: string
exports: Record<string, string>
}
await $`bun tsc`
const pkg = await import("../package.json").then(
(m) => m.default as { name: string; version: string; exports: Record<string, string> },
)
const original = JSON.parse(JSON.stringify(pkg))
if (await published(pkg.name, pkg.version)) {
console.log(`already published ${pkg.name}@${pkg.version}`)
process.exit(0)
}
for (const [key, value] of Object.entries(pkg.exports)) {
const file = value.replace("./src/", "./dist/").replace(".ts", "")
// @ts-ignore
pkg.exports[key] = {
import: file + ".js",
types: file + ".d.ts",
const published = (name: string, version: string) =>
Effect.promise(() => $`npm view ${name}@${version} version`.nothrow()).pipe(
Effect.map((result) => result.exitCode === 0),
)
const program = Effect.gen(function* () {
yield* Effect.promise(() => $`bun tsc`)
const pkg = (yield* Effect.promise(() => import("../package.json").then((m) => m.default))) as PackageJson
if (yield* published(pkg.name, pkg.version)) {
console.log(`already published ${pkg.name}@${pkg.version}`)
return
}
}
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
await $`bun pm pack && npm publish *.tgz --tag ${Script.channel} --access public`
await Bun.write("package.json", JSON.stringify(original, null, 2))
const next = {
...pkg,
exports: Object.fromEntries(
Object.entries(pkg.exports).map(([key, value]) => {
const file = value.replace("./src/", "./dist/").replace(".ts", "")
return [key, { import: file + ".js", types: file + ".d.ts" }]
}),
),
}
yield* Effect.promise(() => Bun.write("package.json", JSON.stringify(next, null, 2)))
yield* Effect.promise(() => $`bun pm pack && npm publish *.tgz --tag ${Script.channel} --access public`)
yield* Effect.promise(() => Bun.write("package.json", JSON.stringify(pkg, null, 2)))
})
await Effect.runPromise(program)