From 0d76321ec6cbe1bfce663e806e717b1ac437639d Mon Sep 17 00:00:00 2001 From: Thomas Knickman Date: Thu, 13 Apr 2023 16:10:45 -0500 Subject: [PATCH] fix(create-turbo): correct package manager selection (#4574) --- packages/create-turbo/src/commands/create/prompts.ts | 9 ++++++--- packages/turbo-utils/src/managers.ts | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/create-turbo/src/commands/create/prompts.ts b/packages/create-turbo/src/commands/create/prompts.ts index 609b9c2d11d66..51dd98ec6cce7 100644 --- a/packages/create-turbo/src/commands/create/prompts.ts +++ b/packages/create-turbo/src/commands/create/prompts.ts @@ -100,9 +100,12 @@ export async function packageManager({ choices: ["npm", "pnpm", "yarn"].map((p) => ({ name: p, value: p, - disabled: availablePackageManagers?.[p as PackageManager]?.available - ? false - : `not installed`, + // npm should always be available + disabled: + p !== "npm" || + availablePackageManagers?.[p as PackageManager]?.available + ? false + : `not installed`, })), }); diff --git a/packages/turbo-utils/src/managers.ts b/packages/turbo-utils/src/managers.ts index e15bfa9fa110d..f1e9f6de09f30 100644 --- a/packages/turbo-utils/src/managers.ts +++ b/packages/turbo-utils/src/managers.ts @@ -15,7 +15,13 @@ async function getVersion( env: { COREPACK_ENABLE_STRICT: "0" }, }; + let available = false; try { + const userAgent = process.env.npm_config_user_agent; + if (userAgent && userAgent.startsWith(packageManager)) { + available = true; + } + const result = await execa(packageManager, ["--version"], execOptions); return { available: true, @@ -23,7 +29,7 @@ async function getVersion( }; } catch (e) { return { - available: false, + available, }; } }