@@ -4,6 +4,7 @@ import fs from 'fs-extra'
44import { Span } from 'next/src/trace'
55import { tmpdir } from 'node:os'
66import path from 'path'
7+ import { satisfies as satisfiesVersionRange } from 'semver'
78import { NextInstance } from './base'
89
910async function packNextRuntimeImpl ( ) {
@@ -58,6 +59,34 @@ export class NextDeployInstance extends NextInstance {
5859
5960 const setupStartTime = Date . now ( )
6061
62+ const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime ( )
63+
64+ this . dependencies = {
65+ ...( this . dependencies || { } ) ,
66+ // add the runtime package as a dependency
67+ [ runtimePackageName ] : `file:${ runtimePackageTarballPath } ` ,
68+ }
69+
70+ if (
71+ typeof this . files === 'string' &&
72+ this . files . includes ( 'back-forward-cache' ) &&
73+ process . env . NEXT_RESOLVED_VERSION &&
74+ satisfiesVersionRange ( process . env . NEXT_RESOLVED_VERSION , '<=15.5.4' )
75+ ) {
76+ require ( 'console' ) . log ( 'Pinning @types/react(-dom) for back-forward-cache test fixture' )
77+ // back-forward-cache test fixture is failing types checking because:
78+ // - @types/react(-dom) types are not pinned
79+ // - fixture uses react `unstable_Activity` export which since fixture was introduced is no longer unstable
80+ // and types were updated for that and no longer provide types for that export (instead provide for `Activity`)
81+ // this adds the pinning of types to version of types that still had `unstable_Activity` type
82+ this . dependencies [ '@types/react' ] = '19.1.1'
83+ this . dependencies [ '@types/react-dom' ] = '19.1.2'
84+ }
85+
86+ if ( ! this . buildCommand && this . buildArgs && this . buildArgs . length > 0 ) {
87+ this . buildCommand = `next build ${ this . buildArgs . join ( ' ' ) } `
88+ }
89+
6190 // create the test site
6291 await super . createTestDir ( { parentSpan, skipInstall : true } )
6392
@@ -70,10 +99,13 @@ export class NextDeployInstance extends NextInstance {
7099 await fs . rename ( nodeModules , nodeModulesBak )
71100 }
72101
73- const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime ( )
74-
75102 // install dependencies
76- await execa ( 'npm' , [ 'i' , runtimePackageTarballPath , '--legacy-peer-deps' ] , {
103+ // --force is used to match behavior of `pnpm install --strict-peer-dependencies=false` used by Vercel
104+ // there is a test fixture that have `@babel/preset-flow` as a dependency which has a peer dependency of `@babel/core@^7.0.0-0`,
105+ // but `@babel/core` is not specified as dependency, so we need to automatically attempt to install peer dependencies
106+ // but also not fail in case of peer dependency versions not matching for other fixtures, so `--legacy-peer-deps` is not good option here
107+ // https://github.com/vercel/next.js/blob/7453d200579512a6574f9c53edd716e5cc01615c/test/e2e/babel/index.test.js#L7-L9
108+ await execa ( 'npm' , [ 'install' , '--force' ] , {
77109 cwd : this . testDir ,
78110 stdio : 'inherit' ,
79111 } )
0 commit comments