@@ -648,7 +648,7 @@ for (const name of SupportedPackageManagerSet) {
648648}
649649
650650describe ( `when called on a project without any defined packageManager` , ( ) => {
651- it ( `should append the field to package.json by default` , async ( ) => {
651+ it ( `should not modify package.json by default` , async ( ) => {
652652 await xfs . mktempPromise ( async cwd => {
653653 await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
654654 // empty package.json file
@@ -658,14 +658,12 @@ describe(`when called on a project without any defined packageManager`, () => {
658658
659659 const data = await xfs . readJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) ) ;
660660
661- expect ( data ) . toMatchObject ( {
662- packageManager : `yarn@${ config . definitions . yarn . default } ` ,
663- } ) ;
661+ expect ( Object . hasOwn ( data , `packageManager` ) ) . toBeFalsy ( ) ;
664662 } ) ;
665663 } ) ;
666664
667- it ( `should not modify package.json if disabled by env` , async ( ) => {
668- process . env . COREPACK_ENABLE_AUTO_PIN = `0 ` ;
665+ it ( `should modify package.json if enabled by env` , async ( ) => {
666+ process . env . COREPACK_ENABLE_AUTO_PIN = `1 ` ;
669667
670668 await xfs . mktempPromise ( async cwd => {
671669 await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
@@ -676,43 +674,46 @@ describe(`when called on a project without any defined packageManager`, () => {
676674
677675 const data = await xfs . readJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) ) ;
678676
679- expect ( Object . hasOwn ( data , `packageManager` ) ) . toBeFalsy ( ) ;
677+ expect ( data ) . toMatchObject ( {
678+ packageManager : expect . stringMatching ( / ^ y a r n @ / ) ,
679+ } ) ;
680680 } ) ;
681681 } ) ;
682682
683- it ( `should not modify package.json if disabled by .corepack.env` , async t => {
683+ it ( `should modify package.json if enabled by .corepack.env` , async t => {
684684 // Skip that test on Node.js 18.x as it lacks support for .env files.
685685 if ( process . version . startsWith ( `v18.` ) ) t . skip ( ) ;
686686
687687 await xfs . mktempPromise ( async cwd => {
688688 await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
689689 // empty package.json file
690690 } ) ;
691- await xfs . writeFilePromise ( ppath . join ( cwd , `.corepack.env` as Filename ) , `COREPACK_ENABLE_AUTO_PIN=0 \n` ) ;
691+ await xfs . writeFilePromise ( ppath . join ( cwd , `.corepack.env` as Filename ) , `COREPACK_ENABLE_AUTO_PIN=1 \n` ) ;
692692
693693 await runCli ( cwd , [ `yarn` ] ) ;
694694
695695 const data = await xfs . readJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) ) ;
696696
697- expect ( Object . hasOwn ( data , `packageManager` ) ) . toBeFalsy ( ) ;
697+ expect ( data ) . toMatchObject ( {
698+ packageManager : expect . stringMatching ( / ^ y a r n @ / ) ,
699+ } ) ;
698700 } ) ;
699701 } ) ;
700- it ( `should modify package.json if .corepack.env if disabled` , async ( ) => {
702+
703+ it ( `should not modify package.json if .corepack.env is disabled` , async ( ) => {
701704 process . env . COREPACK_ENV_FILE = `0` ;
702705
703706 await xfs . mktempPromise ( async cwd => {
704707 await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
705708 // empty package.json file
706709 } ) ;
707- await xfs . writeFilePromise ( ppath . join ( cwd , `.corepack.env` as Filename ) , `COREPACK_ENABLE_AUTO_PIN=0 \n` ) ;
710+ await xfs . writeFilePromise ( ppath . join ( cwd , `.corepack.env` as Filename ) , `COREPACK_ENABLE_AUTO_PIN=1 \n` ) ;
708711
709712 await runCli ( cwd , [ `yarn` ] ) ;
710713
711714 const data = await xfs . readJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) ) ;
712715
713- expect ( data ) . toMatchObject ( {
714- packageManager : `yarn@${ config . definitions . yarn . default } ` ,
715- } ) ;
716+ expect ( Object . hasOwn ( data , `packageManager` ) ) . toBeFalsy ( ) ;
716717 } ) ;
717718 } ) ;
718719} ) ;
@@ -1302,7 +1303,7 @@ it(`should download latest pnpm from custom registry`, async () => {
13021303 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
13031304 exitCode : 0 ,
13041305 stdout : `pnpm: Hello from custom registry\n` ,
1305- stderr :
expect . stringContaining ( `! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing [email protected] +sha1.` ) , 1306+ stderr : `` ,
13061307 } ) ;
13071308
13081309 // Should keep working with cache
@@ -1335,7 +1336,7 @@ describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
13351336 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
13361337 exitCode : 0 ,
13371338 stdout : `pnpm: Hello from custom registry\n` ,
1338- stderr : expect . stringContaining ( `The local project doesn't define a 'packageManager' field` ) ,
1339+ stderr : `` ,
13391340 } ) ;
13401341 } ) ;
13411342 } ) ;
@@ -1358,7 +1359,7 @@ describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
13581359 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
13591360 exitCode : 0 ,
13601361 stdout : `pnpm: Hello from custom registry\n` ,
1361- stderr : expect . stringContaining ( `The local project doesn't define a 'packageManager' field` ) ,
1362+ stderr : `` ,
13621363 } ) ;
13631364 } ) ;
13641365 } ) ;
@@ -1385,7 +1386,7 @@ describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
13851386 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
13861387 exitCode : 0 ,
13871388 stdout : `pnpm: Hello from custom registry\n` ,
1388- stderr : expect . stringContaining ( `The local project doesn't define a 'packageManager' field` ) ,
1389+ stderr : `` ,
13891390 } ) ;
13901391 } ) ;
13911392 } ) ;
@@ -1408,7 +1409,7 @@ describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
14081409 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
14091410 exitCode : 0 ,
14101411 stdout : `pnpm: Hello from custom registry\n` ,
1411- stderr : expect . stringContaining ( `The local project doesn't define a 'packageManager' field` ) ,
1412+ stderr : `` ,
14121413 } ) ;
14131414 } ) ;
14141415 } ) ;
@@ -1434,7 +1435,7 @@ describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
14341435 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
14351436 exitCode : 0 ,
14361437 stdout : `pnpm: Hello from custom registry\n` ,
1437- stderr : expect . stringContaining ( `The local project doesn't define a 'packageManager' field` ) ,
1438+ stderr : `` ,
14381439 } ) ;
14391440 } ) ;
14401441 } ) ;
@@ -1458,7 +1459,7 @@ describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
14581459 await expect ( runCli ( cwd , [ `pnpm` , `--version` ] , true ) ) . resolves . toMatchObject ( {
14591460 exitCode : 0 ,
14601461 stdout : `pnpm: Hello from custom registry\n` ,
1461- stderr : expect . stringContaining ( `The local project doesn't define a 'packageManager' field` ) ,
1462+ stderr : `` ,
14621463 } ) ;
14631464 } ) ;
14641465 } ) ;
0 commit comments