Skip to content

Commit

Permalink
fix(create-turbo): correct package manager selection (vercel#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
tknickman authored and NicholasLYang committed Apr 21, 2023
1 parent 1f2b703 commit fb10c29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/create-turbo/src/commands/create/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
})),
});

Expand Down
8 changes: 7 additions & 1 deletion packages/turbo-utils/src/managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ 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,
version: result.stdout.trim(),
};
} catch (e) {
return {
available: false,
available,
};
}
}
Expand Down

0 comments on commit fb10c29

Please sign in to comment.