Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-12371][eas-cli] allow user to select package manager when doing onboarding #2402

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🎉 New features

- Allow selecting package manager when doing onboarding. ([#2402](https://github.com/expo/eas-cli/pull/2402) by [@szdziedzic](https://github.com/szdziedzic))

### 🐛 Bug fixes

- Use the correct app config for no GitHub flow in `init:onboarding`. ([#2397](https://github.com/expo/eas-cli/pull/2397) by [@szdziedzic](https://github.com/szdziedzic))
Expand Down
32 changes: 31 additions & 1 deletion packages/eas-cli/src/commands/project/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import {
runGitPushAsync,
} from '../../onboarding/git';
import { installDependenciesAsync } from '../../onboarding/installDependencies';
import {
PackageManager,
getAvailablePackageManagersAsync,
getLockfileForPackageManager,
} from '../../onboarding/packageManagers';
import { runCommandAsync } from '../../onboarding/runCommand';
import { RequestedPlatform } from '../../platform';
import { ExpoConfigOptions, getPrivateExpoConfig } from '../../project/expoConfig';
Expand Down Expand Up @@ -178,9 +183,12 @@ export default class Onboarding extends EasCommand {
});
}

const packageManager = await selectPackageManagerAsync();
await installDependenciesAsync({
projectDir: finalTargetProjectDirectory,
packageManager,
});

const exp = await getPrivateExpoConfigWithProjectIdAsync({
projectDir: finalTargetProjectDirectory,
graphqlClient,
Expand Down Expand Up @@ -212,7 +220,7 @@ export default class Onboarding extends EasCommand {
});
Log.log();
}
await vcsClient.trackFileAsync('package-lock.json');
await vcsClient.trackFileAsync(getLockfileForPackageManager(packageManager));

const shouldSetupCredentials =
((platform === Platform.IOS &&
Expand Down Expand Up @@ -492,3 +500,25 @@ async function configureProjectFromBareDefaultExpoTemplateAsync({
function stripInvalidCharactersForBundleIdentifier(string: string): string {
return string.replaceAll(/[^A-Za-z0-9]/g, '');
}

async function selectPackageManagerAsync(): Promise<PackageManager> {
const avilablePackageManagers = await getAvailablePackageManagersAsync();

let packageManager: PackageManager;
if (avilablePackageManagers.length === 1) {
packageManager = avilablePackageManagers[0];
} else {
const { selectedPackageManager } = await promptAsync({
type: 'select',
name: 'selectedPackageManager',
message: '📦 Which package manager would you like to use?',
choices: avilablePackageManagers.map(pm => ({
title: pm,
value: pm,
})),
});
Log.log();
packageManager = selectedPackageManager;
}
return packageManager;
}
5 changes: 4 additions & 1 deletion packages/eas-cli/src/onboarding/installDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { PackageManager } from './packageManagers';
import { runCommandAsync } from './runCommand';

export async function installDependenciesAsync({
projectDir,
packageManager,
}: {
projectDir: string;
packageManager: PackageManager;
}): Promise<void> {
// TODO: add support for other package managers
await runCommandAsync({
command: 'npm',
command: packageManager,
args: ['install'],
cwd: projectDir,
shouldShowStderrLine: line => {
Expand Down
58 changes: 58 additions & 0 deletions packages/eas-cli/src/onboarding/packageManagers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import spawnAsync from '@expo/spawn-async';

export type PackageManager = 'bun' | 'yarn' | 'pnpm' | 'npm';

export function getLockfileForPackageManager(packageManager: PackageManager): string {
switch (packageManager) {
case 'bun':
return 'bun.lockb';
case 'yarn':
return 'yarn.lock';
case 'pnpm':
return 'pnpm-lock.yaml';
case 'npm':
return 'package-lock.json';
}
}

export async function getAvailablePackageManagersAsync(): Promise<PackageManager[]> {
const availablePackageManagers: PackageManager[] = [];
if (await isBunAvailableAsync()) {
availablePackageManagers.push('bun');
}
if (await isYarnAvailableAsync()) {
availablePackageManagers.push('yarn');
}
if (await isPnpmAvailableAsync()) {
availablePackageManagers.push('pnpm');
}
availablePackageManagers.push('npm');
return availablePackageManagers;
}

async function isBunAvailableAsync(): Promise<boolean> {
try {
await spawnAsync('bun', ['--version']);
return true;
} catch {
return false;
}
}

async function isYarnAvailableAsync(): Promise<boolean> {
try {
await spawnAsync('yarn', ['--version']);
return true;
} catch {
return false;
}
}

async function isPnpmAvailableAsync(): Promise<boolean> {
try {
await spawnAsync('pnpm', ['--version']);
return true;
} catch {
return false;
}
}
Loading