GeezerVison is showing github.com — release: avoid package.json drift during publish · different-ai/opencode@5eaef6b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/plugin/script/publish.ts +21-15Lines changed: 21 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,22 +11,28 @@ async function published(name: string, version: string) { | 11 | 11 | } | 12 | 12 |
| 13 | 13 | await $`bun tsc` | 14 | | -const pkg = await import("../package.json").then( | 15 | | - (m) => m.default as { name: string; version: string; exports: Record<string, string> }, | 16 | | -) | 17 | | -const original = JSON.parse(JSON.stringify(pkg)) | | 14 | +const originalText = await Bun.file("package.json").text() | | 15 | +const pkg = JSON.parse(originalText) as { | | 16 | + name: string | | 17 | + version: string | | 18 | + exports: Record<string, string> | | 19 | +} | 18 | 20 | if (await published(pkg.name, pkg.version)) { | 19 | 21 | console.log(`already published ${pkg.name}@${pkg.version}`) | 20 | | - process.exit(0) | 21 | | -} | 22 | | -for (const [key, value] of Object.entries(pkg.exports)) { | 23 | | - const file = value.replace("./src/", "./dist/").replace(".ts", "") | 24 | | - // @ts-ignore | 25 | | - pkg.exports[key] = { | 26 | | - import: file + ".js", | 27 | | - types: file + ".d.ts", | | 22 | +} else { | | 23 | + for (const [key, value] of Object.entries(pkg.exports)) { | | 24 | + const file = value.replace("./src/", "./dist/").replace(".ts", "") | | 25 | + // @ts-ignore | | 26 | + pkg.exports[key] = { | | 27 | + import: file + ".js", | | 28 | + types: file + ".d.ts", | | 29 | + } | | 30 | + } | | 31 | + await Bun.write("package.json", JSON.stringify(pkg, null, 2)) | | 32 | + try { | | 33 | + await $`bun pm pack` | | 34 | + await $`npm publish *.tgz --tag ${Script.channel} --access public` | | 35 | + } finally { | | 36 | + await Bun.write("package.json", originalText) | 28 | 37 | } | 29 | 38 | } | 30 | | -await Bun.write("package.json", JSON.stringify(pkg, null, 2)) | 31 | | -await $`bun pm pack && npm publish *.tgz --tag ${Script.channel} --access public` | 32 | | -await Bun.write("package.json", JSON.stringify(original, null, 2)) | |
Collapse file Copy file name to clipboardExpand all lines: packages/sdk/js/script/publish.ts +11-8Lines changed: 11 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,12 +11,12 @@ async function published(name: string, version: string) { | 11 | 11 | return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0 | 12 | 12 | } | 13 | 13 |
| 14 | | -const pkg = (await import("../package.json").then((m) => m.default)) as { | | 14 | +const originalText = await Bun.file("package.json").text() | | 15 | +const pkg = JSON.parse(originalText) as { | 15 | 16 | name: string | 16 | 17 | version: string | 17 | 18 | exports: Record<string, unknown> | 18 | 19 | } | 19 | | -const original = JSON.parse(JSON.stringify(pkg)) | 20 | 20 | function transformExports(exports: Record<string, unknown>) { | 21 | 21 | return Object.fromEntries( | 22 | 22 | Object.entries(exports).map(([key, value]) => { | @@ -33,10 +33,13 @@ function transformExports(exports: Record<string, unknown>) { | 33 | 33 | } | 34 | 34 | if (await published(pkg.name, pkg.version)) { | 35 | 35 | console.log(`already published ${pkg.name}@${pkg.version}`) | 36 | | - process.exit(0) | | 36 | +} else { | | 37 | + pkg.exports = transformExports(pkg.exports) | | 38 | + await Bun.write("package.json", JSON.stringify(pkg, null, 2)) | | 39 | + try { | | 40 | + await $`bun pm pack` | | 41 | + await $`npm publish *.tgz --tag ${Script.channel} --access public` | | 42 | + } finally { | | 43 | + await Bun.write("package.json", originalText) | | 44 | + } | 37 | 45 | } | 38 | | -pkg.exports = transformExports(pkg.exports) | 39 | | -await Bun.write("package.json", JSON.stringify(pkg, null, 2)) | 40 | | -await $`bun pm pack` | 41 | | -await $`npm publish *.tgz --tag ${Script.channel} --access public` | 42 | | -await Bun.write("package.json", JSON.stringify(original, null, 2)) | |
Collapse file Copy file name to clipboardExpand all lines: script/publish.ts +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,11 +15,23 @@ const pkgjsons = await Array.fromAsync( | 15 | 15 | ).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist"))) | 16 | 16 |
| 17 | 17 | const extensionToml = fileURLToPath(new URL("../packages/extensions/zed/extension.toml", import.meta.url)) | | 18 | +const publishPackageJsons = ["packages/plugin/package.json", "packages/sdk/js/package.json"] | 18 | 19 |
| 19 | 20 | async function hasChanges() { | 20 | 21 | return (await $`git diff --quiet && git diff --cached --quiet`.nothrow()).exitCode !== 0 | 21 | 22 | } | 22 | 23 |
| | 24 | +async function hasPublishPackageJsonChanges() { | | 25 | + if ((await $`git diff --quiet -- ${publishPackageJsons}`.nothrow()).exitCode !== 0) return true | | 26 | + return (await $`git diff --cached --quiet -- ${publishPackageJsons}`.nothrow()).exitCode !== 0 | | 27 | +} | | 28 | + | | 29 | +async function logPublishPackageJsonChanges() { | | 30 | + await $`git status --short -- ${publishPackageJsons}` | | 31 | + await $`git diff -- ${publishPackageJsons}` | | 32 | + await $`git diff --cached -- ${publishPackageJsons}` | | 33 | +} | | 34 | + | 23 | 35 | async function releaseTagExists() { | 24 | 36 | return (await $`git rev-parse -q --verify refs/tags/${tag}`.nothrow()).exitCode === 0 | 25 | 37 | } | @@ -76,6 +88,11 @@ if (Script.release) { | 76 | 88 |
| 77 | 89 | if (Script.release && !Script.preview) { | 78 | 90 | await $`git fetch origin` | | 91 | + if (await hasPublishPackageJsonChanges()) { | | 92 | + console.error("publish scripts left package.json changes before syncing dev") | | 93 | + await logPublishPackageJsonChanges() | | 94 | + throw new Error("packages/plugin/package.json or packages/sdk/js/package.json changed during publish") | | 95 | + } | 79 | 96 | await $`git checkout -B dev origin/dev` | 80 | 97 | await prepareReleaseFiles() | 81 | 98 | if (await hasChanges()) { | |
|