Skip to content

Commit

Permalink
[ENG-12057][eas-cli] don't prompt user to set android.package and `…
Browse files Browse the repository at this point in the history
…ios.bundleIdentifier` value when runing in non-interactive mode (#2336)

* [eas-cli] don't prompt user to set `android.package` and `ios.bundleIdentifier` value when runing in non-interactive mode

* update CHANGELOG.md

* rename test
  • Loading branch information
szdziedzic authored Apr 23, 2024
1 parent 44cd3b2 commit 9ef86f5
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🐛 Bug fixes

- Don't prompt to set `android.package` and `ios.bundleIdentifier` values when running in non-interactive mode. ([#2336](https://github.com/expo/eas-cli/pull/2336) by [@szdziedzic](https://github.com/szdziedzic))

### 🧹 Chores

- Amend credential removal wording. ([#2334](https://github.com/expo/eas-cli/pull/2334) by [@quinlanj](https://github.com/quinlanj))
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/commands/build/version/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default class BuildVersionGetView extends EasCommand {
buildProfile: profile,
platform,
vcsClient,
nonInteractive: flags['non-interactive'],
});
const remoteVersions = await AppVersionQuery.latestVersionAsync(
graphqlClient,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/commands/build/version/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class BuildVersionSetView extends EasCommand {
buildProfile: profile,
platform,
vcsClient,
nonInteractive: false,
});
const remoteVersions = await AppVersionQuery.latestVersionAsync(
graphqlClient,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/commands/build/version/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default class BuildVersionSyncView extends EasCommand {
buildProfile: profileInfo.profile,
platform: profileInfo.platform,
vcsClient,
nonInteractive: false,
});
const remoteVersions = await AppVersionQuery.latestVersionAsync(
graphqlClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,30 @@ describe(ensureApplicationIdIsDefinedForManagedProjectAsync, () => {
projectId: '',
exp: {} as any,
vcsClient,
nonInteractive: false,
})
).rejects.toThrowError(/we can't update this file programmatically/);
});
it('throws an error in non-interactive mode', async () => {
const graphqlClient = instance(mock<ExpoGraphqlClient>());

vol.fromJSON(
{
'app.json': '{ "blah": {} }',
},
'/app'
);
await expect(
ensureApplicationIdIsDefinedForManagedProjectAsync({
graphqlClient,
projectDir: '/app',
projectId: '',
exp: {} as any,
vcsClient,
nonInteractive: true,
})
).rejects.toThrowError(/non-interactive/);
});
it('prompts for the Android package if using app.json', async () => {
const graphqlClient = instance(mock<ExpoGraphqlClient>());
jest.mocked(AppQuery.byIdAsync).mockResolvedValue({
Expand Down Expand Up @@ -163,6 +184,7 @@ describe(ensureApplicationIdIsDefinedForManagedProjectAsync, () => {
projectId: '',
exp: {} as any,
vcsClient,
nonInteractive: false,
})
).resolves.toBe('com.expo.notdominik');
expect(promptAsync).toHaveBeenCalled();
Expand Down Expand Up @@ -196,6 +218,7 @@ describe(ensureApplicationIdIsDefinedForManagedProjectAsync, () => {
projectId: '',
exp: {} as any,
vcsClient,
nonInteractive: false,
})
).resolves.toBe('com.expo.notdominik');
const appJson = JSON.parse(await fs.readFile('/app/app.json', 'utf-8'));
Expand Down
20 changes: 19 additions & 1 deletion packages/eas-cli/src/project/android/applicationId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export async function ensureApplicationIdIsDefinedForManagedProjectAsync({
projectId,
exp,
vcsClient,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectDir: string;
projectId: string;
exp: ExpoConfig;
vcsClient: Client;
nonInteractive: boolean;
}): Promise<string> {
const workflow = await resolveWorkflowAsync(projectDir, Platform.ANDROID, vcsClient);
assert(workflow === Workflow.MANAGED, 'This function should be called only for managed projects');
Expand All @@ -43,7 +45,13 @@ export async function ensureApplicationIdIsDefinedForManagedProjectAsync({
moduleName: gradleUtils.DEFAULT_MODULE_NAME,
});
} catch {
return await configureApplicationIdAsync({ graphqlClient, projectDir, projectId, exp });
return await configureApplicationIdAsync({
graphqlClient,
projectDir,
projectId,
exp,
nonInteractive,
});
}
}

Expand Down Expand Up @@ -128,12 +136,22 @@ async function configureApplicationIdAsync({
projectDir,
projectId,
exp,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectDir: string;
projectId: string;
exp: ExpoConfig;
nonInteractive: boolean;
}): Promise<string> {
if (nonInteractive) {
throw new Error(
`The "android.package" is required to be set in app config when running in non-interactive mode. ${learnMore(
'https://docs.expo.dev/versions/latest/config/app/#package'
)}`
);
}

const paths = getConfigFilePaths(projectDir);
// we can't automatically update app.config.js
if (paths.dynamicConfigPath) {
Expand Down
4 changes: 4 additions & 0 deletions packages/eas-cli/src/project/applicationIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function getApplicationIdentifierAsync({
buildProfile,
platform,
vcsClient,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectDir: string;
Expand All @@ -33,6 +34,7 @@ export async function getApplicationIdentifierAsync({
buildProfile: BuildProfile;
platform: Platform;
vcsClient: Client;
nonInteractive: boolean;
}): Promise<string> {
if (platform === Platform.ANDROID) {
const profile = buildProfile as BuildProfile<Platform.ANDROID>;
Expand All @@ -45,6 +47,7 @@ export async function getApplicationIdentifierAsync({
projectId,
exp,
vcsClient,
nonInteractive,
});
}

Expand All @@ -60,6 +63,7 @@ export async function getApplicationIdentifierAsync({
projectId,
exp,
vcsClient,
nonInteractive,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,29 @@ describe(ensureBundleIdentifierIsDefinedForManagedProjectAsync, () => {
projectId: '1234',
exp: {} as any,
vcsClient,
nonInteractive: false,
})
).rejects.toThrowError(/we can't update this file programmatically/);
});
it('throws an error in non-interactive mode', async () => {
const graphqlClient = instance(mock<ExpoGraphqlClient>());
vol.fromJSON(
{
'app.json': '{ "blah": {} }',
},
'/app'
);
await expect(
ensureBundleIdentifierIsDefinedForManagedProjectAsync({
graphqlClient,
projectDir: '/app',
projectId: '1234',
exp: {} as any,
vcsClient,
nonInteractive: true,
})
).rejects.toThrowError(/non-interactive/);
});
it('prompts for the bundle identifier if using app.json', async () => {
const graphqlClient = instance(mock<ExpoGraphqlClient>());
jest.mocked(AppQuery.byIdAsync).mockResolvedValue({
Expand Down Expand Up @@ -141,6 +161,7 @@ describe(ensureBundleIdentifierIsDefinedForManagedProjectAsync, () => {
projectId: '1234',
exp: {} as any,
vcsClient,
nonInteractive: false,
})
).resolves.toBe('com.expo.notdominik');
expect(promptAsync).toHaveBeenCalled();
Expand Down Expand Up @@ -172,6 +193,7 @@ describe(ensureBundleIdentifierIsDefinedForManagedProjectAsync, () => {
projectId: '1234',
exp: {} as any,
vcsClient,
nonInteractive: false,
})
).resolves.toBe('com.expo.notdominik');
const appJson = JSON.parse(await fs.readFile('/app/app.json', 'utf-8'));
Expand Down
14 changes: 14 additions & 0 deletions packages/eas-cli/src/project/ios/bundleIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export async function ensureBundleIdentifierIsDefinedForManagedProjectAsync({
projectId,
exp,
vcsClient,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectDir: string;
projectId: string;
exp: ExpoConfig;
vcsClient: Client;
nonInteractive: boolean;
}): Promise<string> {
const workflow = await resolveWorkflowAsync(projectDir, Platform.IOS, vcsClient);
assert(workflow === Workflow.MANAGED, 'This function should be called only for managed projects');
Expand All @@ -39,6 +41,7 @@ export async function ensureBundleIdentifierIsDefinedForManagedProjectAsync({
projectDir,
exp,
projectId,
nonInteractive,
});
}
}
Expand Down Expand Up @@ -120,12 +123,22 @@ async function configureBundleIdentifierAsync({
projectDir,
projectId,
exp,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectDir: string;
projectId: string;
exp: ExpoConfig;
nonInteractive: boolean;
}): Promise<string> {
if (nonInteractive) {
throw new Error(
`The "ios.bundleIdentifier" is required to be set in app config when running in non-interactive mode. ${learnMore(
'https://docs.expo.dev/versions/latest/config/app/#bundleidentifier'
)}`
);
}

const paths = getConfigFilePaths(projectDir);
// we can't automatically update app.config.js
if (paths.dynamicConfigPath) {
Expand All @@ -148,6 +161,7 @@ async function configureBundleIdentifierAsync({
exp,
projectId
);

const { bundleIdentifier } = await promptAsync({
name: 'bundleIdentifier',
type: 'text',
Expand Down

0 comments on commit 9ef86f5

Please sign in to comment.