Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
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
100 changes: 100 additions & 0 deletions packages/build-tools/src/common/__tests__/setup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { randomUUID } from 'crypto';
import path from 'path';

import { vol } from 'memfs';
import fs from 'fs-extra';
import {
Platform,
BuildMode,
BuildTrigger,
Workflow,
ArchiveSourceType,
BuildJob,
} from '@expo/eas-build-job';

import { BuildContext } from '../..';
import { prepareProjectAsync } from '../setup';
import { createMockLogger } from '../../__tests__/utils/logger';

jest.mock('../projectSources');

describe('setup', () => {
beforeEach(() => {
vol.reset();
});

it('should delete .expo directory if it exists', async () => {
// Arrange
const projectRoot = '/app';
await vol.promises.mkdir(path.join(projectRoot, '.expo'), { recursive: true });
await vol.promises.writeFile(path.join(projectRoot, '.expo', 'test.txt'), 'test');

const ctx = new BuildContext(
{
triggeredBy: BuildTrigger.EAS_CLI,
type: Workflow.MANAGED,
mode: BuildMode.BUILD,
initiatingUserId: randomUUID(),
appId: randomUUID(),
projectArchive: {
type: ArchiveSourceType.PATH,
path: projectRoot,
},
platform: Platform.IOS,
secrets: {
robotAccessToken: randomUUID(),
environmentSecrets: [],
},
} as BuildJob,
{
env: {},
workingdir: '/workingdir',
logger: createMockLogger(),
logBuffer: { getLogs: () => [], getPhaseLogs: () => [] },
uploadArtifact: jest.fn(),
}
);
jest.spyOn(ctx, 'getReactNativeProjectDirectory').mockReturnValue(projectRoot);

// Act
await prepareProjectAsync(ctx);

// Assert
expect(await fs.pathExists(path.join(projectRoot, '.expo'))).toBe(false);
});

it('should not fail if .expo directory does not exist', async () => {
const projectRoot = '/app';

const ctx = new BuildContext(
{
triggeredBy: BuildTrigger.EAS_CLI,
type: Workflow.MANAGED,
mode: BuildMode.BUILD,
initiatingUserId: randomUUID(),
appId: randomUUID(),
projectArchive: {
type: ArchiveSourceType.PATH,
path: projectRoot,
},
platform: Platform.IOS,
secrets: {
robotAccessToken: randomUUID(),
environmentSecrets: [],
},
} as BuildJob,
{
env: {},
workingdir: '/workingdir',
logger: createMockLogger(),
logBuffer: { getLogs: () => [], getPhaseLogs: () => [] },
uploadArtifact: jest.fn(),
}
);
jest.spyOn(ctx, 'getReactNativeProjectDirectory').mockReturnValue(projectRoot);

await prepareProjectAsync(ctx);

expect(await fs.pathExists(path.join(projectRoot, '.expo'))).toBe(false);
});
});
44 changes: 31 additions & 13 deletions packages/build-tools/src/common/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,7 @@ class InstallDependenciesTimeoutError extends Error {}

export async function setupAsync<TJob extends BuildJob>(ctx: BuildContext<TJob>): Promise<void> {
await ctx.runBuildPhase(BuildPhase.PREPARE_PROJECT, async () => {
await prepareProjectSourcesAsync(ctx);
await setUpNpmrcAsync(ctx, ctx.logger);
if (ctx.job.platform === Platform.IOS && ctx.env.EAS_BUILD_RUNNER === 'eas-build') {
await deleteXcodeEnvLocalIfExistsAsync(ctx as BuildContext<Ios.Job>);
}
if (ctx.job.triggeredBy === BuildTrigger.GIT_BASED_INTEGRATION) {
// We need to setup envs from eas.json before
// eas-build-pre-install hook is called.
const env = await resolveEnvFromBuildProfileAsync(ctx, {
cwd: ctx.getReactNativeProjectDirectory(),
});
ctx.updateEnv(env);
}
await prepareProjectAsync(ctx);
});

await ctx.runBuildPhase(BuildPhase.PRE_INSTALL_HOOK, async () => {
Expand Down Expand Up @@ -130,6 +118,36 @@ export async function setupAsync<TJob extends BuildJob>(ctx: BuildContext<TJob>)
}
}

export async function prepareProjectAsync<TJob extends BuildJob>(
ctx: BuildContext<TJob>
): Promise<void> {
await prepareProjectSourcesAsync(ctx);
await setUpNpmrcAsync(ctx, ctx.logger);
if (ctx.job.platform === Platform.IOS && ctx.env.EAS_BUILD_RUNNER === 'eas-build') {
await deleteXcodeEnvLocalIfExistsAsync(ctx as BuildContext<Ios.Job>);
}

// Delete .expo directory if it exists.
const expoDir = path.join(ctx.getReactNativeProjectDirectory(), '.expo');
try {
if (await fs.pathExists(expoDir)) {
await fs.remove(expoDir);
ctx.logger.info('Deleted .expo directory.');
}
} catch (err) {
ctx.logger.warn({ err }, 'Failed to delete .expo directory.');
}

if (ctx.job.triggeredBy === BuildTrigger.GIT_BASED_INTEGRATION) {
// We need to setup envs from eas.json before
// eas-build-pre-install hook is called.
const env = await resolveEnvFromBuildProfileAsync(ctx, {
cwd: ctx.getReactNativeProjectDirectory(),
});
ctx.updateEnv(env);
}
}

async function runExpoDoctor<TJob extends Job>(ctx: BuildContext<TJob>): Promise<SpawnResult> {
ctx.logger.info('Running "expo doctor"');
let timeout: NodeJS.Timeout | undefined;
Expand Down