Skip to content

Commit

Permalink
[eas-cli] add simplified projectId-focused context (#2653)
Browse files Browse the repository at this point in the history
<!-- If this PR requires a changelog entry, add it by commenting the PR with the command `/changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]`. -->
<!-- You can skip the changelog check by labeling the PR with "no changelog". -->

# Why

As suggested in the base PR we need a simple context focused on only getting the project ID, without specifying the server-side environment and resolving Expo config with it.

# How

Add such context. Make the `withServerSideEnvironment` argument required for standard project config context.

# Test Plan

Tests, test manually
  • Loading branch information
szdziedzic authored Oct 25, 2024
1 parent d0f01cb commit 8c05a71
Show file tree
Hide file tree
Showing 58 changed files with 148 additions and 98 deletions.
8 changes: 8 additions & 0 deletions packages/eas-cli/src/commandUtils/EasCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import MaybeLoggedInContextField from './context/MaybeLoggedInContextField';
import { OptionalPrivateProjectConfigContextField } from './context/OptionalPrivateProjectConfigContextField';
import { PrivateProjectConfigContextField } from './context/PrivateProjectConfigContextField';
import ProjectDirContextField from './context/ProjectDirContextField';
import { ProjectIdContextField } from './context/ProjectIdContextField';
import { ServerSideEnvironmentVariablesContextField } from './context/ServerSideEnvironmentVariablesContextField';
import SessionManagementContextField from './context/SessionManagementContextField';
import VcsClientContextField from './context/VcsClientContextField';
Expand Down Expand Up @@ -140,6 +141,12 @@ export default abstract class EasCommand extends Command {
// eslint-disable-next-line async-protect/async-suffix
getServerSideEnvironmentVariablesAsync: new ServerSideEnvironmentVariablesContextField(),
},
/**
* Require the project to be identified and registered on server. Returns the project ID evaluated from the app config.
*/
ProjectId: {
projectId: new ProjectIdContextField(),
},
};

/**
Expand Down Expand Up @@ -181,6 +188,7 @@ export default abstract class EasCommand extends Command {
// to resolve dynamic config (if dynamic config context is used) and enable getServerSideEnvironmentVariablesAsync function (if server side environment variables context is used)
withServerSideEnvironment,
}: C extends
| GetContextType<typeof EasCommand.ContextOptions.ProjectConfig>
| GetContextType<typeof EasCommand.ContextOptions.DynamicProjectConfig>
| GetContextType<typeof EasCommand.ContextOptions.OptionalProjectConfig>
| GetContextType<typeof EasCommand.ContextOptions.ServerSideEnvironmentVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { ExpoConfig } from '@expo/config';

import ContextField, { ContextOptions } from './ContextField';
import { createGraphqlClient } from './contextUtils/createGraphqlClient';
import { findProjectDirAndVerifyProjectSetupAsync } from './contextUtils/findProjectDirAndVerifyProjectSetupAsync';
import { getProjectIdAsync } from './contextUtils/getProjectIdAsync';
import { loadServerSideEnvironmentVariablesAsync } from './contextUtils/loadServerSideEnvironmentVariablesAsync';
import { getPrivateExpoConfig } from '../../project/expoConfig';

export class PrivateProjectConfigContextField extends ContextField<{
projectId: string;
exp: ExpoConfig;
projectDir: string;
}> {
async getValueAsync({ nonInteractive, sessionManager }: ContextOptions): Promise<{
async getValueAsync({
nonInteractive,
sessionManager,
withServerSideEnvironment,
}: ContextOptions): Promise<{
projectId: string;
exp: ExpoConfig;
projectDir: string;
Expand All @@ -20,7 +26,20 @@ export class PrivateProjectConfigContextField extends ContextField<{
const projectId = await getProjectIdAsync(sessionManager, expBefore, {
nonInteractive,
});
const exp = getPrivateExpoConfig(projectDir);
let serverSideEnvVars: Record<string, string> | undefined;
if (withServerSideEnvironment) {
const { authenticationInfo } = await sessionManager.ensureLoggedInAsync({
nonInteractive,
});
const graphqlClient = createGraphqlClient(authenticationInfo);
const serverSideEnvironmentVariables = await loadServerSideEnvironmentVariablesAsync({
environment: withServerSideEnvironment,
projectId,
graphqlClient,
});
serverSideEnvVars = serverSideEnvironmentVariables;
}
const exp = getPrivateExpoConfig(projectDir, { env: serverSideEnvVars });

return {
projectId,
Expand Down
15 changes: 15 additions & 0 deletions packages/eas-cli/src/commandUtils/context/ProjectIdContextField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ContextField, { ContextOptions } from './ContextField';
import { findProjectDirAndVerifyProjectSetupAsync } from './contextUtils/findProjectDirAndVerifyProjectSetupAsync';
import { getProjectIdAsync } from './contextUtils/getProjectIdAsync';
import { getPrivateExpoConfig } from '../../project/expoConfig';

export class ProjectIdContextField extends ContextField<string> {
async getValueAsync({ nonInteractive, sessionManager }: ContextOptions): Promise<string> {
const projectDir = await findProjectDirAndVerifyProjectSetupAsync();
const expBefore = getPrivateExpoConfig(projectDir);
const projectId = await getProjectIdAsync(sessionManager, expBefore, {
nonInteractive,
});
return projectId;
}
}
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/branch/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class BranchCreate extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
...this.ContextOptions.Vcs,
};
Expand All @@ -36,7 +36,7 @@ export default class BranchCreate extends EasCommand {
flags: { json: jsonFlag, 'non-interactive': nonInteractive },
} = await this.parse(BranchCreate);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
vcsClient,
} = await this.getContextAsync(BranchCreate, {
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/branch/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class BranchDelete extends EasCommand {
static override description = 'delete a branch';

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand Down Expand Up @@ -108,7 +108,7 @@ export default class BranchDelete extends EasCommand {
}

const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BranchDelete, { nonInteractive });
const projectDisplayName = await getDisplayNameForProjectIdAsync(graphqlClient, projectId);
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/branch/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export default class BranchList extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

async runAsync(): Promise<void> {
const { flags } = await this.parse(BranchList);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BranchList, {
nonInteractive: flags['non-interactive'],
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/branch/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class BranchRename extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -72,7 +72,7 @@ export default class BranchRename extends EasCommand {
flags: { json: jsonFlag, from: currentName, to: newName, 'non-interactive': nonInteractive },
} = await this.parse(BranchRename);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BranchRename, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/branch/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class BranchView extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -38,7 +38,7 @@ export default class BranchView extends EasCommand {
} = await this.parse(BranchView);
const { 'non-interactive': nonInteractive } = flags;
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BranchView, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/build/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class BuildCancel extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
...this.ContextOptions.Vcs,
};
Expand All @@ -128,7 +128,7 @@ export default class BuildCancel extends EasCommand {
}

const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BuildCancel, {
nonInteractive,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/commands/build/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class BuildConfigure extends EasCommand {
vcsClient,
} = await this.getContextAsync(BuildConfigure, {
nonInteractive: false,
withServerSideEnvironment: null,
});

Log.log(
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/build/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class BuildDelete extends EasCommand {
}),
};
static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
...this.ContextOptions.Vcs,
};
Expand All @@ -112,7 +112,7 @@ export default class BuildDelete extends EasCommand {
}

const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BuildDelete, { nonInteractive });
const displayName = await getDisplayNameForProjectIdAsync(graphqlClient, projectId);
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/build/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class BuildList extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
...this.ContextOptions.Vcs,
};
Expand All @@ -99,7 +99,7 @@ export default class BuildList extends EasCommand {
process.exit(1);
}
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BuildList, {
nonInteractive,
Expand Down
5 changes: 2 additions & 3 deletions packages/eas-cli/src/commands/build/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export default class Run extends EasCommand {

static override contextDefinition = {
...this.ContextOptions.LoggedIn,
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectDir,
...this.ContextOptions.ProjectId,
...this.ContextOptions.Vcs,
};

Expand All @@ -90,7 +89,7 @@ export default class Run extends EasCommand {
const queryOptions = getPaginatedQueryOptions(flags);
const {
loggedIn: { graphqlClient },
privateProjectConfig: { projectId },
projectId,
} = await this.getContextAsync(Run, {
nonInteractive: false,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/build/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class BuildView extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
...this.ContextOptions.Vcs,
};
Expand All @@ -29,7 +29,7 @@ export default class BuildView extends EasCommand {
flags,
} = await this.parse(BuildView);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(BuildView, {
nonInteractive: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/channel/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class ChannelCreate extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -33,7 +33,7 @@ export default class ChannelCreate extends EasCommand {
flags: { json: jsonFlag, 'non-interactive': nonInteractive },
} = await this.parse(ChannelCreate);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelCreate, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/channel/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class ChannelDelete extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -41,7 +41,7 @@ export default class ChannelDelete extends EasCommand {
flags: { json: jsonFlag, 'non-interactive': nonInteractive },
} = await this.parse(ChannelDelete);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelDelete, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/channel/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class ChannelEdit extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -84,7 +84,7 @@ export default class ChannelEdit extends EasCommand {
flags: { branch: branchFlag, json, 'non-interactive': nonInteractive },
} = await this.parse(ChannelEdit);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelEdit, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/channel/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ChannelList extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -27,7 +27,7 @@ export default class ChannelList extends EasCommand {
const paginatedQueryOptions = getPaginatedQueryOptions(flags);
const { json: jsonFlag, 'non-interactive': nonInteractive } = flags;
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelList, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/channel/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class ChannelPause extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -76,7 +76,7 @@ export default class ChannelPause extends EasCommand {
flags: { json, 'non-interactive': nonInteractive },
} = await this.parse(ChannelPause);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelPause, {
nonInteractive,
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/commands/channel/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class ChannelResume extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.ProjectConfig,
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};

Expand All @@ -76,7 +76,7 @@ export default class ChannelResume extends EasCommand {
flags: { json, 'non-interactive': nonInteractive },
} = await this.parse(ChannelResume);
const {
privateProjectConfig: { projectId },
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelResume, {
nonInteractive,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/commands/channel/rollout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default class ChannelRollout extends EasCommand {
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelRollout, {
nonInteractive: argsAndFlags.nonInteractive,
withServerSideEnvironment: null,
});
if (argsAndFlags.json) {
enableJsonOutput();
Expand Down
Loading

0 comments on commit 8c05a71

Please sign in to comment.