Skip to content

Commit 8c3fc29

Browse files
authored
fix: get package manager (#22)
* fix: get package manager ---------
1 parent e41f8a2 commit 8c3fc29

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
1616
//
1717
// Don't love the flag, need to find a better name.
1818
const skipHint = process.argv.slice(2).includes('--skip-hints');
19-
const packageManager = /yarn/.test(process.env.npm_execpath)
20-
? 'yarn'
21-
: process.env.PNPM_PACKAGE_NAME
22-
? 'pnpm'
23-
: 'npm';
19+
const packageManager = getPkgManager();
2420

2521
prompts.intro(
2622
kl.trueColor(...brandColor)(
@@ -252,3 +248,13 @@ function installPackages(pkgs, opts) {
252248
},
253249
);
254250
}
251+
252+
/**
253+
* @returns {'yarn' | 'pnpm' | 'npm'}
254+
*/
255+
function getPkgManager() {
256+
const userAgent = process.env.npm_config_user_agent || ''
257+
if (userAgent.startsWith('yarn')) return 'yarn'
258+
if (userAgent.startsWith('pnpm')) return 'pnpm'
259+
return 'npm'
260+
}

0 commit comments

Comments
 (0)