Files
next.js/scripts/release/version-packages.ts
T
Jimmy LaiGitHubgraphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>JJ Kasper
5c8fdbe104 misc: allow beta to be triggered (#84713)
![a-picture-of-a-bear-in-a-spaceship-with-the-words-i-have-no-idea-what-i-m-doing](https://github.com/user-attachments/assets/a53076b7-6d4c-4e98-b540-b4f6950d4901)

- update codemod script
- upgrade both release scripts, not sure which one is correct


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: JJ Kasper <[email protected]>
2025-10-09 16:28:52 -07:00

127 lines
3.5 KiB
TypeScript

import execa from 'execa'
import { existsSync } from 'fs'
import { writeFile, readFile, unlink } from 'fs/promises'
import { join } from 'path'
// NOTE: This type may change over time.
type ChangesetStatusJson = {
changesets: {
releases: {
name: string
type: string
summary: string
id: string
}[]
}[]
releases: {
name: string
type: string
oldVersion: string
changesets: string[]
newVersion: string
}[]
}
async function versionPackages() {
const preConfigPath = join(process.cwd(), '.changeset', 'pre.json')
// Exit previous pre mode to prepare for the next release.
if (existsSync(preConfigPath)) {
if (require(preConfigPath).mode !== 'exit') {
// Since current repository is in pre mode, need
// to exit before versioning the packages.
await execa('pnpm', ['changeset', 'pre', 'exit'], {
stdio: 'inherit',
})
}
}
// For prereleases, we need to set the "mode" on `pre.json`, which
// can be done by running `changeset pre enter <mode>`.
const releaseType = process.env.RELEASE_TYPE
switch (releaseType) {
case 'canary': {
// Enter pre mode as "canary" tag.
await execa('pnpm', ['changeset', 'pre', 'enter', 'canary'], {
stdio: 'inherit',
})
console.log(
'▲ Preparing to bump the canary version, checking if there are any changesets.'
)
// Create an empty changeset for `next` to bump the canary version
// even if there are no changesets for `next`.
await execa('pnpm', [
'changeset',
'status',
'--output',
'./changeset-status.json',
])
let hasNextChangeset = false
if (existsSync('./changeset-status.json')) {
const changesetStatus: ChangesetStatusJson = JSON.parse(
await readFile('./changeset-status.json', 'utf8')
)
console.log('▲ Changeset Status:')
console.log(changesetStatus)
hasNextChangeset =
changesetStatus.releases.find(
(release) => release.name === 'next'
) !== undefined
await unlink('./changeset-status.json')
}
if (!hasNextChangeset) {
console.log(
'▲ No changesets found for `next`, creating an empty changeset.'
)
// TODO: Since this is temporary until we hard-require a changeset, we will
// need to remove this in the future to prevent publishing empty releases.
await writeFile(
join(process.cwd(), '.changeset', `next-canary-${Date.now()}.md`),
`---\n'next': patch\n---`
)
}
break
}
case 'release-candidate': {
// Enter pre mode as "rc" tag.
await execa('pnpm', ['changeset', 'pre', 'enter', 'rc'], {
stdio: 'inherit',
})
break
}
case 'beta': {
// Enter pre mode as "beta" tag.
await execa('pnpm', ['changeset', 'pre', 'enter', 'beta'], {
stdio: 'inherit',
})
break
}
case 'stable': {
// No additional steps needed for 'stable' releases since we've already
// exited any pre-release mode. Only need to run `changeset version` after.
break
}
default: {
throw new Error(`Invalid release type: ${releaseType}`)
}
}
await execa('pnpm', ['changeset', 'version'], {
stdio: 'inherit',
})
// TODO: Update the pnpm-lock.yaml since the packages' depend on
// each other. Remove this once they use `workspace:` protocol.
await execa('pnpm', ['install', '--no-frozen-lockfile'], {
stdio: 'inherit',
})
}
versionPackages()