Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build-tools] Allow eas/prebuild in custom jobs #492

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
53 changes: 33 additions & 20 deletions packages/build-tools/src/steps/functions/prebuild.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import assert from 'assert';

import { Platform } from '@expo/config';
import { BuildJob } from '@expo/eas-build-job';
import { BuildFunction, BuildStepInput, BuildStepInputValueTypeName } from '@expo/steps';
import spawn from '@expo/turtle-spawn';

import { PackageManager, resolvePackageManager } from '../../utils/packageManager';

import { installNodeModules } from './installNodeModules';

type PrebuildOptions = {
clean?: boolean;
};

export function createPrebuildBuildFunction(): BuildFunction {
return new BuildFunction({
namespace: 'eas',
Expand All @@ -30,16 +23,22 @@ export function createPrebuildBuildFunction(): BuildFunction {
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
required: false,
}),
BuildStepInput.createProvider({
id: 'platform',
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
required: false,
}),
],
fn: async (stepCtx, { inputs, env }) => {
const { logger } = stepCtx;
const appleTeamId = inputs.apple_team_id.value as string | undefined;
const packageManager = resolvePackageManager(stepCtx.workingDirectory);
const defaultPlatform = process.platform === 'darwin' ? 'ios' : 'android';

assert(stepCtx.global.staticContext.job, 'Job is not defined');
const job = stepCtx.global.staticContext.job;
assert(job.platform, 'Prebuild command is not supported in generic jobs.');
const prebuildCommandArgs = getPrebuildCommandArgs(job, {
const prebuildCommandArgs = getPrebuildCommandArgs({
platform: job.platform ?? defaultPlatform,
customPrebuildCommand: job.platform ? job.experimental?.prebuildCommand : undefined,
clean: inputs.clean.value as boolean,
});
const argsWithExpo = ['expo', ...prebuildCommandArgs];
Expand Down Expand Up @@ -68,22 +67,36 @@ export function createPrebuildBuildFunction(): BuildFunction {
});
}

function getPrebuildCommandArgs(job: BuildJob, { clean }: PrebuildOptions): string[] {
if (job.experimental?.prebuildCommand) {
return sanitizeUserDefinedPrebuildCommand(job.experimental.prebuildCommand, job.platform, {
function getPrebuildCommandArgs({
platform,
customPrebuildCommand,
clean,
}: {
platform: Platform;
customPrebuildCommand?: string;
clean: boolean;
}): string[] {
if (customPrebuildCommand) {
return sanitizeUserDefinedPrebuildCommand({
customPrebuildCommand,
platform,
clean,
});
}
return ['prebuild', '--no-install', '--platform', job.platform, ...(clean ? ['--clean'] : [])];
return ['prebuild', '--no-install', '--platform', platform, ...(clean ? ['--clean'] : [])];
}

// TODO: deprecate prebuildCommand in eas.json
function sanitizeUserDefinedPrebuildCommand(
userDefinedPrebuildCommand: string,
platform: Platform,
{ clean }: PrebuildOptions
): string[] {
let prebuildCommand = userDefinedPrebuildCommand;
function sanitizeUserDefinedPrebuildCommand({
customPrebuildCommand,
platform,
clean,
}: {
customPrebuildCommand: string;
platform: Platform;
clean: boolean;
}): string[] {
let prebuildCommand = customPrebuildCommand;
if (!prebuildCommand.match(/(?:--platform| -p)/)) {
prebuildCommand = `${prebuildCommand} --platform ${platform}`;
}
Expand Down
Loading