Skip to content

Commit

Permalink
[expo-updates] Gate roll back to embedded to expo-updates >= 0.19.0 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman authored Oct 18, 2023
1 parent 743ae7c commit 14980fe
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is the log of notable changes to EAS CLI and related packages.
### 🎉 New features

- Add account type to the items in the prompt to select project owner. ([#2083](https://github.com/expo/eas-cli/pull/2083) by [@alanjhughes](https://github.com/alanjhughes))
- Gate roll back to embedded to expo-updates >= 0.19.0. ([#2094](https://github.com/expo/eas-cli/pull/2094) by [@wschurman](https://github.com/wschurman))

### 🐛 Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jest.mock('@expo/config');
jest.mock('@expo/config-plugins');
jest.mock('../../../branch/queries');
jest.mock('../../../commandUtils/context/contextUtils/getProjectIdAsync');
jest.mock('../../../project/projectUtils', () => ({
...jest.requireActual('../../../project/projectUtils'),
enforceRollBackToEmbeddedUpdateSupportAsync: jest.fn(),
}));
jest.mock('../../../update/configure');
jest.mock('../../../update/getBranchNameFromChannelNameAsync');
jest.mock('../../../graphql/mutations/PublishMutation');
Expand Down
9 changes: 7 additions & 2 deletions packages/eas-cli/src/commands/update/roll-back-to-embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { PublishMutation } from '../../graphql/mutations/PublishMutation';
import Log, { link } from '../../log';
import { ora } from '../../ora';
import { RequestedPlatform } from '../../platform';
import { getOwnerAccountForProjectIdAsync } from '../../project/projectUtils';
import {
enforceRollBackToEmbeddedUpdateSupportAsync,
getOwnerAccountForProjectIdAsync,
} from '../../project/projectUtils';
import {
ExpoCLIExportPlatformFlag,
defaultPublishPlatforms,
Expand Down Expand Up @@ -67,7 +70,6 @@ type UpdateFlags = {
};

export default class UpdateRollBackToEmbedded extends EasCommand {
static override hidden = true; // until we launch
static override description = 'roll back to the embedded update';

static override flags = {
Expand Down Expand Up @@ -154,6 +156,9 @@ export default class UpdateRollBackToEmbedded extends EasCommand {
vcsClient,
});

// check that the expo-updates package version supports roll back to embedded
await enforceRollBackToEmbeddedUpdateSupportAsync(projectDir);

const { exp } = await getDynamicPublicProjectConfigAsync();
const { exp: expPrivate } = await getDynamicPrivateProjectConfigAsync();
const codeSigningInfo = await getCodeSigningInfoAsync(expPrivate, privateKeyPath);
Expand Down
2 changes: 0 additions & 2 deletions packages/eas-cli/src/commands/update/rollback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import UpdateRollBackToEmbedded from './roll-back-to-embedded';
export default class UpdateRollback extends EasCommand {
static override description = 'roll back to an embedded update or an existing update';

static override hidden = true;

static override flags = {
'private-key-path': Flags.string({
description: `File containing the PEM-encoded private key corresponding to the certificate in expo-updates' configuration. Defaults to a file named "private-key.pem" in the certificate's directory.`,
Expand Down
68 changes: 68 additions & 0 deletions packages/eas-cli/src/project/__tests__/projectUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { AppJSONConfig, PackageJSONConfig } from '@expo/config';
import { vol } from 'memfs';
import path from 'path';
import resolveFrom from 'resolve-from';

import { enforceRollBackToEmbeddedUpdateSupportAsync } from '../projectUtils';

jest.mock('fs');
jest.mock('resolve-from');

const projectRoot = '/test-project';

describe(enforceRollBackToEmbeddedUpdateSupportAsync, () => {
it('does not throw when an appropriate version is installed', async () => {
mockTestProject('0.19.1');

await enforceRollBackToEmbeddedUpdateSupportAsync(projectRoot);
});

it('throws when an unappropriate version is installed', async () => {
mockTestProject('0.18.0');

await expect(enforceRollBackToEmbeddedUpdateSupportAsync(projectRoot)).rejects.toThrowError(
'The expo-updates package must have a version >= 0.19.0 to use roll back to embedded, which corresponds to Expo SDK 50 or greater.'
);
});
});

function mockTestProject(expoUpdatesPackageVersion: string): { appJson: AppJSONConfig } {
const packageJSON: PackageJSONConfig = {
name: 'testing123',
version: '0.1.0',
description: 'fake description',
main: 'index.js',
dependencies: {
'expo-updates': expoUpdatesPackageVersion,
},
};

const expoUpdatesPackageJSON: PackageJSONConfig = {
name: 'expo-updates',
version: expoUpdatesPackageVersion,
};

const appJSON: AppJSONConfig = {
expo: {
name: 'testing 123',
version: '0.1.0',
slug: 'testing-123',
sdkVersion: '33.0.0',
},
};

jest
.mocked(resolveFrom.silent)
.mockReturnValue(path.join(projectRoot, 'node_modules/expo-updates/package.json'));

vol.fromJSON(
{
'package.json': JSON.stringify(packageJSON),
'app.json': JSON.stringify(appJSON),
'node_modules/expo-updates/package.json': JSON.stringify(expoUpdatesPackageJSON),
},
projectRoot
);

return { appJson: appJSON };
}
17 changes: 17 additions & 0 deletions packages/eas-cli/src/project/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ export async function validateAppVersionRuntimePolicySupportAsync(
);
}

export async function enforceRollBackToEmbeddedUpdateSupportAsync(
projectDir: string
): Promise<void> {
const maybePackageJson = resolveFrom.silent(projectDir, 'expo-updates/package.json');

if (maybePackageJson) {
const { version } = await fs.readJson(maybePackageJson);
if (semver.gte(version, '0.19.0')) {
return;
}
}

throw new Error(
'The expo-updates package must have a version >= 0.19.0 to use roll back to embedded, which corresponds to Expo SDK 50 or greater.'
);
}

export async function installExpoUpdatesAsync(
projectDir: string,
options?: { silent: boolean }
Expand Down

0 comments on commit 14980fe

Please sign in to comment.