mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
A new pack-npm job applies the release version rewrite and runs the 14 library publish scripts in a pack-only mode (OPENCODE_NPM_PACK_DIR), with their typecheck, ui tests and codemode smoke install, and uploads the tarballs. It has only contents: read and no secrets. publish downloads them and sets OPENCODE_NPM_TARBALLS. script/publish.ts checks that every tarball exists and holds the expected name and version before it publishes anything, and each library script keeps its npm view check and then publishes its carried tarball instead of building again. Without either variable the scripts behave as before. The version rewrite moves to script/release-files.ts so publish and pack-npm share it.
55 lines
1.7 KiB
TypeScript
Executable file
55 lines
1.7 KiB
TypeScript
Executable file
#!/usr/bin/env bun
|
|
import { NpmLibraries } from "@opencode/script/npm"
|
|
import { $ } from "bun"
|
|
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
|
|
}
|
|
|
|
const originalText = await Bun.file("package.json").text()
|
|
const pkg = JSON.parse(originalText) as {
|
|
name: string
|
|
version: string
|
|
exports: Record<string, string>
|
|
imports: Record<string, Record<string, string>>
|
|
}
|
|
const tarball = `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`
|
|
const carried = await NpmLibraries.carried(tarball)
|
|
|
|
if (!carried) await $`bun run build`
|
|
if (!NpmLibraries.packDir && (await published(pkg.name, pkg.version))) {
|
|
console.log(`already published ${pkg.name}@${pkg.version}`)
|
|
} else if (carried) {
|
|
await NpmLibraries.publish(carried)
|
|
} else {
|
|
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",
|
|
}
|
|
}
|
|
pkg.imports = Object.fromEntries(
|
|
Object.entries(pkg.imports).map(([key, conditions]) => [
|
|
key,
|
|
Object.fromEntries(
|
|
Object.entries(conditions).map(([condition, value]) => [
|
|
condition,
|
|
value.replace("./src/", "./dist/").replace(/\.ts$/, ".js"),
|
|
]),
|
|
),
|
|
]),
|
|
)
|
|
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
|
|
try {
|
|
await $`bun pm pack`
|
|
await NpmLibraries.publish(tarball)
|
|
} finally {
|
|
await Bun.write("package.json", originalText)
|
|
}
|
|
}
|