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

[eas-cli] use expo config related functions shipped with project's expo package to resolve config #2529

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { findProjectDirAndVerifyProjectSetupAsync } from './contextUtils/findPro
import { getProjectIdAsync } from './contextUtils/getProjectIdAsync';
import {
ExpoConfigOptions,
getPrivateExpoConfig,
getPublicExpoConfig,
getPrivateExpoConfigAsync,
getPublicExpoConfigAsync,
} from '../../project/expoConfig';

export type DynamicConfigContextFn = (options?: ExpoConfigOptions) => Promise<{
Expand All @@ -22,12 +22,12 @@ export class DynamicPublicProjectConfigContextField extends ContextField<Dynamic
}: ContextOptions): Promise<DynamicConfigContextFn> {
const projectDir = await findProjectDirAndVerifyProjectSetupAsync();
return async (options?: ExpoConfigOptions) => {
const expBefore = getPublicExpoConfig(projectDir, options);
const expBefore = await getPublicExpoConfigAsync(projectDir, options);
const projectId = await getProjectIdAsync(sessionManager, expBefore, {
nonInteractive,
env: options?.env,
});
const exp = getPublicExpoConfig(projectDir, options);
const exp = await getPublicExpoConfigAsync(projectDir, options);
return {
exp,
projectDir,
Expand All @@ -44,12 +44,12 @@ export class DynamicPrivateProjectConfigContextField extends ContextField<Dynami
}: ContextOptions): Promise<DynamicConfigContextFn> {
const projectDir = await findProjectDirAndVerifyProjectSetupAsync();
return async (options?: ExpoConfigOptions) => {
const expBefore = getPrivateExpoConfig(projectDir, options);
const expBefore = await getPrivateExpoConfigAsync(projectDir, options);
const projectId = await getProjectIdAsync(sessionManager, expBefore, {
nonInteractive,
env: options?.env,
});
const exp = getPrivateExpoConfig(projectDir, options);
const exp = await getPrivateExpoConfigAsync(projectDir, options);
return {
exp,
projectDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InvalidEasJsonError } from '@expo/eas-json/build/errors';
import ContextField, { ContextOptions } from './ContextField';
import { findProjectDirAndVerifyProjectSetupAsync } from './contextUtils/findProjectDirAndVerifyProjectSetupAsync';
import { getProjectIdAsync } from './contextUtils/getProjectIdAsync';
import { getPrivateExpoConfig } from '../../project/expoConfig';
import { getPrivateExpoConfigAsync } from '../../project/expoConfig';

export class OptionalPrivateProjectConfigContextField extends ContextField<
| {
Expand Down Expand Up @@ -35,11 +35,11 @@ export class OptionalPrivateProjectConfigContextField extends ContextField<
return undefined;
}

const expBefore = getPrivateExpoConfig(projectDir);
const expBefore = await getPrivateExpoConfigAsync(projectDir);
const projectId = await getProjectIdAsync(sessionManager, expBefore, {
nonInteractive,
});
const exp = getPrivateExpoConfig(projectDir);
const exp = await getPrivateExpoConfigAsync(projectDir);
return {
exp,
projectDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExpoConfig } from '@expo/config';
import ContextField, { ContextOptions } from './ContextField';
import { findProjectDirAndVerifyProjectSetupAsync } from './contextUtils/findProjectDirAndVerifyProjectSetupAsync';
import { getProjectIdAsync } from './contextUtils/getProjectIdAsync';
import { getPrivateExpoConfig } from '../../project/expoConfig';
import { getPrivateExpoConfigAsync } from '../../project/expoConfig';

export class PrivateProjectConfigContextField extends ContextField<{
projectId: string;
Expand All @@ -16,11 +16,11 @@ export class PrivateProjectConfigContextField extends ContextField<{
projectDir: string;
}> {
const projectDir = await findProjectDirAndVerifyProjectSetupAsync();
const expBefore = getPrivateExpoConfig(projectDir);
const expBefore = await getPrivateExpoConfigAsync(projectDir);
const projectId = await getProjectIdAsync(sessionManager, expBefore, {
nonInteractive,
});
const exp = getPrivateExpoConfig(projectDir);
const exp = await getPrivateExpoConfigAsync(projectDir);

return {
projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Role } from '../../../../graphql/generated';
import { AppQuery } from '../../../../graphql/queries/AppQuery';
import { learnMore } from '../../../../log';
import { fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync } from '../../../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync';
import { isExpoInstalled } from '../../../../project/projectUtils';
import SessionManager from '../../../../user/SessionManager';
import { findProjectRootAsync } from '../findProjectDirAndVerifyProjectSetupAsync';
import { getProjectIdAsync } from '../getProjectIdAsync';
Expand All @@ -21,6 +22,7 @@ jest.mock('../../../../ora', () => ({
}),
}));
jest.mock('../../../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync');
jest.mock('../../../../project/projectUtils');

describe(getProjectIdAsync, () => {
let sessionManager: SessionManager;
Expand Down Expand Up @@ -71,6 +73,7 @@ describe(getProjectIdAsync, () => {
);

jest.mocked(findProjectRootAsync).mockResolvedValue('/app');
jest.mocked(isExpoInstalled).mockReturnValue(true);
});

it('gets the project ID from app config if exists', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { findProjectRootAsync } from './findProjectDirAndVerifyProjectSetupAsync
import { AppQuery } from '../../../graphql/queries/AppQuery';
import Log, { learnMore } from '../../../log';
import { ora } from '../../../ora';
import { createOrModifyExpoConfigAsync, getPrivateExpoConfig } from '../../../project/expoConfig';
import {
createOrModifyExpoConfigAsync,
getPrivateExpoConfigAsync,
} from '../../../project/expoConfig';
import { fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync } from '../../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync';
import { toAppPrivacy } from '../../../project/projectUtils';
import SessionManager from '../../../user/SessionManager';
Expand All @@ -25,7 +28,7 @@ export async function saveProjectIdToAppConfigAsync(
options: { env?: Env } = {}
): Promise<void> {
// NOTE(cedric): we disable plugins to avoid writing plugin-generated content to `expo.extra`
const exp = getPrivateExpoConfig(projectDir, { skipPlugins: true, ...options });
const exp = await getPrivateExpoConfigAsync(projectDir, { skipPlugins: true, ...options });
const result = await createOrModifyExpoConfigAsync(
projectDir,
{
Expand Down
3 changes: 3 additions & 0 deletions packages/eas-cli/src/commands/project/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AppMutation } from '../../../graphql/mutations/AppMutation';
import { AppQuery } from '../../../graphql/queries/AppQuery';
import { createOrModifyExpoConfigAsync } from '../../../project/expoConfig';
import { findProjectIdByAccountNameAndSlugNullableAsync } from '../../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync';
import { isExpoInstalled } from '../../../project/projectUtils';
import { confirmAsync, promptAsync } from '../../../prompts';
import ProjectInit from '../init';

Expand All @@ -34,6 +35,7 @@ jest.mock('../../../ora', () => ({
}));
jest.mock('../../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync');
jest.mock('../../../commandUtils/context/contextUtils/getProjectIdAsync');
jest.mock('../../../project/projectUtils');

let originalProcessArgv: string[];

Expand Down Expand Up @@ -91,6 +93,7 @@ function mockTestProject(options: {
featureGating: new FeatureGating({}, new FeatureGateEnvOverrides()),
graphqlClient,
});
jest.mocked(isExpoInstalled).mockReturnValue(true);
}

const commandOptions = { root: '/test-project' } as any;
Expand Down
8 changes: 4 additions & 4 deletions packages/eas-cli/src/commands/project/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AppMutation } from '../../graphql/mutations/AppMutation';
import { AppQuery } from '../../graphql/queries/AppQuery';
import Log, { link } from '../../log';
import { ora } from '../../ora';
import { createOrModifyExpoConfigAsync, getPrivateExpoConfig } from '../../project/expoConfig';
import { createOrModifyExpoConfigAsync, getPrivateExpoConfigAsync } from '../../project/expoConfig';
import { findProjectIdByAccountNameAndSlugNullableAsync } from '../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync';
import { toAppPrivacy } from '../../project/projectUtils';
import { Choice, confirmAsync, promptAsync } from '../../prompts';
Expand Down Expand Up @@ -106,7 +106,7 @@ export default class ProjectInit extends EasCommand {
projectDir: string,
{ force, nonInteractive }: InitializeMethodOptions
): Promise<void> {
const exp = getPrivateExpoConfig(projectDir);
const exp = await getPrivateExpoConfigAsync(projectDir);
const appForProjectId = await AppQuery.byIdAsync(graphqlClient, projectId);
const correctOwner = appForProjectId.ownerAccount.name;
const correctSlug = appForProjectId.slug;
Expand Down Expand Up @@ -161,7 +161,7 @@ export default class ProjectInit extends EasCommand {
projectDir: string,
{ force, nonInteractive }: InitializeMethodOptions
): Promise<void> {
const exp = getPrivateExpoConfig(projectDir);
const exp = await getPrivateExpoConfigAsync(projectDir);
const existingProjectId = exp.extra?.eas?.projectId;

if (projectId === existingProjectId) {
Expand Down Expand Up @@ -218,7 +218,7 @@ export default class ProjectInit extends EasCommand {
projectDir: string,
{ force, nonInteractive }: InitializeMethodOptions
): Promise<string> {
const exp = getPrivateExpoConfig(projectDir);
const exp = await getPrivateExpoConfigAsync(projectDir);
const existingProjectId = exp.extra?.eas?.projectId;

if (existingProjectId) {
Expand Down
6 changes: 3 additions & 3 deletions packages/eas-cli/src/commands/project/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { installDependenciesAsync } from '../../onboarding/installDependencies';
import { runCommandAsync } from '../../onboarding/runCommand';
import { RequestedPlatform } from '../../platform';
import { ExpoConfigOptions, getPrivateExpoConfig } from '../../project/expoConfig';
import { ExpoConfigOptions, getPrivateExpoConfigAsync } from '../../project/expoConfig';
import { promptAsync } from '../../prompts';
import { Actor } from '../../user/User';
import { easCliVersion } from '../../utils/easCli';
Expand Down Expand Up @@ -339,7 +339,7 @@ async function getPrivateExpoConfigWithProjectIdAsync({
actor: Actor;
options?: ExpoConfigOptions;
}): Promise<CredentialsContextProjectInfo> {
const expBefore = getPrivateExpoConfig(projectDir, options);
const expBefore = await getPrivateExpoConfigAsync(projectDir, options);
const projectId = await validateOrSetProjectIdAsync({
exp: expBefore,
graphqlClient,
Expand All @@ -349,7 +349,7 @@ async function getPrivateExpoConfigWithProjectIdAsync({
},
cwd: projectDir,
});
const exp = getPrivateExpoConfig(projectDir, options);
const exp = await getPrivateExpoConfigAsync(projectDir, options);
return {
exp,
projectId,
Expand Down
11 changes: 1 addition & 10 deletions packages/eas-cli/src/commands/update/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,7 @@ describe(UpdatePublish.name, () => {

// Add configuration to the project that should not be included in the update
const { appJson } = mockTestProject({
expoConfig: {
hooks: {
postPublish: [
{
file: 'custom-hook.js',
config: { some: 'config' },
},
],
},
},
expoConfig: {},
});

const { platforms, runtimeVersion } = mockTestExport({ platforms: ['ios'] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,7 @@ describe(UpdateRollBackToEmbedded.name, () => {

// Add configuration to the project that should not be included in the update
mockTestProject({
expoConfig: {
hooks: {
postPublish: [
{
file: 'custom-hook.js',
config: { some: 'config' },
},
],
},
},
expoConfig: {},
});

const platforms = ['ios'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export function createCtxMock(mockOverride: Record<string, any> = {}): Credentia
},
hasAppleCtx: jest.fn(() => true),
hasProjectContext: true,
exp: testAppJson,
getExpoConfigAsync: async () => testAppJson,
projectDir: '.',
getProjectIdAsync: async () => 'test-project-id',
};
return merge(defaultMock, mockOverride) as any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export async function getAppLookupParamsFromContextAsync(
ctx: CredentialsContext,
gradleContext?: GradleBuildContext
): Promise<AppLookupParams> {
ctx.ensureProjectContext();
const projectName = ctx.exp.slug;
const projectId = ctx.projectId;
const exp = await ctx.getExpoConfigAsync();
const projectName = exp.slug;
const projectId = await ctx.getProjectIdAsync();
const account = await getOwnerAccountForProjectIdAsync(ctx.graphqlClient, projectId);

const androidApplicationIdentifier = await getApplicationIdAsync(
ctx.projectDir,
ctx.exp,
exp,
ctx.vcsClient,
gradleContext
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CreateKeystore {
throw new Error(`New keystore cannot be created in non-interactive mode.`);
}

const projectId = ctx.projectId;
const projectId = await ctx.getProjectIdAsync();
const keystore = await this.provideOrGenerateAsync(ctx.graphqlClient, ctx.analytics, projectId);
const keystoreFragment = await ctx.android.createKeystoreAsync(
ctx.graphqlClient,
Expand Down
14 changes: 7 additions & 7 deletions packages/eas-cli/src/credentials/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AuthenticationMode } from './ios/appstore/authenticateTypes';
import { Analytics } from '../analytics/AnalyticsManager';
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
import Log from '../log';
import { getPrivateExpoConfig } from '../project/expoConfig';
import { getPrivateExpoConfigAsync } from '../project/expoConfig';
import { confirmAsync } from '../prompts';
import { Actor } from '../user/User';
import { Client } from '../vcs/vcs';
Expand Down Expand Up @@ -67,22 +67,22 @@ export class CredentialsContext {
return !!this.projectInfo;
}

get exp(): ExpoConfig {
this.ensureProjectContext();
public async getExpoConfigAsync(): Promise<ExpoConfig> {
await this.ensureProjectContextAsync();
return this.projectInfo!.exp;
}

get projectId(): string {
this.ensureProjectContext();
public async getProjectIdAsync(): Promise<string> {
await this.ensureProjectContextAsync();
return this.projectInfo!.projectId;
}

public ensureProjectContext(): void {
public async ensureProjectContextAsync(): Promise<void> {
if (this.hasProjectContext) {
return;
}
// trigger getConfig error
getPrivateExpoConfig(this.options.projectDir);
await getPrivateExpoConfigAsync(this.options.projectDir);
}

async bestEffortAppStoreAuthenticateAsync(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export async function assignBuildCredentialsAsync(
}

export async function getAppFromContextAsync(ctx: CredentialsContext): Promise<App> {
ctx.ensureProjectContext();
const projectName = ctx.exp.slug;
const projectId = ctx.projectId;
const exp = await ctx.getExpoConfigAsync();
const projectName = exp.slug;
const projectId = await ctx.getProjectIdAsync();
const account = await getOwnerAccountForProjectIdAsync(ctx.graphqlClient, projectId);
return {
account,
Expand Down
9 changes: 5 additions & 4 deletions packages/eas-cli/src/credentials/manager/ManageIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ManageIos {
};

const account = ctx.hasProjectContext
? await getAccountForProjectAsync(ctx.projectId)
? await getAccountForProjectAsync(await ctx.getProjectIdAsync())
: ensureActorHasPrimaryAccount(ctx.user);

let app = null;
Expand Down Expand Up @@ -195,18 +195,19 @@ export class ManageIos {
}> {
assert(ctx.hasProjectContext, 'createProjectContextAsync: must have project context.');

const app = { account, projectName: ctx.exp.slug };
const exp = await ctx.getExpoConfigAsync();
const app = { account, projectName: exp.slug };
const xcodeBuildContext = await resolveXcodeBuildContextAsync(
{
projectDir: ctx.projectDir,
nonInteractive: ctx.nonInteractive,
exp: ctx.exp,
exp,
vcsClient: ctx.vcsClient,
},
buildProfile
);
const targets = await resolveTargetsAsync({
exp: ctx.exp,
exp,
projectDir: ctx.projectDir,
xcodeBuildContext,
env: buildProfile.env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class SetUpIosBuildCredentials extends ManageIos {
};

const account = ctx.hasProjectContext
? await getAccountForProjectAsync(ctx.projectId)
? await getAccountForProjectAsync(await ctx.getProjectIdAsync())
: ensureActorHasPrimaryAccount(ctx.user);

let app = null;
Expand Down
Loading
Loading