diff --git a/packages/build-tools/src/utils/__tests__/project.test.ts b/packages/build-tools/src/utils/__tests__/project.test.ts index c57ab1c6d6..18c6595b93 100644 --- a/packages/build-tools/src/utils/__tests__/project.test.ts +++ b/packages/build-tools/src/utils/__tests__/project.test.ts @@ -7,7 +7,7 @@ import { instance, mock, when } from 'ts-mockito'; import { BuildContext } from '../../context'; import { PackageManager } from '../packageManager'; -import { readEasJsonContents, runExpoCliCommand } from '../project'; +import { isUsingModernYarnVersion, readEasJsonContents, runExpoCliCommand } from '../project'; jest.mock('fs'); jest.mock('@expo/turtle-spawn', () => ({ @@ -87,3 +87,27 @@ describe(readEasJsonContents, () => { expect(readEasJsonContents(projectDir)).toBe(contents); }); }); + +describe(isUsingModernYarnVersion, () => { + const mockSpawn = spawn as jest.Mock; + + beforeEach(() => { + mockSpawn.mockReset(); + }); + + it('returns false for yarn 1.x', async () => { + mockSpawn.mockResolvedValue({ stdout: '1.22.22' }); + + const result = await isUsingModernYarnVersion('/project'); + + expect(result).toBe(false); + }); + + it('returns true for yarn 4.x', async () => { + mockSpawn.mockResolvedValue({ stdout: '4.13.0' }); + + const result = await isUsingModernYarnVersion('/project'); + + expect(result).toBe(true); + }); +}); diff --git a/packages/build-tools/src/utils/project.ts b/packages/build-tools/src/utils/project.ts index 3580833e48..265f6dc245 100644 --- a/packages/build-tools/src/utils/project.ts +++ b/packages/build-tools/src/utils/project.ts @@ -2,15 +2,16 @@ import spawn, { SpawnOptions, SpawnPromise, SpawnResult } from '@expo/turtle-spa import fs from 'fs-extra'; import path from 'path'; -import { PackageManager, findPackagerRootDir } from '../utils/packageManager'; +import { PackageManager } from '../utils/packageManager'; /** - * check if .yarnrc.yml exists in the project dir or in the workspace root dir + * Check if yarn version is 2 or later (modern yarn) by running `yarn --version` */ export async function isUsingModernYarnVersion(projectDir: string): Promise { - const yarnrcPath = path.join(projectDir, '.yarnrc.yml'); - const yarnrcRootPath = path.join(findPackagerRootDir(projectDir), '.yarnrc.yml'); - return (await fs.pathExists(yarnrcPath)) || (await fs.pathExists(yarnrcRootPath)); + const result = await spawn('yarn', ['--version'], { cwd: projectDir, stdio: 'pipe' }); + const version = result.stdout.trim(); + const majorVersion = parseInt(version.split('.')[0], 10); + return majorVersion >= 2; } export function runExpoCliCommand({