@@ -361,6 +361,32 @@ describe(`should accept range in devEngines only if a specific version is provid
361361 } ) ;
362362 } ) ;
363363 } ) ;
364+ it ( `either in a different env file specified in env` , async ( ) => {
365+ await xfs . mktempPromise ( async cwd => {
366+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as PortablePath ) , {
367+ devEngines : {
368+ packageManager : {
369+ name : `pnpm` ,
370+ version : `6.x` ,
371+ } ,
372+ } ,
373+ } ) ;
374+ await expect ( runCli ( cwd , [ `pnpm` , `--version` ] ) ) . resolves . toMatchObject ( {
375+ exitCode : 1 ,
376+ stderr : `Invalid package manager specification in package.json (pnpm@6.x); expected a semver version\n` ,
377+ stdout : `` ,
378+ } ) ;
379+
380+ await xfs . writeFilePromise ( ppath . join ( cwd , `.env` as PortablePath ) ,
381+ `COREPACK_DEV_ENGINES_PNPM=6.6.2+sha224.eb5c0acad3b0f40ecdaa2db9aa5a73134ad256e17e22d1419a2ab073\n` ) ;
382+ process . env . COREPACK_ENV_FILE = `.env` ;
383+ await expect ( runCli ( cwd , [ `pnpm` , `--version` ] ) ) . resolves . toMatchObject ( {
384+ exitCode : 0 ,
385+ stderr : `` ,
386+ stdout : `6.6.2\n` ,
387+ } ) ;
388+ } ) ;
389+ } ) ;
364390 it ( `either in an env variable` , async ( ) => {
365391 await xfs . mktempPromise ( async cwd => {
366392 await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as PortablePath ) , {
@@ -419,6 +445,44 @@ describe(`should accept range in devEngines only if a specific version is provid
419445 } ) ;
420446} ) ;
421447
448+ it ( `Should use version from correct source` , async ( ) => {
449+ await xfs . mktempPromise ( async cwd => {
450+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as PortablePath ) , {
451+ devEngines : {
452+ packageManager : {
453+ name : `pnpm` ,
454+ version : `6.6.2+sha1.11111` ,
455+ } ,
456+ } ,
457+ } ) ;
458+ await xfs . writeFilePromise ( ppath . join ( cwd , `.corepack.env` as PortablePath ) , `COREPACK_DEV_ENGINES_PNPM=6.6.2+sha1.22222\n` ) ;
459+ await xfs . writeFilePromise ( ppath . join ( cwd , `.other.env` as PortablePath ) , `COREPACK_DEV_ENGINES_PNPM=6.6.2+sha1.33333\n` ) ;
460+
461+ // By default, it should pick up .corepack.env
462+ await expect ( runCli ( cwd , [ `pnpm` , `--version` ] ) ) . resolves . toMatchObject ( {
463+ exitCode : 1 ,
464+ stderr : expect . stringContaining ( `Mismatch hashes. Expected 22222, got 7b4d6b176c1b93b5670ed94c24babb7d80c13854` ) ,
465+ stdout : `` ,
466+ } ) ;
467+
468+ // When disabling env file, it should pick up the hash inn package.json
469+ process . env . COREPACK_ENV_FILE = `0` ;
470+ await expect ( runCli ( cwd , [ `pnpm` , `--version` ] ) ) . resolves . toMatchObject ( {
471+ exitCode : 1 ,
472+ stderr : expect . stringContaining ( `Mismatch hashes. Expected 11111, got 7b4d6b176c1b93b5670ed94c24babb7d80c13854` ) ,
473+ stdout : `` ,
474+ } ) ;
475+
476+ // When specifying another env file, this one should used
477+ process . env . COREPACK_ENV_FILE = `.other.env` ;
478+ await expect ( runCli ( cwd , [ `pnpm` , `--version` ] ) ) . resolves . toMatchObject ( {
479+ exitCode : 1 ,
480+ stderr : expect . stringContaining ( `Mismatch hashes. Expected 33333, got 7b4d6b176c1b93b5670ed94c24babb7d80c13854` ) ,
481+ stdout : `` ,
482+ } ) ;
483+ } ) ;
484+ } ) ;
485+
422486describe ( `should reject if range in devEngines does not match version provided` , ( ) => {
423487 it ( `in .corepack.env` , async ( ) => {
424488 await xfs . mktempPromise ( async cwd => {
0 commit comments