33import { readFile , writeFile } from 'node:fs/promises'
44
55import fg from 'fast-glob'
6- import { coerce , gt , gte , satisfies , valid } from 'semver'
6+ import { coerce , gt , gte , parse as parseSemver , satisfies , valid } from 'semver'
77import { execaCommand } from 'execa'
88
99const FUTURE_NEXT_PATCH_VERSION = '16.999.0'
@@ -193,7 +193,7 @@ export async function setNextVersionInFixture(
193193 const nextPeerDependencies = JSON . parse ( stdout )
194194
195195 if ( updateReact && nextVersionRequiresReact19 ( checkVersion ) ) {
196- // canaries started reporting peerDependencies as `^18.2.0 || 19.0.0-rc-<hash>-<date>`
196+ // canaries started reporting peerDependencies as `^18.2.0 || 19.0.0-rc-<hash>-<date> || ^19.0.0 `
197197 // with https://github.com/vercel/next.js/pull/70219 which is valid range for package managers
198198 // but not for @nx /next which checks dependencies and tries to assure that at least React 18 is used
199199 // but the check doesn't handle the alternative in version selector which thinks it's not valid:
@@ -205,14 +205,22 @@ export async function setNextVersionInFixture(
205205 . split ( '||' )
206206 . map ( ( alternative ) => {
207207 const selector = alternative . trim ( )
208- const coerced = coerce ( selector ) ?. format ( )
208+ // we need to pick the highest version from alternatives and to handle
209+ // comparison of both range selectors (^) and pinned prerelease version (-rc-<hash>-<date>)
210+ // we need to use couple of tricks:
211+ // 1. we do try to parse semver - this only works for pinned versions and will handle prereleases, it will return null for ranges
212+ // 2. if parsing returns null, we coerce
213+ // this will allow us to preserve prerelease identifiers for comparisons (as coercing prerelease version strip those)
214+
215+ const versionToCompare = ( parseSemver ( selector ) ?? coerce ( selector ) ) ?. format ( )
216+
209217 return {
210218 selector,
211- coerced ,
219+ versionToCompare ,
212220 }
213221 } )
214222 . sort ( ( a , b ) => {
215- return gt ( a . coerced , b . coerced ) ? - 1 : 1
223+ return gt ( a . versionToCompare , b . versionToCompare ) ? - 1 : 1
216224 } ) [ 0 ] . selector
217225
218226 const reactVersion =
0 commit comments