@@ -210,11 +210,18 @@ export function createEsmAndCjsTests(
210
210
// Create a minimal package.json with requested dependencies (if any) and install them
211
211
const additionalDependencies = options ?. additionalDependencies ?? { } ;
212
212
if ( Object . keys ( additionalDependencies ) . length > 0 ) {
213
+ // Ensure Volta picks up the monorepo's pinned Node/Yarn versions even inside the tmp dir.
214
+ // Combined with the explicit `volta run yarn add` below, this guarantees we use the repo's toolchain.
215
+ // This avoids CI engine mismatches (e.g. packages requiring Node >= 20 while the system Node is 18).
216
+ const monorepoRootPackageJsonPath = join ( process . cwd ( ) , '../../package.json' ) ;
213
217
const packageJson = {
214
218
name : 'tmp-integration-test' ,
215
219
private : true ,
216
220
version : '0.0.0' ,
217
221
dependencies : additionalDependencies ,
222
+ volta : {
223
+ extends : monorepoRootPackageJsonPath ,
224
+ } ,
218
225
} as const ;
219
226
220
227
writeFileSync ( join ( tmpDirPath , 'package.json' ) , JSON . stringify ( packageJson , null , 2 ) ) ;
@@ -228,7 +235,15 @@ export function createEsmAndCjsTests(
228
235
} ) ;
229
236
230
237
if ( deps . length > 0 ) {
231
- const result = spawnSync ( 'yarn' , [ 'add' , '--non-interactive' , ...deps ] , {
238
+ // Install using Volta when available to enforce the monorepo's pinned Node/Yarn versions.
239
+ // Falls back to direct yarn if Volta is not on PATH (e.g. local dev without Volta).
240
+ const hasVolta = spawnSync ( 'volta' , [ '--version' ] , { encoding : 'utf8' } ) . status === 0 ;
241
+ const cmd = hasVolta ? 'volta' : 'yarn' ;
242
+ const args = hasVolta
243
+ ? [ 'run' , 'yarn' , 'add' , '--non-interactive' , ...deps ]
244
+ : [ 'add' , '--non-interactive' , ...deps ] ;
245
+
246
+ const result = spawnSync ( cmd , args , {
232
247
cwd : tmpDirPath ,
233
248
encoding : 'utf8' ,
234
249
} ) ;
@@ -237,9 +252,9 @@ export function createEsmAndCjsTests(
237
252
// eslint-disable-next-line no-console
238
253
console . log ( '[additionalDependencies]' , deps . join ( ' ' ) ) ;
239
254
// eslint-disable-next-line no-console
240
- console . log ( '[yarn stdout]' , result . stdout ) ;
255
+ console . log ( `[ ${ cmd } stdout]` , result . stdout ) ;
241
256
// eslint-disable-next-line no-console
242
- console . log ( '[yarn stderr]' , result . stderr ) ;
257
+ console . log ( `[ ${ cmd } stderr]` , result . stderr ) ;
243
258
}
244
259
245
260
if ( result . error ) {
0 commit comments