diff options
| author | Matt Pocock <mattpocockvoice@gmail.com> | 2026-08-05 18:54:44 +0100 |
|---|---|---|
| committer | Matt Pocock <mattpocockvoice@gmail.com> | 2026-08-05 18:54:44 +0100 |
| commit | f3554acafee0f1549d3f8f7881eca0634fd446d0 (patch) | |
| tree | 6e8eddb8c9c1205e7de571549c8746557bb5662d /scripts/sync-plugin-version.mjs | |
| parent | 07999e06b58541362f2f3d6de9e2b108ac28dc52 (diff) | |
chore: sync the plugin version from package.json on releasesync-plugin-version
`npm run version` now runs `changeset version` and then
`scripts/sync-plugin-version.mjs`, which copies the new version into
`.claude-plugin/plugin.json`. The release workflow calls `npm run version`
instead of `npx changeset version`, so the version PR carries both files.
Also closes the drift this replaces: `plugin.json` was manually bumped to
1.2.1 while `package.json` stayed at 1.2.0. `package.json` moves up to
1.2.1 so the plugin version never goes backwards.
`npm run check-plugin-version` reports drift without writing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'scripts/sync-plugin-version.mjs')
| -rw-r--r-- | scripts/sync-plugin-version.mjs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/sync-plugin-version.mjs b/scripts/sync-plugin-version.mjs new file mode 100644 index 0000000..c9e9907 --- /dev/null +++ b/scripts/sync-plugin-version.mjs @@ -0,0 +1,41 @@ +#!/usr/bin/env node +// Copies package.json's version into .claude-plugin/plugin.json. +// Runs as part of `npm run version`, immediately after `changeset version`. +// With --check it changes nothing and exits 1 if the two versions differ. + +import { readFileSync, writeFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const repo = join(dirname(fileURLToPath(import.meta.url)), ".."); +const pluginPath = join(repo, ".claude-plugin", "plugin.json"); + +const { version } = JSON.parse(readFileSync(join(repo, "package.json"), "utf8")); +const source = readFileSync(pluginPath, "utf8"); +const plugin = JSON.parse(source); + +if (plugin.version === version) { + console.log(`plugin.json version is ${version} — already in sync`); + process.exit(0); +} + +if (process.argv.includes("--check")) { + console.error( + `plugin.json version is ${plugin.version}, package.json is ${version}. Run \`node scripts/sync-plugin-version.mjs\`.`, + ); + process.exit(1); +} + +// Rewrite only the version line, to keep the key order and the formatting. +const updated = source.replace( + /("version"\s*:\s*")[^"]*(")/, + `$1${version}$2`, +); + +if (JSON.parse(updated).version !== version) { + console.error(`Could not find a version field to replace in ${pluginPath}.`); + process.exit(1); +} + +writeFileSync(pluginPath, updated); +console.log(`plugin.json version ${plugin.version} -> ${version}`); |
