diff --git a/scripts/release/publish-npm.ts b/scripts/release/publish-npm.ts index 33d076604cb79..40e6d50f0c645 100644 --- a/scripts/release/publish-npm.ts +++ b/scripts/release/publish-npm.ts @@ -15,9 +15,11 @@ async function fetchTagsFromRegistry(packageName: string) { async function getTag({ name, version, + latest, }: { name: string version: string + latest: string }): Promise { const preConfigPath = join(process.cwd(), '.changeset', 'pre.json') @@ -40,6 +42,17 @@ async function getTag({ ) } + // If the current version is less than the latest, + // it means this is a backport release. Since NPM + // sets the 'latest' tag by default during publishing, + // when users install `next@latest`, they might get the + // backported version instead of the actual "latest" + // version. Hence, we explicitly set the tag as + // 'stable' for backports. + if (semver.lt(version, latest)) { + return 'stable' + } + return 'latest' } @@ -82,6 +95,7 @@ async function publishNpm() { const tag = await getTag({ name: pkgJson.name, version: pkgJson.version, + latest: tags.latest, }) const packagePath = join(packagesDir, packageDir.name)