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

Commit

Permalink
[xdl][cli] Fix beta integration of init (#2978)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Nov 30, 2020
1 parent da4d8d8 commit 515182f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/expo-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BareAppConfig, getConfig } from '@expo/config';
import { AndroidConfig, IOSConfig } from '@expo/config-plugins';
import plist from '@expo/plist';
import spawnAsync from '@expo/spawn-async';
import { Exp, UserManager } from '@expo/xdl';
import { Exp, UserManager, Versions } from '@expo/xdl';
import chalk from 'chalk';
import program, { Command } from 'commander';
import fs from 'fs-extra';
Expand Down Expand Up @@ -180,6 +180,25 @@ async function action(projectDir: string, command: Command) {
resolvedTemplate = 'blank';
}

const {
version: newestSdkVersion,
data: newestSdkReleaseData,
} = await Versions.newestReleasedSdkVersionAsync();

// If the user is opting into a beta then we need to append the template tag explicitly
// in order to not fall back to the latest tag for templates.
let versionParam = '';
if (newestSdkReleaseData?.beta) {
const majorVersion = parseInt(newestSdkVersion, 10);
versionParam = `@sdk-${majorVersion}`;

// If the --template flag is provided without an explicit version, then opt-in to
// the beta version
if (resolvedTemplate && !resolvedTemplate.includes('@')) {
resolvedTemplate = `${resolvedTemplate}${versionParam}`;
}
}

let templateSpec;
if (resolvedTemplate) {
templateSpec = npmPackageArg(resolvedTemplate);
Expand Down Expand Up @@ -228,7 +247,7 @@ async function action(projectDir: string, command: Command) {
'--template: argument is required in non-interactive mode. Valid choices are: "blank", "tabs", "bare-minimum" or any custom template (name of npm package).',
}
);
templateSpec = npmPackageArg(template);
templateSpec = npmPackageArg(`${template}${versionParam}`);
}

const projectName = path.basename(projectRoot);
Expand Down
5 changes: 5 additions & 0 deletions packages/xdl/src/Versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export async function versionsAsync(): Promise<Versions> {
0,
path.join(__dirname, '../caches/versions.json')
);

// Clear cache when opting in to beta because things can change quickly in beta
if (getenv.boolish('EXPO_BETA', false)) {
versionCache.clearAsync();
}
return await versionCache.getAsync();
}

Expand Down

0 comments on commit 515182f

Please sign in to comment.