diff --git a/packages/opencode/script/publish.ts b/packages/opencode/script/publish.ts index 23c88e28fb..5af35468c5 100755 --- a/packages/opencode/script/publish.ts +++ b/packages/opencode/script/publish.ts @@ -14,6 +14,9 @@ const published = (name: string, version: string) => Effect.map((result) => result.exitCode === 0), ) +const sha256 = (path: string) => + Effect.promise(() => $`sha256sum ${path} | cut -d' ' -f1`.text()).pipe(Effect.map((text) => text.trim())) + const publishPackage = (dir: string, name: string, version: string) => Effect.gen(function* () { if (yield* published(name, version)) { @@ -92,18 +95,12 @@ const program = Effect.gen(function* () { if (Script.preview) return - const arm64Sha = (yield* Effect.promise(() => - $`sha256sum ./dist/opencode-linux-arm64.tar.gz | cut -d' ' -f1`.text(), - )).trim() - const x64Sha = (yield* Effect.promise(() => - $`sha256sum ./dist/opencode-linux-x64.tar.gz | cut -d' ' -f1`.text(), - )).trim() - const macX64Sha = (yield* Effect.promise(() => - $`sha256sum ./dist/opencode-darwin-x64.zip | cut -d' ' -f1`.text(), - )).trim() - const macArm64Sha = (yield* Effect.promise(() => - $`sha256sum ./dist/opencode-darwin-arm64.zip | cut -d' ' -f1`.text(), - )).trim() + const [arm64Sha, x64Sha, macX64Sha, macArm64Sha] = yield* Effect.all([ + sha256("./dist/opencode-linux-arm64.tar.gz"), + sha256("./dist/opencode-linux-x64.tar.gz"), + sha256("./dist/opencode-darwin-x64.zip"), + sha256("./dist/opencode-darwin-arm64.zip"), + ]) const [pkgver, subver = ""] = Script.version.split(/(-.*)/, 2) const binaryPkgbuild = [ diff --git a/packages/plugin/script/publish.ts b/packages/plugin/script/publish.ts index fd02f34967..4d22a0cfd0 100755 --- a/packages/plugin/script/publish.ts +++ b/packages/plugin/script/publish.ts @@ -14,15 +14,47 @@ type PackageJson = { exports: Record } +const packageJson = (value: unknown) => { + if ( + typeof value === "object" && + value !== null && + "name" in value && + typeof value.name === "string" && + "version" in value && + typeof value.version === "string" && + "exports" in value && + typeof value.exports === "object" && + value.exports !== null + ) { + return { + name: value.name, + version: value.version, + exports: Object.fromEntries( + Object.entries(value.exports).filter((entry): entry is [string, string] => typeof entry[1] === "string"), + ), + } + } + throw new Error("invalid plugin package manifest") +} + const published = (name: string, version: string) => Effect.promise(() => $`npm view ${name}@${version} version`.nothrow()).pipe( Effect.map((result) => result.exitCode === 0), ) +const withPackageJson = ( + pkg: PackageJson, + next: { name: string; version: string; exports: Record }, +) => + Effect.promise(() => Bun.write("package.json", JSON.stringify(next, null, 2))).pipe( + Effect.zipRight(Effect.promise(() => $`bun pm pack && npm publish *.tgz --tag ${Script.channel} --access public`)), + Effect.ensuring(Effect.promise(() => Bun.write("package.json", JSON.stringify(pkg, null, 2)))), + ) + const program = Effect.gen(function* () { yield* Effect.promise(() => $`bun tsc`) - const pkg = (yield* Effect.promise(() => import("../package.json").then((m) => m.default))) as PackageJson + const pkg = packageJson(yield* Effect.promise(() => import("../package.json").then((m) => m.default))) if (yield* published(pkg.name, pkg.version)) { console.log(`already published ${pkg.name}@${pkg.version}`) return @@ -38,9 +70,7 @@ const program = Effect.gen(function* () { ), } - 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))) + yield* withPackageJson(pkg, next) }) await Effect.runPromise(program) diff --git a/packages/sdk/js/script/publish.ts b/packages/sdk/js/script/publish.ts index faa1c407c1..4696afe661 100755 --- a/packages/sdk/js/script/publish.ts +++ b/packages/sdk/js/script/publish.ts @@ -34,6 +34,13 @@ const published = (name: string, version: string) => Effect.map((result) => result.exitCode === 0), ) +const withPackageJson = (pkg: ReturnType, next: ReturnType) => + Effect.promise(() => Bun.write("package.json", JSON.stringify(next, null, 2))).pipe( + Effect.zipRight(Effect.promise(() => $`bun pm pack`)), + Effect.zipRight(Effect.promise(() => $`npm publish *.tgz --tag ${Script.channel} --access public`)), + Effect.ensuring(Effect.promise(() => Bun.write("package.json", JSON.stringify(pkg, null, 2)))), + ) + function transformExports(exports: Record) { return Object.fromEntries( Object.entries(exports).map(([key, value]) => { @@ -59,10 +66,7 @@ const program = Effect.gen(function* () { exports: transformExports(pkg.exports), } - yield* Effect.promise(() => Bun.write("package.json", JSON.stringify(next, null, 2))) - yield* Effect.promise(() => $`bun pm pack`) - yield* Effect.promise(() => $`npm publish *.tgz --tag ${Script.channel} --access public`) - yield* Effect.promise(() => Bun.write("package.json", JSON.stringify(pkg, null, 2))) + yield* withPackageJson(pkg, next) }) await Effect.runPromise(program)