@@ -560,7 +560,10 @@ it(`should not override the package manager exit code`, async () => {
560560 } ) ;
561561} ) ;
562562
563- it ( `should not override the package manager exit code when it throws` , async ( ) => {
563+ it ( `should not preserve the process.exitCode when a package manager throws` , async ( ) => {
564+ // Node.js doesn't preserve process.exitCode when an exception is thrown
565+ // so we need to make sure we don't break this behaviour.
566+
564567 await xfs . mktempPromise ( async cwd => {
565568 await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
566569 packageManager :
`[email protected] ` , @@ -575,9 +578,9 @@ it(`should not override the package manager exit code when it throws`, async ()
575578 ` ) ;
576579
577580 await expect ( runCli ( cwd , [ `yarn` , `--version` ] ) ) . resolves . toMatchObject ( {
578- exitCode : 42 ,
579- stdout : expect . stringContaining ( `foo` ) ,
580- stderr : `` ,
581+ exitCode : 1 ,
582+ stdout : `` ,
583+ stderr : expect . stringContaining ( `foo` ) ,
581584 } ) ;
582585 } ) ;
583586} ) ;
@@ -606,3 +609,28 @@ it(`should not set the exit code after successfully launching the package manage
606609 } ) ;
607610 } ) ;
608611} ) ;
612+
613+ it ( `should support package managers in ESM format` , async ( ) => {
614+ await xfs . mktempPromise ( async cwd => {
615+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
616+ packageManager :
`[email protected] ` , 617+ } ) ;
618+
619+ const yarnDir = ppath . join ( npath . toPortablePath ( process . env . COREPACK_HOME ! ) , `yarn/2.2.2` as PortablePath ) ;
620+
621+ await xfs . mkdirPromise ( yarnDir , { recursive : true } ) ;
622+ await xfs . writeFilePromise ( ppath . join ( yarnDir , `yarn.js` as PortablePath ) , `
623+ import 'fs';
624+ console.log(42);
625+ ` ) ;
626+ await xfs . writeJsonPromise ( ppath . join ( yarnDir , `package.json` as PortablePath ) , {
627+ type : `module` ,
628+ } ) ;
629+
630+ await expect ( runCli ( cwd , [ `yarn` , `--version` ] ) ) . resolves . toMatchObject ( {
631+ exitCode : 0 ,
632+ stdout : `42\n` ,
633+ stderr : `` ,
634+ } ) ;
635+ } ) ;
636+ } ) ;
0 commit comments