@@ -70,7 +70,7 @@ export function nextVersionRequiresReact19(version) {
7070 * @param {'update' | 'revert' } [options.operation] This just informs log output wording, otherwise it has no effect
7171 * @param {boolean } [options.silent] Doesn't produce any logs if truthy
7272 * @param {boolean } [options.updateReact] Update React version to match Next version
73- * @returns {Promise<void> }
73+ * @returns {Promise<boolean> } true if fixture's next version requirements are satisfied
7474 */
7575export async function setNextVersionInFixture (
7676 cwd ,
@@ -87,40 +87,67 @@ export async function setNextVersionInFixture(
8787 // if resolved version is different from version, we add it to the log to provide additional details
8888 const nextVersionForLogs = `next@${ version } ${ resolvedVersion !== version ? ` (${ resolvedVersion } )` : `` } `
8989
90- if ( ! silent ) {
91- console . log (
92- `${ logPrefix } ▲ ${ operation === 'revert' ? 'Reverting' : 'Updating' } to ${ nextVersionForLogs } ...` ,
93- )
94- }
95-
9690 const packageJsons = await fg . glob ( [ '**/package.json' , '!**/node_modules' ] , {
9791 cwd,
9892 absolute : true ,
9993 } )
10094
10195 const isSemverVersion = valid ( resolvedVersion )
10296
103- await Promise . all (
97+ const areNextVersionConstraintsSatisfied = await Promise . all (
10498 packageJsons . map ( async ( packageJsonPath ) => {
10599 const packageJson = JSON . parse ( await readFile ( packageJsonPath , 'utf8' ) )
106100 if ( packageJson . dependencies ?. next ) {
107101 const versionConstraint = packageJson . test ?. dependencies ?. next
108102 // We can't use semver to check "canary" or "latest", so we use a fake future minor version
109103 const checkVersion = isSemverVersion ? resolvedVersion : FUTURE_NEXT_PATCH_VERSION
104+ console . log ( {
105+ checkVersion,
106+ versionConstraint,
107+ isNextCanary : isNextCanary ( ) ,
108+ } )
110109 if (
111110 operation === 'update' &&
112111 versionConstraint &&
113- ! satisfies ( checkVersion , versionConstraint , { includePrerelease : true } ) &&
112+ ! ( versionConstraint === 'canary'
113+ ? isNextCanary ( )
114+ : satisfies ( checkVersion , versionConstraint , { includePrerelease : true } ) ) &&
114115 version !== versionConstraint
115116 ) {
116117 if ( ! silent ) {
117118 console . log (
118119 `${ logPrefix } ⏩ Skipping '${ packageJson . name } ' because it requires next@${ versionConstraint } ` ,
119120 )
120121 }
121- return
122+ return false
122123 }
124+ }
125+ return true
126+ } ) ,
127+ )
128+
129+ if ( areNextVersionConstraintsSatisfied . some ( ( isSatisfied ) => ! isSatisfied ) ) {
130+ // at least one next version constraint is not satisfied so we skip this fixture
131+ return false
132+ }
133+
134+ if ( process . env . NEXT_VERSION ?? 'latest' === 'latest' ) {
135+ // latest is default so we don't want to make any changes
136+ return true
137+ }
138+
139+ if ( ! silent ) {
140+ console . log (
141+ `${ logPrefix } ▲ ${ operation === 'revert' ? 'Reverting' : 'Updating' } to ${ nextVersionForLogs } ...` ,
142+ )
143+ }
144+
145+ await Promise . all (
146+ packageJsons . map ( async ( packageJsonPath ) => {
147+ const packageJson = JSON . parse ( await readFile ( packageJsonPath , 'utf8' ) )
148+ if ( packageJson . dependencies ?. next ) {
123149 packageJson . dependencies . next = version
150+ const checkVersion = isSemverVersion ? resolvedVersion : FUTURE_NEXT_PATCH_VERSION
124151
125152 const { stdout } = await execaCommand (
126153 `npm info next@${ resolvedVersion } peerDependencies --json` ,
@@ -172,4 +199,6 @@ export async function setNextVersionInFixture(
172199 `${ logPrefix } ▲ ${ operation === 'revert' ? 'Reverted' : 'Updated' } to ${ nextVersionForLogs } ` ,
173200 )
174201 }
202+
203+ return true
175204}
0 commit comments