mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-24 16:16:17 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a4b20ee64 |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'eas-cli': patch
|
||||
---
|
||||
|
||||
When a project is unconfigured, only suggest creating it if the current credential can create projects on the target account.
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
getPrivateExpoConfigAsync,
|
||||
} from '../../../project/expoConfig';
|
||||
import { fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync } from '../../../project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync';
|
||||
import { getUnconfiguredProjectError } from '../../../project/projectNotConfiguredError';
|
||||
import { ProjectNotConfiguredError } from '../../../project/projectNotConfiguredError';
|
||||
import { promptAsync } from '../../../prompts';
|
||||
import SessionManager from '../../../user/SessionManager';
|
||||
import { Actor, getActorUsername } from '../../../user/User';
|
||||
@@ -230,7 +230,7 @@ async function chooseAccountNameForEASProjectAsync(
|
||||
}
|
||||
|
||||
if (actor.__typename === 'Robot') {
|
||||
throw getUnconfiguredProjectError({
|
||||
throw new ProjectNotConfiguredError({
|
||||
actor,
|
||||
reason: 'A robot access token cannot configure it interactively.',
|
||||
additionalFix: 'Alternatively, set the "owner" field in your app config.',
|
||||
@@ -243,7 +243,7 @@ async function chooseAccountNameForEASProjectAsync(
|
||||
}
|
||||
|
||||
if (options.nonInteractive) {
|
||||
throw getUnconfiguredProjectError({ actor });
|
||||
throw new ProjectNotConfiguredError({ actor });
|
||||
}
|
||||
|
||||
const choices = getAccountChoices(actor);
|
||||
|
||||
+24
-19
@@ -5,23 +5,28 @@ import { jester } from '../../credentials/__tests__/fixtures-constants';
|
||||
import { fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync } from '../fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync';
|
||||
|
||||
describe(fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync, () => {
|
||||
it('throws when non-interactive is specified but interaction is required', async () => {
|
||||
const graphqlClient = instance(mock<ExpoGraphqlClient>());
|
||||
await expect(
|
||||
fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync(
|
||||
graphqlClient,
|
||||
{ accountName: 'fake', projectName: 'fake' },
|
||||
{ nonInteractive: true },
|
||||
jester
|
||||
)
|
||||
).rejects.toThrow(
|
||||
`EAS project not configured. This command cannot configure it in non-interactive mode. ` +
|
||||
`Run one of the following, then re-run this command:\n\n` +
|
||||
`To link an existing project:\n\n` +
|
||||
` eas init --id <project-id> --non-interactive\n\n` +
|
||||
`To create a new project:\n\n` +
|
||||
` eas init --account fake --non-interactive\n\n` +
|
||||
`Accounts you can create projects in: jester`
|
||||
);
|
||||
});
|
||||
it.each([
|
||||
{ accounts: jester.accounts, eligibleAccounts: ['jester'] },
|
||||
{ accounts: [], eligibleAccounts: [] },
|
||||
])(
|
||||
'only suggests linking when the owner cannot create projects',
|
||||
async ({ accounts, eligibleAccounts }) => {
|
||||
const graphqlClient = instance(mock<ExpoGraphqlClient>());
|
||||
await expect(
|
||||
fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync(
|
||||
graphqlClient,
|
||||
{ accountName: 'fake', projectName: 'fake' },
|
||||
{ nonInteractive: true },
|
||||
{ ...jester, accounts }
|
||||
)
|
||||
).rejects.toMatchObject({
|
||||
accountName: 'fake',
|
||||
eligibleAccounts,
|
||||
message:
|
||||
`EAS project not configured. This command cannot configure it in non-interactive mode. ` +
|
||||
`To link an existing project:\n\n` +
|
||||
` eas init --id <project-id> --non-interactive`,
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import chalk from 'chalk';
|
||||
|
||||
import { getUnconfiguredProjectError } from './projectNotConfiguredError';
|
||||
import { ProjectNotConfiguredError } from './projectNotConfiguredError';
|
||||
import { getProjectDashboardUrl } from '../build/utils/url';
|
||||
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppMutation } from '../graphql/mutations/AppMutation';
|
||||
@@ -33,7 +33,7 @@ export async function fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsyn
|
||||
const allAccounts = actor.accounts;
|
||||
|
||||
if (options.nonInteractive) {
|
||||
throw getUnconfiguredProjectError({ actor, accountName });
|
||||
throw new ProjectNotConfiguredError({ actor, accountName });
|
||||
}
|
||||
const account = allAccounts.find(a => a.name === accountName);
|
||||
if (!account) {
|
||||
|
||||
@@ -4,31 +4,39 @@ import { Actor, getCreatableAccountNames } from '../user/User';
|
||||
* Build the error shown when an EAS project is not configured and the CLI cannot configure it
|
||||
* without more input. Lists the exact commands to run, because bare "eas init" also needs
|
||||
* interaction and fails in the same situation.
|
||||
*
|
||||
* @param actor the logged-in actor
|
||||
* @param accountName the account that should own the project, when it is already known
|
||||
* @param reason why the CLI cannot configure the project here
|
||||
* @param additionalFix an extra way to resolve the error, appended at the end
|
||||
*/
|
||||
export function getUnconfiguredProjectError({
|
||||
actor,
|
||||
accountName,
|
||||
reason = 'This command cannot configure it in non-interactive mode.',
|
||||
additionalFix,
|
||||
}: {
|
||||
actor: Actor;
|
||||
accountName?: string;
|
||||
reason?: string;
|
||||
additionalFix?: string;
|
||||
}): Error {
|
||||
return new Error(
|
||||
`EAS project not configured. ${reason} ` +
|
||||
`Run one of the following, then re-run this command:\n\n` +
|
||||
`To link an existing project:\n\n` +
|
||||
` eas init --id <project-id> --non-interactive\n\n` +
|
||||
`To create a new project:\n\n` +
|
||||
` eas init --account ${accountName ?? '<account-name>'} --non-interactive\n\n` +
|
||||
`Accounts you can create projects in: ${getCreatableAccountNames(actor).join(', ')}` +
|
||||
(additionalFix ? `\n\n${additionalFix}` : '')
|
||||
);
|
||||
export class ProjectNotConfiguredError extends Error {
|
||||
readonly accountName?: string;
|
||||
readonly eligibleAccounts: string[];
|
||||
|
||||
constructor({
|
||||
actor,
|
||||
accountName,
|
||||
reason = 'This command cannot configure it in non-interactive mode.',
|
||||
additionalFix,
|
||||
}: {
|
||||
actor: Actor;
|
||||
accountName?: string;
|
||||
reason?: string;
|
||||
additionalFix?: string;
|
||||
}) {
|
||||
const eligibleAccounts = getCreatableAccountNames(actor);
|
||||
const canCreate =
|
||||
accountName === undefined
|
||||
? eligibleAccounts.length > 0
|
||||
: eligibleAccounts.includes(accountName);
|
||||
const linkExisting =
|
||||
'To link an existing project:\n\n eas init --id <project-id> --non-interactive';
|
||||
const guidance = canCreate
|
||||
? `Run one of the following, then re-run this command:\n\n${linkExisting}\n\n` +
|
||||
`To create a new project:\n\n eas init --account ${accountName ?? '<account-name>'} --non-interactive\n\n` +
|
||||
`Accounts you can create projects in: ${eligibleAccounts.join(', ')}`
|
||||
: linkExisting;
|
||||
super(
|
||||
`EAS project not configured. ${reason} ${guidance}` +
|
||||
(additionalFix ? `\n\n${additionalFix}` : '')
|
||||
);
|
||||
this.accountName = accountName;
|
||||
this.eligibleAccounts = eligibleAccounts;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user