From 6f393b32680e3d1350000f3c3399cd108a185f05 Mon Sep 17 00:00:00 2001 From: Anton Timmermans Date: Fri, 3 May 2024 10:24:20 +0200 Subject: [PATCH 1/3] fix: upgrade the turbo package in Yarn 4 --- .../migrate/steps/getTurboUpgradeCommand.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts b/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts index 3fe6666a4d252..00395e78bd910 100644 --- a/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts +++ b/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts @@ -50,6 +50,19 @@ function getLocalUpgradeCommand({ case "yarn": // yarn 2.x and 3.x (berry) if (gte(packageManagerVersion, "2.0.0")) { + if (isUsingWorkspaces) { + return renderCommand([ + "yarn", + "workspaces", + "foreach", + "--all", + "--include .", + "add", + `turbo@${to}`, + installType === "devDependencies" && "--dev", + ]); + } + return renderCommand([ "yarn", "add", From 5056f88e88aa3f0c9270f8effb09cdb563d56685 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Sun, 1 Dec 2024 22:22:51 -0700 Subject: [PATCH 2/3] WIP --- .../migrate/steps/getTurboUpgradeCommand.ts | 13 ------------- packages/turbo-utils/src/managers.ts | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts b/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts index 00395e78bd910..3fe6666a4d252 100644 --- a/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts +++ b/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts @@ -50,19 +50,6 @@ function getLocalUpgradeCommand({ case "yarn": // yarn 2.x and 3.x (berry) if (gte(packageManagerVersion, "2.0.0")) { - if (isUsingWorkspaces) { - return renderCommand([ - "yarn", - "workspaces", - "foreach", - "--all", - "--include .", - "add", - `turbo@${to}`, - installType === "devDependencies" && "--dev", - ]); - } - return renderCommand([ "yarn", "add", diff --git a/packages/turbo-utils/src/managers.ts b/packages/turbo-utils/src/managers.ts index 5591ae0f75d93..c003171fbc84d 100644 --- a/packages/turbo-utils/src/managers.ts +++ b/packages/turbo-utils/src/managers.ts @@ -24,7 +24,9 @@ export async function getAvailablePackageManagers(): Promise< Record > { const [yarn, npm, pnpm, bun] = await Promise.all([ - exec("yarnpkg", ["--version"]), + // Yarn berry doesn't have a global bin so this checks from the repo root + // If the repo uses berry, it will return it's specified version + exec("yarnpkg", ["--version"], { cwd: "." }), exec("npm", ["--version"]), exec("pnpm", ["--version"]), exec("bun", ["--version"]), @@ -42,7 +44,15 @@ export async function getPackageManagersBinPaths(): Promise< Record > { const [yarn, npm, pnpm, bun] = await Promise.all([ - exec("yarnpkg", ["global", "bin"]), + // yarn berry doesn't have a global bin so we check from within the repo + exec("yarnpkg", ["--version"], { cwd: "." }).then((version) => { + if (version && !version.startsWith("1.")) { + return `.yarn/releases/yarn-${version}.cjs`; + // yarn 1 + } else if (version) { + return exec("yarn", ["global", "bin"]); + } + }), exec("npm", ["config", "get", "prefix"]), exec("pnpm", ["bin", "--global"]), exec("bun", ["pm", "--g", "bin"]), From a80f437b42dc47abfc93515d73656b9bd210d7a4 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Sun, 1 Dec 2024 22:26:14 -0700 Subject: [PATCH 3/3] WIP --- .../src/commands/migrate/steps/getTurboUpgradeCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts b/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts index 3fe6666a4d252..e689a76ba46aa 100644 --- a/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts +++ b/packages/turbo-codemod/src/commands/migrate/steps/getTurboUpgradeCommand.ts @@ -56,8 +56,8 @@ function getLocalUpgradeCommand({ `turbo@${to}`, installType === "devDependencies" && "--dev", ]); - // yarn 1.x } + // yarn 1.x return renderCommand([ "yarn", "add",