From 8b2369eb423df81c9438287b0f125a9e490c87d0 Mon Sep 17 00:00:00 2001 From: seanyusa Date: Mon, 13 Dec 2021 17:08:44 -0600 Subject: [PATCH 1/3] checkIfYarnInstalled function --- create-turbo/src/yarn.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 create-turbo/src/yarn.ts diff --git a/create-turbo/src/yarn.ts b/create-turbo/src/yarn.ts new file mode 100644 index 0000000000000..b65f0505f1b3b --- /dev/null +++ b/create-turbo/src/yarn.ts @@ -0,0 +1,10 @@ +import { execSync } from "child_process"; + +export function checkIfYarnInstalled(): boolean { + try { + execSync("yarnpkg --version", { stdio: "ignore" }); + return true; + } catch (e) { + return false; + } +} From 6bb6cef6e4621db73c13817465833f53b8624fdf Mon Sep 17 00:00:00 2001 From: seanyusa Date: Mon, 13 Dec 2021 17:09:11 -0600 Subject: [PATCH 2/3] disable yarn option if not installed --- create-turbo/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/create-turbo/src/index.ts b/create-turbo/src/index.ts index 1ecf1c4f7004a..d47b2c8401f79 100644 --- a/create-turbo/src/index.ts +++ b/create-turbo/src/index.ts @@ -10,6 +10,7 @@ import gradient from "gradient-string"; import checkForUpdate from "update-check"; import chalk from "chalk"; import cliPkgJson from "../package.json"; +import { checkIfYarnInstalled } from "./yarn"; import { shouldUseYarn } from "./shouldUseYarn"; import { tryGitInit } from "./git"; @@ -79,6 +80,7 @@ async function run() { ).dir ); + const isYarnInstalled = checkIfYarnInstalled(); let answers = await inquirer.prompt<{ packageManager: "yarn" | "npm"; install: boolean; @@ -88,7 +90,11 @@ async function run() { type: "list", message: "Which package manager do you want to use?", choices: [ - { name: "Yarn", value: "yarn" }, + { + name: "Yarn", + value: "yarn", + disabled: !isYarnInstalled && "not installed", + }, { name: "NPM", value: "npm" }, // { name: "PNPM", value: "pnpm" }, ], From b03f04afe7214f0087e89ba51b97fa6a4aa7250e Mon Sep 17 00:00:00 2001 From: seanyusa Date: Tue, 14 Dec 2021 08:41:35 -0600 Subject: [PATCH 3/3] use shouldUseYarn to check if yarn is available --- create-turbo/src/index.ts | 3 +-- create-turbo/src/yarn.ts | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 create-turbo/src/yarn.ts diff --git a/create-turbo/src/index.ts b/create-turbo/src/index.ts index d47b2c8401f79..12e1bf6329d7e 100644 --- a/create-turbo/src/index.ts +++ b/create-turbo/src/index.ts @@ -10,7 +10,6 @@ import gradient from "gradient-string"; import checkForUpdate from "update-check"; import chalk from "chalk"; import cliPkgJson from "../package.json"; -import { checkIfYarnInstalled } from "./yarn"; import { shouldUseYarn } from "./shouldUseYarn"; import { tryGitInit } from "./git"; @@ -80,7 +79,7 @@ async function run() { ).dir ); - const isYarnInstalled = checkIfYarnInstalled(); + const isYarnInstalled = shouldUseYarn(); let answers = await inquirer.prompt<{ packageManager: "yarn" | "npm"; install: boolean; diff --git a/create-turbo/src/yarn.ts b/create-turbo/src/yarn.ts deleted file mode 100644 index b65f0505f1b3b..0000000000000 --- a/create-turbo/src/yarn.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { execSync } from "child_process"; - -export function checkIfYarnInstalled(): boolean { - try { - execSync("yarnpkg --version", { stdio: "ignore" }); - return true; - } catch (e) { - return false; - } -}