Skip to content

Commit

Permalink
fix(create-turbo): correct package manager selection (#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
tknickman committed Apr 13, 2023
1 parent 4626147 commit 0d76321
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

1 comment on commit 0d76321

@vercel
Copy link

@vercel vercel bot commented on 0d76321 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.