|
1 | | -// checks a GitHub release before it is published to npm, run by .github/workflows/release.yml: |
2 | | -// the tag matches package.json, the version is valid semver, newer than what npm has and listed in the changelog, |
3 | | -// prereleases are marked as such. Prints the npm dist-tag to publish under (and writes it to GITHUB_OUTPUT) |
| 1 | +// checks a GitHub release before it is published to npm and JSR, run by .github/workflows/release.yml: |
| 2 | +// the tag matches package.json and jsr.json, the version is valid semver, newer than what npm has, not on JSR yet and |
| 3 | +// listed in the changelog, prereleases are marked as such. Prints the npm dist-tag to publish under (and writes it to GITHUB_OUTPUT) |
4 | 4 | // usage: node scripts/release-check.js <tag> [prerelease flag of the GitHub release: true/false] |
5 | 5 | const fs = require('fs'); |
6 | 6 | const path = require('path'); |
7 | 7 |
|
8 | 8 | const root = path.join(__dirname, '..'); |
9 | 9 | const { name, version } = require('../package.json'); |
| 10 | +const jsr = require('../jsr.json'); |
10 | 11 | const [tag = '', prereleaseFlag = 'false'] = process.argv.slice(2); |
11 | 12 |
|
12 | 13 | const errors = []; |
@@ -50,6 +51,8 @@ async function main() { |
50 | 51 | fail(current.pre.length ? `${version} is a prerelease version, mark the GitHub release as prerelease` |
51 | 52 | : `the GitHub release is marked as prerelease, but ${version} has no prerelease suffix (like -beta.1)`); |
52 | 53 |
|
| 54 | + if (jsr.version !== version) fail(`jsr.json has version ${jsr.version}, package.json ${version} (npm run build syncs them)`); |
| 55 | + |
53 | 56 | const changelog = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8'); |
54 | 57 | if (!changelog.split('\n').some(line => /^##\s/.test(line) && line.replace(/^##\s+v?/, '').trim().split(/\s/)[0] === version)) |
55 | 58 | fail(`CHANGELOG.md has no "## ${version}" section`); |
@@ -83,6 +86,12 @@ async function main() { |
83 | 86 | else if (latest && compare(current, latest) < 0) distTag = `v${current.major}-latest`; |
84 | 87 | } |
85 | 88 |
|
| 89 | + // JSR has no dist-tags, its "latest" is the newest stable version |
| 90 | + const [scope, jsrName] = jsr.name.slice(1).split('/'); |
| 91 | + const jsrRes = await fetch(`https://api.jsr.io/scopes/${scope}/packages/${jsrName}/versions/${encodeURIComponent(version)}`); |
| 92 | + if (jsrRes.ok) fail(`${jsr.name}@${version} is already published on JSR`); |
| 93 | + else if (jsrRes.status !== 404) throw new Error(`JSR answered ${jsrRes.status}`); |
| 94 | + |
86 | 95 | if (errors.length) { |
87 | 96 | for (const e of errors) console.error(`::error::${e}`); |
88 | 97 | process.exit(1); |
|
0 commit comments