Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packages/build-tools/src/utils/__tests__/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -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);
});
});
11 changes: 6 additions & 5 deletions packages/build-tools/src/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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({
Expand Down
Loading