From 165948892b3edb77a8f3c3367c4b4cdd27470079 Mon Sep 17 00:00:00 2001 From: Daniel Cousens <413395+dcousens@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:07:11 +1000 Subject: [PATCH] inline the user-agent parsing --- packages/create/src/index.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/create/src/index.ts b/packages/create/src/index.ts index 571dcdb351b..d494cfd657d 100644 --- a/packages/create/src/index.ts +++ b/packages/create/src/index.ts @@ -49,15 +49,8 @@ async function normalizeArgs(): Promise { }; } -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 => { - 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(); @@ -69,7 +62,7 @@ const installDeps = async (cwd: string): Promise => { spinner.fail(`Failed to install with ${pkgManager}.`); throw err; } -}; +} (async () => { versionInfo();