diff --git a/packages/repo-tools/src/commands/generate-patch/generate-patch.ts b/packages/repo-tools/src/commands/generate-patch/generate-patch.ts index 6701695155..4cac90cc5b 100644 --- a/packages/repo-tools/src/commands/generate-patch/generate-patch.ts +++ b/packages/repo-tools/src/commands/generate-patch/generate-patch.ts @@ -78,6 +78,9 @@ export default async ( ); } + await verifyYarnVersion(sourceRepo.root.dir); + await verifyYarnVersion(targetRepo.root.dir); + const sourcePkg = sourceRepo.packages.find( pkg => pkg.packageJson.name === packageArg || @@ -221,6 +224,22 @@ async function loadTrimmedRootPkg(ctx: PatchContext, query?: string) { }; } +// Verify that a repo is using a supported Yarn version +async function verifyYarnVersion(cwd: string) { + const { stdout } = await exec('yarn', ['--version'], { + cwd, + }); + const version = stdout.toString('utf8').trim(); + + if (version.startsWith('1.')) { + throw new Error( + `Unsupported Yarn version in target repository, got ${stdout + .toString('utf8') + .trim()} but 2+ is required`, + ); + } +} + // Generate a new patch and return the path to the generated patch file. Will // instead return undefined if the patch is empty. async function generatePatch(