diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24f3119a4aa..0d23a1b12cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,6 +84,11 @@ jobs: env: OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: ${{ runner.os == 'Windows' && 'true' || 'false' }} + - name: Verify published codemode package + if: runner.os == 'Linux' + working-directory: packages/codemode + run: bun run script/publish.ts --dry-run + - name: Verify compiled service lifecycle if: always() timeout-minutes: 10 diff --git a/packages/codemode/script/publish.ts b/packages/codemode/script/publish.ts index 8e37674b644..aa2d08b54a8 100644 --- a/packages/codemode/script/publish.ts +++ b/packages/codemode/script/publish.ts @@ -2,20 +2,26 @@ import { Script } from "@opencode-ai/script" import { $ } from "bun" -import { rm } from "node:fs/promises" +import { mkdtemp, rm } from "node:fs/promises" +import { tmpdir } from "node:os" +import { join } from "node:path" import { fileURLToPath } from "node:url" process.chdir(fileURLToPath(new URL("..", import.meta.url))) +const dryRun = Bun.argv.includes("--dry-run") const originalText = await Bun.file("package.json").text() const pkg = JSON.parse(originalText) as { name: string version: string exports: Record + imports: Record> } const tarball = `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz` +const output = (value: string, types = false) => + value.replace("./src/", "./dist/").replace(/\.ts$/, types ? ".d.ts" : ".js") -if ((await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode === 0) { +if (!dryRun && (await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode === 0) { console.log(`already published ${pkg.name}@${pkg.version}`) process.exit(0) } @@ -29,16 +35,38 @@ try { return [ key, { - import: value.replace("./src/", "./dist/").replace(/\.ts$/, ".js"), - types: value.replace("./src/", "./dist/").replace(/\.ts$/, ".d.ts"), + import: output(value), + types: output(value, true), }, ] }), ) + pkg.imports = Object.fromEntries( + Object.entries(pkg.imports).map(([key, conditions]) => [ + key, + Object.fromEntries(Object.entries(conditions).map(([condition, value]) => [condition, output(value)])), + ]), + ) await Bun.write("package.json", JSON.stringify(pkg, null, 2) + "\n") await rm(tarball, { force: true }) await $`bun pm pack` - await $`npm publish ${tarball} --tag ${Script.channel} --access public` + const consumer = await mkdtemp(join(tmpdir(), "opencode-codemode-")) + try { + await Bun.write( + join(consumer, "package.json"), + JSON.stringify({ + private: true, + type: "module", + dependencies: { [pkg.name]: `file:${join(process.cwd(), tarball)}` }, + }), + ) + await $`npm install --ignore-scripts --no-audit --no-fund`.cwd(consumer) + await $`node --input-type=module -e ${`await import(${JSON.stringify(pkg.name)})`}`.cwd(consumer) + await $`bun --conditions=workerd -e ${`await import(${JSON.stringify(pkg.name)})`}`.cwd(consumer) + } finally { + await rm(consumer, { recursive: true, force: true }) + } + if (!dryRun) await $`npm publish ${tarball} --tag ${Script.channel} --access public` } finally { await Bun.write("package.json", originalText) await rm(tarball, { force: true })