Unverified Commit 85d043a6 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Create-next-app update message (#88706)

### What?

This PR fixes `create-next-app` update notifications for prerelease
versions by checking against the correct npm dist-tag.

### Why?

Users running `pnpx create-next-app@canary` were incorrectly prompted to
update to the stable version because:

1. The `update-check` library queries npm's `latest` dist-tag by default
2. Version comparison using `localeCompare` considers `16.1.1-canary.32`
less than `16.1.3` (since base version `16.1.1 < 16.1.3`)
3. This incorrectly triggered an update notification

### How?

Instead of skipping the update check entirely for prerelease versions,
this PR:

1. Extracts the dist-tag from the current version (e.g., `canary` from
`16.1.1-canary.32`)
2. Passes this as the `distTag` option to `update-check`
3. Updates the suggested command to include the correct tag (e.g., `pnpm
add -g create-next-app@canary`)

This ensures:
- Stable users are notified about newer stable releases
- Canary users are notified about newer canary releases
- Beta/RC users are notified about newer versions of their respective
channels
Co-authored-by: 's avatarCursor Agent <cursoragent@cursor.com>
parent 98fd3456
...@@ -656,7 +656,18 @@ async function run(): Promise<void> { ...@@ -656,7 +656,18 @@ async function run(): Promise<void> {
conf.set('preferences', preferences) conf.set('preferences', preferences)
} }
const update = updateCheck(packageJson).catch(() => null) // Determine the appropriate dist-tag to check for updates.
// For prerelease versions like "16.1.1-canary.32", extract "canary" and check
// against that dist-tag. This ensures canary users are notified about newer
// canary releases, not incorrectly prompted to "update" to stable.
function getDistTag(version: string): string {
const prereleaseMatch = version.match(/-([a-z]+)/)
return prereleaseMatch ? prereleaseMatch[1] : 'latest'
}
const update = updateCheck(packageJson, {
distTag: getDistTag(packageJson.version),
}).catch(() => null)
async function notifyUpdate(): Promise<void> { async function notifyUpdate(): Promise<void> {
try { try {
...@@ -667,7 +678,9 @@ async function notifyUpdate(): Promise<void> { ...@@ -667,7 +678,9 @@ async function notifyUpdate(): Promise<void> {
pnpm: 'pnpm add -g', pnpm: 'pnpm add -g',
bun: 'bun add -g', bun: 'bun add -g',
} }
const updateMessage = `${global[packageManager]} create-next-app` const distTag = getDistTag(packageJson.version)
const pkgTag = distTag === 'latest' ? '' : `@${distTag}`
const updateMessage = `${global[packageManager]} create-next-app${pkgTag}`
console.log( console.log(
yellow(bold('A new version of `create-next-app` is available!')) + yellow(bold('A new version of `create-next-app` is available!')) +
'\n' + '\n' +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment