@@ -621,6 +621,95 @@ it(`should allow using transparent commands on npm-configured projects`, async (
621621 } ) ;
622622} ) ;
623623
624+ describe ( `should allow global install/uninstall commands in projects configured for a different package manager` , ( ) => {
625+ it ( `npm install -g in yarn project` , async ( ) => {
626+ await xfs . mktempPromise ( async cwd => {
627+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
628+ packageManager :
`[email protected] ` , 629+ } ) ;
630+
631+ // npm install -g --help should work (we use --help to avoid actual installation)
632+ await expect ( runCli ( cwd , [ `npm` , `install` , `-g` , `--help` ] ) ) . resolves . toMatchObject ( {
633+ exitCode : 0 ,
634+ } ) ;
635+ } ) ;
636+ } ) ;
637+
638+ it ( `npm uninstall --global in yarn project` , async ( ) => {
639+ await xfs . mktempPromise ( async cwd => {
640+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
641+ packageManager :
`[email protected] ` , 642+ } ) ;
643+
644+ await expect ( runCli ( cwd , [ `npm` , `uninstall` , `--global` , `--help` ] ) ) . resolves . toMatchObject ( {
645+ exitCode : 0 ,
646+ } ) ;
647+ } ) ;
648+ } ) ;
649+
650+ it ( `npm i -g in pnpm project` , async ( ) => {
651+ await xfs . mktempPromise ( async cwd => {
652+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
653+ packageManager :
`[email protected] ` , 654+ } ) ;
655+
656+ await expect ( runCli ( cwd , [ `npm` , `i` , `-g` , `--help` ] ) ) . resolves . toMatchObject ( {
657+ exitCode : 0 ,
658+ } ) ;
659+ } ) ;
660+ } ) ;
661+
662+ it ( `pnpm add -g in yarn project` , async ( ) => {
663+ await xfs . mktempPromise ( async cwd => {
664+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
665+ packageManager :
`[email protected] ` , 666+ } ) ;
667+
668+ await expect ( runCli ( cwd , [ `pnpm` , `add` , `-g` , `--help` ] ) ) . resolves . toMatchObject ( {
669+ exitCode : 0 ,
670+ } ) ;
671+ } ) ;
672+ } ) ;
673+
674+ it ( `pnpm remove --global in npm project` , async ( ) => {
675+ await xfs . mktempPromise ( async cwd => {
676+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
677+ packageManager :
`[email protected] ` , 678+ } ) ;
679+
680+ await expect ( runCli ( cwd , [ `pnpm` , `remove` , `--global` , `--help` ] ) ) . resolves . toMatchObject ( {
681+ exitCode : 0 ,
682+ } ) ;
683+ } ) ;
684+ } ) ;
685+
686+ it ( `yarn global add in npm project` , async ( ) => {
687+ await xfs . mktempPromise ( async cwd => {
688+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
689+ packageManager :
`[email protected] ` , 690+ } ) ;
691+
692+ // yarn global add should not be blocked by project packageManager
693+ // Note: If a Yarn version that doesn't support `global` is used,
694+ // Yarn itself will report an appropriate error.
695+ const result = await runCli ( cwd , [ `yarn` , `global` , `add` , `does-not-exist-pkg-12345` ] ) ;
696+ expect ( result . stderr ) . not . toContain ( `This project is configured to use` ) ;
697+ } ) ;
698+ } ) ;
699+
700+ it ( `yarn global remove in pnpm project` , async ( ) => {
701+ await xfs . mktempPromise ( async cwd => {
702+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
703+ packageManager :
`[email protected] ` , 704+ } ) ;
705+
706+ // yarn global remove should not be blocked by project packageManager
707+ const result = await runCli ( cwd , [ `yarn` , `global` , `remove` , `does-not-exist-pkg-12345` ] ) ;
708+ expect ( result . stderr ) . not . toContain ( `This project is configured to use` ) ;
709+ } ) ;
710+ } ) ;
711+ } ) ;
712+
624713it ( `should transparently use the preconfigured version when there is no local project` , async ( ) => {
625714 await xfs . mktempPromise ( async cwd => {
626715 await expect ( runCli ( cwd , [ `yarn` , `--version` ] ) ) . resolves . toMatchObject ( {
0 commit comments