@@ -560,7 +560,10 @@ it(`should not override the package manager exit code`, async () => {
560
560
} ) ;
561
561
} ) ;
562
562
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
+
564
567
await xfs . mktempPromise ( async cwd => {
565
568
await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
566
569
packageManager : `yarn@2.2.2` ,
@@ -575,9 +578,9 @@ it(`should not override the package manager exit code when it throws`, async ()
575
578
` ) ;
576
579
577
580
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` ) ,
581
584
} ) ;
582
585
} ) ;
583
586
} ) ;
@@ -606,3 +609,28 @@ it(`should not set the exit code after successfully launching the package manage
606
609
} ) ;
607
610
} ) ;
608
611
} ) ;
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 : `yarn@2.2.2` ,
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