Skip to content

Commit e5350c0

Browse files
committed
Fix default package manager detection
1 parent 8d544ac commit e5350c0

File tree

1 file changed

+8
-7
lines changed
  • packages/create-react-admin/src

1 file changed

+8
-7
lines changed

packages/create-react-admin/src/cli.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ const getAuthProvider = (flags: typeof cli.flags) => {
5353
return 'none';
5454
};
5555

56-
const getDefaultInstaller = (processExec: string) => {
57-
if (processExec.includes('yarn')) return 'yarn';
58-
if (processExec.includes('bun')) return 'bun';
59-
return 'npm';
56+
const getDefaultInstaller = (userAgent: string) => {
57+
if (!userAgent) return undefined;
58+
const pkgSpec = userAgent.split(' ')[0];
59+
const pkgSpecArr = pkgSpec.split('/');
60+
return pkgSpecArr[0];
6061
};
6162

62-
const getInstall = (flags: typeof cli.flags, processExec: string) => {
63+
const getInstall = (flags: typeof cli.flags, userAgent: string) => {
6364
if (flags.install) return flags.install;
6465
if (flags.interactive) return undefined;
65-
return getDefaultInstaller(processExec);
66+
return getDefaultInstaller(userAgent);
6667
};
6768

6869
const getResources = (flags: typeof cli.flags) => {
@@ -133,7 +134,7 @@ if (cli.flags.h) {
133134
}
134135
const dataProvider = getDataProvider(cli.flags);
135136
const authProvider = getAuthProvider(cli.flags);
136-
const install = getInstall(cli.flags, process.execPath);
137+
const install = getInstall(cli.flags, process.env.npm_config_user_agent);
137138
const resources = getResources(cli.flags);
138139

139140
render(

0 commit comments

Comments
 (0)