Skip to content

Commit 09c1261

Browse files
committed
feat: automatically set package manager
1 parent 8ce0a10 commit 09c1261

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/commands/index.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Args, Command, Flags } from '@oclif/core'
22
import { input } from '@inquirer/prompts'
33
import { run } from '@formidablejs/installer'
4-
import path = require('path')
4+
5+
type Mapper = {
6+
[key: string]: string
7+
}
58

69
export default class Create extends Command {
710
static description = 'Create a new Formidable application'
@@ -43,6 +46,27 @@ export default class Create extends Command {
4346
args.name = name
4447
}
4548

49+
if (!flags['use-pnpm'] && !flags['use-npm'] && !flags['use-yarn'] && !flags['use-bun'] && !flags.manager) {
50+
const userAgent = process.env.npm_config_user_agent
51+
52+
if (userAgent && typeof userAgent === 'string') {
53+
const agent = userAgent.split('/')[0]
54+
55+
const mapper: Mapper = {
56+
'npm': 'npm',
57+
'pnpm': 'pnpm',
58+
'yarn': 'yarn',
59+
'yarn@berry': 'yarn',
60+
'bun': 'bun',
61+
'pnpm@6': 'pnpm',
62+
}
63+
64+
if (agent !== '' && Object.keys(mapper).includes(agent)) {
65+
flags.manager = mapper[agent]
66+
}
67+
}
68+
}
69+
4670
const installerArgs = ['new', args.name]
4771

4872
for (const [key, value] of Object.entries(flags)) {

0 commit comments

Comments
 (0)