Skip to content

Commit

Permalink
inline the user-agent parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Jul 18, 2024
1 parent c4347cf commit 1659488
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,8 @@ async function normalizeArgs(): Promise<Args> {
};
}

function pkgManagerFromUserAgent(userAgent: string | undefined) {
if (!userAgent) return 'npm';
const pkgSpec = userAgent.split(' ')[0];
const [name, _version] = pkgSpec.split('/');
return name ?? 'npm';
}

const installDeps = async (cwd: string): Promise<string> => {
const pkgManager = pkgManagerFromUserAgent(process.env.npm_config_user_agent);
async function installDeps (cwd: string) {
const pkgManager = (process.env.npm_config_user_agent ?? 'npm').split('/').shift()
const spinner = ora(
`Installing dependencies with ${pkgManager}. This may take a few minutes.`
).start();
Expand All @@ -69,7 +62,7 @@ const installDeps = async (cwd: string): Promise<string> => {
spinner.fail(`Failed to install with ${pkgManager}.`);
throw err;
}
};
}

(async () => {
versionInfo();
Expand Down

0 comments on commit 1659488

Please sign in to comment.