Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/changeset-preview/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@changesets/get-release-plan": "^4.0.16"
"get-release-plan-v4": "npm:@changesets/get-release-plan@^4.0.16",
"get-release-plan-v5": "npm:@changesets/get-release-plan@^5.0.2"
}
}
48 changes: 45 additions & 3 deletions .github/changeset-preview/preview-changeset-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,56 @@
* Uses `@changesets/get-release-plan` to get the version bumps and formats it as markdown.
*/

import { writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { readFileSync, writeFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { join, resolve } from 'node:path'
import { parseArgs } from 'node:util'
import getReleasePlan from '@changesets/get-release-plan'

const GITHUB_WORKSPACE = resolve(process.env.GITHUB_WORKSPACE)

console.log(`Using workspace: ${GITHUB_WORKSPACE}`)

/**
* Release plan semantics differ between changesets majors (e.g. v2 bumps peer
* dependents to major unless `onlyUpdatePeerDependentsWhenOutOfRange` is set,
* v3 doesn't), so use the `get-release-plan` major that matches the
* `@changesets/cli` the workspace actually releases with.
*/
const RELEASE_PLAN_BY_CLI_MAJOR = {
2: 'get-release-plan-v4',
3: 'get-release-plan-v5',
}
const DEFAULT_CLI_MAJOR = 3

function getChangesetsCliMajor() {
try {
const require = createRequire(join(GITHUB_WORKSPACE, 'package.json'))
const pkgPath = require.resolve('@changesets/cli/package.json')
const { version } = JSON.parse(readFileSync(pkgPath, 'utf8'))
console.log(`Found @changesets/cli@${version}`)
return Number(version.split('.')[0])
} catch {
console.warn(
`Could not resolve @changesets/cli from workspace, assuming v${DEFAULT_CLI_MAJOR}`,
)
return DEFAULT_CLI_MAJOR
}
}

async function loadGetReleasePlan() {
const cliMajor = getChangesetsCliMajor()
let pkg = RELEASE_PLAN_BY_CLI_MAJOR[cliMajor]
if (!pkg) {
console.warn(
`Unsupported @changesets/cli major v${cliMajor}, falling back to v${DEFAULT_CLI_MAJOR}`,
)
pkg = RELEASE_PLAN_BY_CLI_MAJOR[DEFAULT_CLI_MAJOR]
}
console.log(`Using ${pkg}`)
const { default: getReleasePlan } = await import(pkg)
return getReleasePlan
}

function reasonRank(reason) {
return reason === 'Changeset' ? 2 : 1
}
Expand All @@ -27,6 +68,7 @@ async function main() {
allowPositionals: false,
})

const getReleasePlan = await loadGetReleasePlan()
const releasePlan = await getReleasePlan(GITHUB_WORKSPACE)
const releases = releasePlan.releases

Expand Down
Loading