release: avoid package.json drift during publish
This commit is contained in:
parent
c5c38cad9c
commit
5eaef6b758
@ -11,22 +11,28 @@ async function published(name: string, version: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await $`bun tsc`
|
await $`bun tsc`
|
||||||
const pkg = await import("../package.json").then(
|
const originalText = await Bun.file("package.json").text()
|
||||||
(m) => m.default as { name: string; version: string; exports: Record<string, string> },
|
const pkg = JSON.parse(originalText) as {
|
||||||
)
|
name: string
|
||||||
const original = JSON.parse(JSON.stringify(pkg))
|
version: string
|
||||||
|
exports: Record<string, string>
|
||||||
|
}
|
||||||
if (await published(pkg.name, pkg.version)) {
|
if (await published(pkg.name, pkg.version)) {
|
||||||
console.log(`already published ${pkg.name}@${pkg.version}`)
|
console.log(`already published ${pkg.name}@${pkg.version}`)
|
||||||
process.exit(0)
|
} else {
|
||||||
}
|
for (const [key, value] of Object.entries(pkg.exports)) {
|
||||||
for (const [key, value] of Object.entries(pkg.exports)) {
|
const file = value.replace("./src/", "./dist/").replace(".ts", "")
|
||||||
const file = value.replace("./src/", "./dist/").replace(".ts", "")
|
// @ts-ignore
|
||||||
// @ts-ignore
|
pkg.exports[key] = {
|
||||||
pkg.exports[key] = {
|
import: file + ".js",
|
||||||
import: file + ".js",
|
types: file + ".d.ts",
|
||||||
types: file + ".d.ts",
|
}
|
||||||
|
}
|
||||||
|
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
|
||||||
|
try {
|
||||||
|
await $`bun pm pack`
|
||||||
|
await $`npm publish *.tgz --tag ${Script.channel} --access public`
|
||||||
|
} finally {
|
||||||
|
await Bun.write("package.json", originalText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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))
|
|
||||||
|
|||||||
@ -11,12 +11,12 @@ async function published(name: string, version: string) {
|
|||||||
return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0
|
return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkg = (await import("../package.json").then((m) => m.default)) as {
|
const originalText = await Bun.file("package.json").text()
|
||||||
|
const pkg = JSON.parse(originalText) as {
|
||||||
name: string
|
name: string
|
||||||
version: string
|
version: string
|
||||||
exports: Record<string, unknown>
|
exports: Record<string, unknown>
|
||||||
}
|
}
|
||||||
const original = JSON.parse(JSON.stringify(pkg))
|
|
||||||
function transformExports(exports: Record<string, unknown>) {
|
function transformExports(exports: Record<string, unknown>) {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(exports).map(([key, value]) => {
|
Object.entries(exports).map(([key, value]) => {
|
||||||
@ -33,10 +33,13 @@ function transformExports(exports: Record<string, unknown>) {
|
|||||||
}
|
}
|
||||||
if (await published(pkg.name, pkg.version)) {
|
if (await published(pkg.name, pkg.version)) {
|
||||||
console.log(`already published ${pkg.name}@${pkg.version}`)
|
console.log(`already published ${pkg.name}@${pkg.version}`)
|
||||||
process.exit(0)
|
} else {
|
||||||
|
pkg.exports = transformExports(pkg.exports)
|
||||||
|
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
|
||||||
|
try {
|
||||||
|
await $`bun pm pack`
|
||||||
|
await $`npm publish *.tgz --tag ${Script.channel} --access public`
|
||||||
|
} finally {
|
||||||
|
await Bun.write("package.json", originalText)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pkg.exports = transformExports(pkg.exports)
|
|
||||||
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
|
|
||||||
await $`bun pm pack`
|
|
||||||
await $`npm publish *.tgz --tag ${Script.channel} --access public`
|
|
||||||
await Bun.write("package.json", JSON.stringify(original, null, 2))
|
|
||||||
|
|||||||
@ -15,11 +15,23 @@ const pkgjsons = await Array.fromAsync(
|
|||||||
).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
|
).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
|
||||||
|
|
||||||
const extensionToml = fileURLToPath(new URL("../packages/extensions/zed/extension.toml", import.meta.url))
|
const extensionToml = fileURLToPath(new URL("../packages/extensions/zed/extension.toml", import.meta.url))
|
||||||
|
const publishPackageJsons = ["packages/plugin/package.json", "packages/sdk/js/package.json"]
|
||||||
|
|
||||||
async function hasChanges() {
|
async function hasChanges() {
|
||||||
return (await $`git diff --quiet && git diff --cached --quiet`.nothrow()).exitCode !== 0
|
return (await $`git diff --quiet && git diff --cached --quiet`.nothrow()).exitCode !== 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function hasPublishPackageJsonChanges() {
|
||||||
|
if ((await $`git diff --quiet -- ${publishPackageJsons}`.nothrow()).exitCode !== 0) return true
|
||||||
|
return (await $`git diff --cached --quiet -- ${publishPackageJsons}`.nothrow()).exitCode !== 0
|
||||||
|
}
|
||||||
|
|
||||||
|
async function logPublishPackageJsonChanges() {
|
||||||
|
await $`git status --short -- ${publishPackageJsons}`
|
||||||
|
await $`git diff -- ${publishPackageJsons}`
|
||||||
|
await $`git diff --cached -- ${publishPackageJsons}`
|
||||||
|
}
|
||||||
|
|
||||||
async function releaseTagExists() {
|
async function releaseTagExists() {
|
||||||
return (await $`git rev-parse -q --verify refs/tags/${tag}`.nothrow()).exitCode === 0
|
return (await $`git rev-parse -q --verify refs/tags/${tag}`.nothrow()).exitCode === 0
|
||||||
}
|
}
|
||||||
@ -76,6 +88,11 @@ if (Script.release) {
|
|||||||
|
|
||||||
if (Script.release && !Script.preview) {
|
if (Script.release && !Script.preview) {
|
||||||
await $`git fetch origin`
|
await $`git fetch origin`
|
||||||
|
if (await hasPublishPackageJsonChanges()) {
|
||||||
|
console.error("publish scripts left package.json changes before syncing dev")
|
||||||
|
await logPublishPackageJsonChanges()
|
||||||
|
throw new Error("packages/plugin/package.json or packages/sdk/js/package.json changed during publish")
|
||||||
|
}
|
||||||
await $`git checkout -B dev origin/dev`
|
await $`git checkout -B dev origin/dev`
|
||||||
await prepareReleaseFiles()
|
await prepareReleaseFiles()
|
||||||
if (await hasChanges()) {
|
if (await hasChanges()) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user