Compare commits

..
24 changed files with 116 additions and 489 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
'eas-cli': patch
---
Keep simulator credentials when the stop response does not confirm that the allocated session stopped.
@@ -1,5 +0,0 @@
---
'eas-cli': minor
---
Add `eas project:icon:unset`, and make `eas project:icon:set` use the icon from the app config when no path is given.
-5
View File
@@ -1,5 +0,0 @@
---
'eas-cli': minor
---
Show the display name, slug and icon in `eas project:info`, and describe how `eas project:icon:set` processes the image.
-5
View File
@@ -1,5 +0,0 @@
---
'eas-cli': minor
---
Add `eas project:name:set` to set the project display name shown on the EAS dashboard.
-5
View File
@@ -1,5 +0,0 @@
---
'eas-cli': patch
---
Fix the log URL of `eas workflow:view` for a project that has a display name.
-6
View File
@@ -227,12 +227,6 @@
"project": {
"description": "manage project"
},
"project:icon": {
"description": "manage the project icon displayed on the EAS dashboard"
},
"project:name": {
"description": "manage the project display name shown on the EAS dashboard"
},
"release": {
"description": "manage update releases"
},
@@ -1,53 +0,0 @@
import { getMockOclifConfig } from '../../../__tests__/commands/utils';
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppQuery } from '../../../graphql/queries/AppQuery';
import Log from '../../../log';
import ProjectInfo from '../info';
jest.mock('../../../graphql/queries/AppQuery');
jest.mock('../../../log');
const projectId = 'test-project-id';
async function runAndGetOutputAsync(): Promise<string> {
const command = new ProjectInfo([], getMockOclifConfig());
// @ts-expect-error getContextAsync is protected
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
projectId,
loggedIn: { graphqlClient: {} as ExpoGraphqlClient },
});
await command.runAsync();
return jest.mocked(Log.log).mock.calls.flat().join('\n');
}
describe(ProjectInfo, () => {
beforeEach(() => {
jest.clearAllMocks();
jest.mocked(AppQuery.byIdAsync).mockResolvedValue({
id: projectId,
name: 'My App',
fullName: '@jester/my-app',
slug: 'my-app',
} as any);
});
it('prints the display name, slug and icon URL', async () => {
jest
.mocked(AppQuery.byIdProfileImageUrlAsync)
.mockResolvedValue('https://example.com/icon.png');
const output = await runAndGetOutputAsync();
expect(output).toMatch(/fullName.* @jester\/my-app/);
expect(output).toMatch(/name.* My App/);
expect(output).toMatch(/slug.* my-app/);
expect(output).toMatch(/icon.* https:\/\/example\.com\/icon\.png/);
expect(output).toMatch(/ID.* test-project-id/);
});
it('prints "not set" when the project has no icon', async () => {
jest.mocked(AppQuery.byIdProfileImageUrlAsync).mockResolvedValue(null);
expect(await runAndGetOutputAsync()).toMatch(/icon.* not set/);
});
});
@@ -4,7 +4,6 @@ import { vol } from 'memfs';
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppUploadSessionType } from '../../../../graphql/generated';
import { AppQuery } from '../../../../graphql/queries/AppQuery';
import { getPrivateExpoConfigAsync } from '../../../../project/expoConfig';
import { uploadAppScopedFileAtPathToGCSAsync } from '../../../../uploads';
import { sleepAsync } from '../../../../utils/promise';
import ProjectIconSet from '../set';
@@ -12,7 +11,6 @@ import ProjectIconSet from '../set';
jest.mock('fs');
jest.mock('../../../../graphql/queries/AppQuery');
jest.mock('../../../../log');
jest.mock('../../../../project/expoConfig');
jest.mock('../../../../ora', () => ({
ora: jest.fn(() => {
const spinner = {
@@ -76,7 +74,6 @@ describe(ProjectIconSet, () => {
// @ts-expect-error getContextAsync is protected
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
projectId,
projectDir: '/app',
loggedIn: { graphqlClient },
});
return command;
@@ -112,51 +109,12 @@ describe(ProjectIconSet, () => {
expect(mockUploadAsync).toHaveBeenCalledTimes(1);
});
it('uploads the icon from the app config when no path is given', async () => {
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
jest.mocked(getPrivateExpoConfigAsync).mockResolvedValue({
name: 'test',
slug: 'test-project',
icon: './assets/icon.png',
} as any);
mockByIdProfileImageUrlAsync
.mockResolvedValueOnce('https://example.com/old.png')
.mockResolvedValueOnce('https://example.com/new.png');
await createCommand([]).runAsync();
expect(mockUploadAsync).toHaveBeenCalledWith(graphqlClient, {
type: AppUploadSessionType.ProfileImageUpload,
appId: projectId,
path: '/app/assets/icon.png',
});
});
it('throws when no path is given and the app config has no icon', async () => {
jest
.mocked(getPrivateExpoConfigAsync)
.mockResolvedValue({ name: 'test', slug: 'test-project' } as any);
await expect(createCommand([]).runAsync()).rejects.toThrow(
'No local icon found in the app config'
);
expect(mockUploadAsync).not.toHaveBeenCalled();
});
it('throws when the file does not exist', async () => {
const command = createCommand(['/app/missing.png']);
await expect(command.runAsync()).rejects.toThrow('No file found at /app/missing.png');
expect(mockUploadAsync).not.toHaveBeenCalled();
});
it('throws for a directory', async () => {
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
const command = createCommand(['/app/assets']);
await expect(command.runAsync()).rejects.toThrow('/app/assets is not a file.');
expect(mockUploadAsync).not.toHaveBeenCalled();
});
it('throws for an unsupported image format', async () => {
vol.fromJSON({ '/app/icon.gif': 'fake-gif-bytes' });
@@ -1,30 +0,0 @@
import { getMockOclifConfig } from '../../../../__tests__/commands/utils';
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppMutation } from '../../../../graphql/mutations/AppMutation';
import Log from '../../../../log';
import ProjectIconUnset from '../unset';
jest.mock('../../../../graphql/mutations/AppMutation');
jest.mock('../../../../log');
describe(ProjectIconUnset, () => {
it('removes the icon of the current project', async () => {
const graphqlClient = {} as ExpoGraphqlClient;
jest
.mocked(AppMutation.removeProfileImageAsync)
.mockResolvedValue({ id: 'project-123', fullName: '@test-account/test-project' });
const command = new ProjectIconUnset([], getMockOclifConfig());
// @ts-expect-error getContextAsync is protected
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
projectId: 'project-123',
loggedIn: { graphqlClient },
});
await command.runAsync();
expect(AppMutation.removeProfileImageAsync).toHaveBeenCalledWith(graphqlClient, 'project-123');
expect(jest.mocked(Log.withTick).mock.calls.flat().join()).toContain(
'@test-account/test-project'
);
});
});
@@ -9,20 +9,18 @@ import Log, { link } from '../../../log';
import { ora } from '../../../ora';
import {
pollForProfileImageChangeAsync,
resolveAppConfigIconAsync,
uploadProjectIconAsync,
validateIconAsync,
} from '../../../project/projectIcon';
export default class ProjectIconSet extends EasCommand {
static override description =
'set the project icon displayed on the EAS dashboard (requires the Admin role)';
static override description = 'set the project icon displayed on the EAS dashboard';
static override args = {
path: Args.string({
required: true,
description:
'Path to the icon image (PNG or JPEG, at most 10 MB). The image is resized to a 1024x1024 PNG, and a non-square image is center-cropped. Defaults to the icon in the app config.',
ignoreStdin: true,
'Path to the icon image (PNG or JPEG, at most 10 MB). Non-square images are center-cropped to a square.',
}),
};
@@ -32,24 +30,21 @@ export default class ProjectIconSet extends EasCommand {
static override contextDefinition = {
...this.ContextOptions.ProjectId,
...this.ContextOptions.ProjectDir,
...this.ContextOptions.LoggedIn,
};
async runAsync(): Promise<void> {
const {
args: { path: pathArgument },
args: { path: imagePath },
flags,
} = await this.parse(ProjectIconSet);
const {
projectId,
projectDir,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ProjectIconSet, {
nonInteractive: flags['non-interactive'],
});
const imagePath = pathArgument ?? (await getAppConfigIconPathAsync(projectDir));
await validateIconAsync(imagePath);
const app = await AppQuery.byIdAsync(graphqlClient, projectId);
@@ -79,14 +74,3 @@ export default class ProjectIconSet extends EasCommand {
}
}
}
async function getAppConfigIconPathAsync(projectDir: string): Promise<string> {
const icon = await resolveAppConfigIconAsync(projectDir);
if (!icon) {
throw new Error(
'No local icon found in the app config (icon, ios.icon, android.adaptiveIcon.foregroundImage or android.icon). Pass the path to an image instead.'
);
}
Log.log(`Using "${icon.field}" from your app config: ${icon.path}`);
return icon.path;
}
@@ -1,33 +0,0 @@
import chalk from 'chalk';
import EasCommand from '../../../commandUtils/EasCommand';
import { EASNonInteractiveFlag } from '../../../commandUtils/flags';
import { AppMutation } from '../../../graphql/mutations/AppMutation';
import Log from '../../../log';
export default class ProjectIconUnset extends EasCommand {
static override description =
'remove the project icon displayed on the EAS dashboard (requires the Admin role)';
static override flags = {
...EASNonInteractiveFlag,
};
static override contextDefinition = {
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};
async runAsync(): Promise<void> {
const { flags } = await this.parse(ProjectIconUnset);
const {
projectId,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ProjectIconUnset, {
nonInteractive: flags['non-interactive'],
});
const { fullName } = await AppMutation.removeProfileImageAsync(graphqlClient, projectId);
Log.withTick(`${chalk.bold(fullName)} now has no icon`);
}
}
+36 -9
View File
@@ -1,8 +1,38 @@
import gql from 'graphql-tag';
import EasCommand from '../../commandUtils/EasCommand';
import { AppQuery } from '../../graphql/queries/AppQuery';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { withErrorHandlingAsync } from '../../graphql/client';
import { AppInfoQuery, AppInfoQueryVariables } from '../../graphql/generated';
import Log from '../../log';
import formatFields from '../../utils/formatFields';
async function projectInfoByIdAsync(
graphqlClient: ExpoGraphqlClient,
appId: string
): Promise<AppInfoQuery> {
const data = await withErrorHandlingAsync(
graphqlClient
.query<AppInfoQuery, AppInfoQueryVariables>(
gql`
query AppInfo($appId: String!) {
app {
byId(appId: $appId) {
id
fullName
}
}
}
`,
{ appId },
{ additionalTypenames: ['App'] }
)
.toPromise()
);
return data;
}
export default class ProjectInfo extends EasCommand {
static override description = 'information about the current project';
@@ -19,18 +49,15 @@ export default class ProjectInfo extends EasCommand {
nonInteractive: true,
});
const [app, iconUrl] = await Promise.all([
AppQuery.byIdAsync(graphqlClient, projectId),
AppQuery.byIdProfileImageUrlAsync(graphqlClient, projectId),
]);
const { app } = await projectInfoByIdAsync(graphqlClient, projectId);
if (!app) {
throw new Error(`Could not find project with id: ${projectId}`);
}
Log.addNewLineIfNone();
Log.log(
formatFields([
{ label: 'fullName', value: app.fullName },
{ label: 'name', value: app.name },
{ label: 'slug', value: app.slug },
{ label: 'icon', value: iconUrl ?? 'not set' },
{ label: 'fullName', value: app.byId.fullName },
{ label: 'ID', value: projectId },
])
);
@@ -1,60 +0,0 @@
import { getMockOclifConfig } from '../../../../__tests__/commands/utils';
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppMutation } from '../../../../graphql/mutations/AppMutation';
import { getPrivateExpoConfigAsync } from '../../../../project/expoConfig';
import ProjectNameSet from '../set';
jest.mock('../../../../graphql/mutations/AppMutation');
jest.mock('../../../../log');
jest.mock('../../../../project/expoConfig');
const graphqlClient = {} as ExpoGraphqlClient;
const mockSetDisplayNameAsync = jest.mocked(AppMutation.setDisplayNameAsync);
async function runAsync(argv: string[]): Promise<void> {
const command = new ProjectNameSet(argv, getMockOclifConfig());
// @ts-expect-error getContextAsync is protected
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
projectId: 'project-123',
projectDir: '/app',
loggedIn: { graphqlClient },
});
await command.runAsync();
}
describe(ProjectNameSet, () => {
beforeEach(() => {
jest.clearAllMocks();
mockSetDisplayNameAsync.mockResolvedValue({
id: 'project-123',
name: 'My App',
fullName: '@test-account/my-app',
});
jest
.mocked(getPrivateExpoConfigAsync)
.mockResolvedValue({ name: 'Config Name', slug: 'my-app' } as any);
});
it('sets the given display name, trimmed', async () => {
await runAsync([' My App ']);
expect(mockSetDisplayNameAsync).toHaveBeenCalledWith(graphqlClient, {
appId: 'project-123',
displayName: 'My App',
});
});
it('uses the name from the app config when no name is given', async () => {
await runAsync([]);
expect(mockSetDisplayNameAsync).toHaveBeenCalledWith(graphqlClient, {
appId: 'project-123',
displayName: 'Config Name',
});
});
it('rejects a blank name', async () => {
await expect(runAsync([' '])).rejects.toThrow('The display name cannot be blank.');
expect(mockSetDisplayNameAsync).not.toHaveBeenCalled();
});
});
@@ -1,55 +0,0 @@
import { Args } from '@oclif/core';
import chalk from 'chalk';
import EasCommand from '../../../commandUtils/EasCommand';
import { EASNonInteractiveFlag } from '../../../commandUtils/flags';
import { AppMutation } from '../../../graphql/mutations/AppMutation';
import Log from '../../../log';
import { getPrivateExpoConfigAsync } from '../../../project/expoConfig';
export default class ProjectNameSet extends EasCommand {
static override description =
'set the project display name shown on the EAS dashboard (does not change the slug)';
static override args = {
name: Args.string({
description: 'Display name, at most 255 characters. Defaults to the name in the app config.',
ignoreStdin: true,
}),
};
static override flags = {
...EASNonInteractiveFlag,
};
static override contextDefinition = {
...this.ContextOptions.ProjectId,
...this.ContextOptions.ProjectDir,
...this.ContextOptions.LoggedIn,
};
async runAsync(): Promise<void> {
const {
args: { name: nameArgument },
flags,
} = await this.parse(ProjectNameSet);
const {
projectId,
projectDir,
loggedIn: { graphqlClient },
} = await this.getContextAsync(ProjectNameSet, {
nonInteractive: flags['non-interactive'],
});
const displayName = (nameArgument ?? (await getPrivateExpoConfigAsync(projectDir)).name).trim();
if (!displayName) {
throw new Error('The display name cannot be blank.');
}
const app = await AppMutation.setDisplayNameAsync(graphqlClient, {
appId: projectId,
displayName,
});
Log.withTick(`Set the display name of ${chalk.bold(app.fullName)} to ${chalk.bold(app.name)}`);
}
}
@@ -3495,6 +3495,31 @@ describe(Simulator, () => {
);
});
it.each([
{ id: 'session-123', status: DeviceRunSessionStatus.InProgress },
{ id: 'another-session', status: DeviceRunSessionStatus.Stopped },
])(
'keeps local credentials when the stop response does not confirm this session: %j',
async response => {
mockByIdAsync
.mockResolvedValueOnce(makeDeviceRunSession())
.mockImplementationOnce(async () => {
process.emit('SIGINT');
return makeDeviceRunSession();
});
mockEnsureDeviceRunSessionStoppedAsync.mockResolvedValueOnce(response);
const { command } = createCommand(['--platform', 'ios']);
await command.runAsync();
expect(mockEnsureDeviceRunSessionStoppedAsync).toHaveBeenCalledWith(
graphqlClient,
'session-123'
);
expect(mockResetSimulatorEnvAsync).not.toHaveBeenCalled();
}
);
it('stops the session when interrupted while it is running', async () => {
mockByIdAsync.mockResolvedValueOnce(makeDeviceRunSession()).mockImplementationOnce(async () => {
process.emit('SIGINT');
@@ -135,6 +135,20 @@ describe(SimulatorStop, () => {
}
});
it.each([{ status: DeviceRunSessionStatus.InProgress }, { id: 'another-session' }])(
'preserves credentials when the stop is unconfirmed: %j',
async response => {
mockEnsureDeviceRunSessionStoppedAsync.mockResolvedValueOnce(
makeStoppedDeviceRunSession(response)
);
const { command } = createCommand(['--id', 'session-123', '--json']);
await expect(command.runAsync()).rejects.toThrow('could not confirm');
expect(mockResetSimulatorEnvAsync).not.toHaveBeenCalled();
expect(mockPrintJsonOnlyOutput).not.toHaveBeenCalled();
}
);
it('throws a helpful error when no simulator session ID is available', async () => {
const previousDeviceRunSessionId = process.env[EAS_SIMULATOR_SESSION_ID];
delete process.env[EAS_SIMULATOR_SESSION_ID];
@@ -77,6 +77,7 @@ import {
getLocalEgressConfig,
getPreviewApiAccess,
getRemoteSessionEnvironmentVariables,
isSimulatorStopConfirmed,
sanitizeRemoteConfigForJson,
} from '../../simulator/utils';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
@@ -1119,11 +1120,11 @@ async function ensureDeviceRunSessionStoppedSafelyAsync(
deviceRunSessionId: string
): Promise<boolean> {
try {
await DeviceRunSessionMutation.ensureDeviceRunSessionStoppedAsync(
const stopped = await DeviceRunSessionMutation.ensureDeviceRunSessionStoppedAsync(
graphqlClient,
deviceRunSessionId
);
return true;
return isSimulatorStopConfirmed(stopped, deviceRunSessionId);
} catch (err) {
// Cleanup is best-effort; surface the failure but don't mask the original error.
Log.warn(
@@ -13,6 +13,7 @@ import {
loadSimulatorEnvAsync,
resetSimulatorEnvAsync,
} from '../../simulator/env';
import { isSimulatorStopConfirmed } from '../../simulator/utils';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
import {
getSimulatorCommandAliases,
@@ -67,6 +68,9 @@ export default class SimulatorStop extends EasCommand {
graphqlClient,
flagId
);
if (!isSimulatorStopConfirmed(session, flagId)) {
throw new Error(`EAS could not confirm that simulator session ${flagId} stopped.`);
}
stopSpinner.succeed(`🎉 Simulator session ${session.id} is ${session.status.toLowerCase()}`);
} catch (err) {
stopSpinner.fail(`Failed to stop simulator session ${flagId}`);
@@ -133,7 +133,7 @@ export default class WorkflowView extends EasCommand {
result.logURL = getWorkflowRunUrl(
result.workflow.app.ownerAccount.name,
result.workflow.app.slug,
result.workflow.app.name,
result.id
);
+7 -15
View File
@@ -14976,6 +14976,13 @@ export type ResumeUpdateChannelMutationVariables = Exact<{
export type ResumeUpdateChannelMutation = { __typename?: 'RootMutation', updateChannel: { __typename?: 'UpdateChannelMutation', resumeUpdateChannel: { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string, isProtected: boolean } } };
export type AppInfoQueryVariables = Exact<{
appId: Scalars['String']['input'];
}>;
export type AppInfoQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, fullName: string } } };
export type CreateAndroidAppBuildCredentialsMutationVariables = Exact<{
androidAppBuildCredentialsInput: AndroidAppBuildCredentialsInput;
androidAppCredentialsId: Scalars['ID']['input'];
@@ -15517,21 +15524,6 @@ export type ScheduleAppDeletionMutationVariables = Exact<{
export type ScheduleAppDeletionMutation = { __typename?: 'RootMutation', app?: { __typename?: 'AppMutation', scheduleAppDeletion: { __typename?: 'BackgroundJobReceipt', id: string, state: BackgroundJobState, tries: number, willRetry: boolean, resultId?: string | null, resultType: BackgroundJobResultType, resultData?: any | null, errorCode?: string | null, errorMessage?: string | null, createdAt: any, updatedAt: any } } | null };
export type RemoveProfileImageMutationVariables = Exact<{
appId: Scalars['ID']['input'];
}>;
export type RemoveProfileImageMutation = { __typename?: 'RootMutation', app?: { __typename?: 'AppMutation', removeProfileImage: { __typename?: 'App', id: string, fullName: string } } | null };
export type SetAppDisplayNameMutationVariables = Exact<{
appId: Scalars['ID']['input'];
appInfo: AppInfoInput;
}>;
export type SetAppDisplayNameMutation = { __typename?: 'RootMutation', app?: { __typename?: 'AppMutation', setAppInfo: { __typename?: 'App', id: string, name: string, fullName: string } } | null };
export type CreateAppVersionMutationVariables = Exact<{
appVersionInput: AppVersionInput;
}>;
@@ -7,12 +7,8 @@ import {
BackgroundJobReceiptDataFragment,
CreateAppMutation,
CreateAppMutationVariables,
RemoveProfileImageMutation,
RemoveProfileImageMutationVariables,
ScheduleAppDeletionMutation,
ScheduleAppDeletionMutationVariables,
SetAppDisplayNameMutation,
SetAppDisplayNameMutationVariables,
} from '../generated';
import { BackgroundJobReceiptNode } from '../types/BackgroundJobReceipt';
@@ -72,57 +68,4 @@ export const AppMutation = {
assert(receipt, 'Background job receipt must be defined');
return receipt;
},
async removeProfileImageAsync(
graphqlClient: ExpoGraphqlClient,
appId: string
): Promise<{ id: string; fullName: string }> {
const data = await withErrorHandlingAsync(
graphqlClient
.mutation<RemoveProfileImageMutation, RemoveProfileImageMutationVariables>(
gql`
mutation RemoveProfileImageMutation($appId: ID!) {
app {
removeProfileImage(appId: $appId) {
id
fullName
}
}
}
`,
{ appId },
{ additionalTypenames: ['App'] }
)
.toPromise()
);
const app = data.app?.removeProfileImage;
assert(app, 'App must be defined');
return app;
},
async setDisplayNameAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, displayName }: { appId: string; displayName: string }
): Promise<{ id: string; name: string; fullName: string }> {
const data = await withErrorHandlingAsync(
graphqlClient
.mutation<SetAppDisplayNameMutation, SetAppDisplayNameMutationVariables>(
gql`
mutation SetAppDisplayNameMutation($appId: ID!, $appInfo: AppInfoInput!) {
app {
setAppInfo(appId: $appId, appInfo: $appInfo) {
id
name
fullName
}
}
}
`,
{ appId, appInfo: { displayName } },
{ additionalTypenames: ['App'] }
)
.toPromise()
);
const app = data.app?.setAppInfo;
assert(app, 'App must be defined');
return app;
},
};
@@ -4,7 +4,6 @@ import { getPrivateExpoConfigAsync } from '../expoConfig';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppUploadSessionType } from '../../graphql/generated';
import { AppQuery } from '../../graphql/queries/AppQuery';
import Log from '../../log';
import { uploadAppScopedFileAtPathToGCSAsync } from '../../uploads';
import { maybeSetProjectIconFromAppConfigAsync, resolveAppConfigIconAsync } from '../projectIcon';
@@ -68,48 +67,6 @@ describe(resolveAppConfigIconAsync, () => {
});
});
it('prefers a supported image over an earlier icon in an unsupported format', async () => {
vol.fromJSON({
'/app/assets/app.icon/icon.json': '{}',
'/app/assets/foreground.png': 'fake-png-bytes',
});
mockAppConfig({
ios: { icon: './assets/app.icon' },
android: { adaptiveIcon: { foregroundImage: './assets/foreground.png' } },
});
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
field: 'android.adaptiveIcon.foregroundImage',
path: '/app/assets/foreground.png',
});
});
it('prefers an image within the size limit over an earlier icon that is too large', async () => {
vol.fromJSON({
'/app/assets/icon.png': 'x'.repeat(10 * 1024 * 1024 + 1),
'/app/assets/ios-icon.png': 'fake-png-bytes',
});
mockAppConfig({ icon: './assets/icon.png', ios: { icon: './assets/ios-icon.png' } });
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
field: 'ios.icon',
path: '/app/assets/ios-icon.png',
});
});
it('prefers an image file over an earlier icon that is a directory', async () => {
vol.fromJSON({
'/app/assets/icon.png/contents.json': '{}',
'/app/assets/ios-icon.png': 'fake-png-bytes',
});
mockAppConfig({ icon: './assets/icon.png', ios: { icon: './assets/ios-icon.png' } });
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
field: 'ios.icon',
path: '/app/assets/ios-icon.png',
});
});
it('falls back to the Android adaptive icon foreground', async () => {
vol.fromJSON({ '/app/assets/foreground.png': 'fake-png-bytes' });
mockAppConfig({
@@ -122,16 +79,6 @@ describe(resolveAppConfigIconAsync, () => {
});
});
it('falls back to the Android icon', async () => {
vol.fromJSON({ '/app/assets/android-icon.png': 'fake-png-bytes' });
mockAppConfig({ android: { icon: './assets/android-icon.png' } });
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
field: 'android.icon',
path: '/app/assets/android-icon.png',
});
});
it('ignores a remote icon URL', async () => {
mockAppConfig({ icon: 'https://example.com/icon.png' });
@@ -179,7 +126,6 @@ describe(maybeSetProjectIconFromAppConfigAsync, () => {
maybeSetProjectIconFromAppConfigAsync(graphqlClient, { projectId, projectDir })
).resolves.toEqual({ status: 'skipped', reason: 'icon-already-set' });
expect(mockUploadAsync).not.toHaveBeenCalled();
expect(jest.mocked(Log.log).mock.calls.flat().join()).toContain('eas project:icon:set');
});
it('skips without a server round-trip when the app config has no icon', async () => {
@@ -212,17 +158,6 @@ describe(maybeSetProjectIconFromAppConfigAsync, () => {
expect(mockUploadAsync).not.toHaveBeenCalled();
});
it('does not propagate a failure to read the current icon', async () => {
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
mockAppConfig({ icon: './assets/icon.png' });
mockByIdProfileImageUrlAsync.mockRejectedValue(new Error('timeout'));
await expect(
maybeSetProjectIconFromAppConfigAsync(graphqlClient, { projectId, projectDir })
).resolves.toEqual({ status: 'skipped', reason: 'upload-failed' });
expect(mockUploadAsync).not.toHaveBeenCalled();
});
it('does not propagate an upload failure', async () => {
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
mockAppConfig({ icon: './assets/icon.png' });
+9 -21
View File
@@ -52,13 +52,13 @@ export async function maybeSetProjectIconFromAppConfigAsync(
return { status: 'skipped', reason: 'invalid-icon' };
}
const existingIconUrl = await AppQuery.byIdProfileImageUrlAsync(graphqlClient, projectId);
if (existingIconUrl) {
Log.debug('The project already has an icon, skipping the icon from the app config.');
return { status: 'skipped', reason: 'icon-already-set' };
}
try {
if (await AppQuery.byIdProfileImageUrlAsync(graphqlClient, projectId)) {
Log.log(
`The project already has an icon. To replace it with "${icon.field}" from your app config, run ${chalk.bold('eas project:icon:set')}.`
);
return { status: 'skipped', reason: 'icon-already-set' };
}
await uploadProjectIconAsync(graphqlClient, { projectId, imagePath: icon.path });
} catch (error: any) {
Log.warn(`Failed to set the project icon from "${icon.field}": ${error.message}`);
@@ -88,24 +88,16 @@ export async function resolveAppConfigIconAsync(projectDir: string): Promise<App
['icon', exp.icon],
['ios.icon', exp.ios?.icon],
['android.adaptiveIcon.foregroundImage', exp.android?.adaptiveIcon?.foregroundImage],
['android.icon', exp.android?.icon],
];
let firstInvalidIcon: AppConfigIcon | null = null;
for (const [field, value] of candidates) {
const iconPath = resolveLocalIconPath(projectDir, value);
if (iconPath && (await fs.pathExists(iconPath))) {
const icon = { field, path: iconPath };
try {
await validateIconAsync(iconPath);
return icon;
} catch {
firstInvalidIcon ??= icon;
}
return { field, path: iconPath };
}
}
return firstInvalidIcon;
return null;
}
function resolveLocalIconPath(projectDir: string, value: unknown): string | null {
@@ -131,17 +123,13 @@ export async function validateIconAsync(imagePath: string): Promise<void> {
if (!(await fs.pathExists(imagePath))) {
throw new Error(`No file found at ${imagePath}`);
}
const stat = await fs.stat(imagePath);
if (!stat.isFile()) {
throw new Error(`${imagePath} is not a file.`);
}
const extension = path.extname(imagePath).toLowerCase();
if (!ALLOWED_EXTENSIONS.includes(extension)) {
throw new Error(
`Unsupported image format "${extension}". The icon must be a PNG or JPEG file.`
);
}
const { size } = stat;
const { size } = await fs.stat(imagePath);
if (size > MAX_IMAGE_SIZE_BYTES) {
throw new Error(
`The image is ${(size / 1024 / 1024).toFixed(1)} MB, but the maximum allowed size is 10 MB.`
+8
View File
@@ -6,6 +6,7 @@ import {
AppPlatform,
DeviceRunSessionByIdQuery,
DeviceRunSessionResourceClass,
DeviceRunSessionStatus,
DeviceRunSessionType,
} from '../graphql/generated';
import { link } from '../log';
@@ -21,6 +22,13 @@ import {
type DeviceRunSessionByIdResult = DeviceRunSessionByIdQuery['deviceRunSessions']['byId'];
export type DeviceRunSessionRemoteConfig = NonNullable<DeviceRunSessionByIdResult['remoteConfig']>;
export function isSimulatorStopConfirmed(
session: Pick<DeviceRunSessionByIdResult, 'id' | 'status'>,
requestedId: string
): boolean {
return session.id === requestedId && session.status === DeviceRunSessionStatus.Stopped;
}
/**
* Message shown when EAS Simulator is not enabled for the account. Shared by every
* command that can hit the gate so users always get the same upgrade pointer. The gate