Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[cli] Add expo-random when upgrading to >= SDK 40 with expo-auth-session
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Dec 9, 2020
1 parent bfd3e9b commit 0457835
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions packages/expo-cli/src/commands/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import chalk from 'chalk';
import program, { Command } from 'commander';
import getenv from 'getenv';
import difference from 'lodash/difference';
import omit from 'lodash/omit';
import pickBy from 'lodash/pickBy';
import ora from 'ora';
import semver from 'semver';
Expand Down Expand Up @@ -83,7 +84,8 @@ async function getExactInstalledModuleVersionAsync(
export async function getUpdatedDependenciesAsync(
projectRoot: string,
workflow: ExpoWorkflow,
targetSdkVersion: TargetSDKVersion | null
targetSdkVersion: TargetSDKVersion | null,
targetSdkVersionString: string
): Promise<DependencyList> {
// Get the updated version for any bundled modules
const { exp, pkg } = getConfig(projectRoot);
Expand All @@ -94,13 +96,27 @@ export async function getUpdatedDependenciesAsync(
// Smoosh regular and dev dependencies together for now
const projectDependencies = { ...pkg.dependencies, ...pkg.devDependencies };

return getDependenciesFromBundledNativeModules({
const dependencies = getDependenciesFromBundledNativeModules({
projectDependencies,
bundledNativeModules,
sdkVersion: exp.sdkVersion,
workflow,
targetSdkVersion,
});

// Add expo-random as a dependency if using expo-auth-session and upgrading to
// a version where it has been moved to a peer dependency.
// We can remove this when we no longer support SDK versions < 40, or have a
// better way of installing peer dependencies.
if (
dependencies['expo-auth-session'] &&
!dependencies['expo-random'] &&
semver.gte(targetSdkVersionString, '40.0.0')
) {
dependencies['expo-random'] = bundledNativeModules['expo-random'];
}

return dependencies;
}

export type UpgradeDependenciesOptions = {
Expand Down Expand Up @@ -589,14 +605,21 @@ export async function upgradeAsync(
log.addNewLineIfNone();

// Get all updated packages
const updates = await getUpdatedDependenciesAsync(projectRoot, workflow, targetSdkVersion);
const updates = await getUpdatedDependenciesAsync(
projectRoot,
workflow,
targetSdkVersion,
targetSdkVersionString
);

// Split updated packages by dependencies and devDependencies
const devDependencies = pickBy(updates, (_version, name) => pkg.devDependencies?.[name]);
const devDependenciesAsStringArray = Object.keys(devDependencies).map(
name => `${name}@${updates[name]}`
);
const dependencies = pickBy(updates, (_version, name) => pkg.dependencies?.[name]);

// Anything that isn't in devDependencies must be a dependency
const dependencies = omit(updates, Object.keys(devDependencies));
const dependenciesAsStringArray = Object.keys(dependencies).map(
name => `${name}@${updates[name]}`
);
Expand Down

0 comments on commit 0457835

Please sign in to comment.