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

added packageManager cli option support #680

Merged
merged 2 commits into from
Aug 19, 2021
Merged
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
8 changes: 8 additions & 0 deletions packages/rnv/src/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ export const PARAM_KEYS = {
isRequired: true,
description: 'Use custom name for ./renative.json. (applies only at root level)'
},
packageManager: {
value: 'value',
description: 'Specify the desired package manager to be used',
examples: [
'--packageManager yarn',
'--packageManager npm'
]
}
};

Object.keys(PARAM_KEYS).forEach((k) => {
Expand Down
25 changes: 20 additions & 5 deletions packages/rnv/src/core/systemManager/npmUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,25 @@ export const installPackageDependencies = async (c, failOnError = false) => {
const yarnLockPath = path.join(c.paths.project.dir, 'yarn.lock');
const npmLockPath = path.join(c.paths.project.dir, 'package-lock.json');
let command = 'npm install';
if (fsExistsSync(yarnLockPath)) {
command = 'yarn';
} else if (fsExistsSync(npmLockPath)) {
command = 'npm install';
} else if (isYarnInstalled) {


const yarnLockExists = fsExistsSync(yarnLockPath);
const packageLockExists = fsExistsSync(npmLockPath);

if (yarnLockExists || packageLockExists) {
// a lock file exists, defaulting to whichever is present
if (yarnLockExists && !isYarnInstalled) throw new Error('You have a yarn.lock file but you don\'t have yarn installed. Install it or delete yarn.lock');
command = yarnLockExists ? 'yarn' : 'npm install';
} else if (c.program.packageManager) {
// no lock file check cli option
if (['yarn', 'npm'].includes(c.program.packageManager)) {
command = c.program.packageManager === 'yarn' ? 'yarn' : 'npm install';
if (command === 'yarn' && !isYarnInstalled) throw new Error('You specified yarn as packageManager but it\'s not installed');
} else {
throw new Error(`Unsupported package manager ${c.program.packageManager}. Only yarn and npm are supported at the moment.`);
}
} else {
// no cli option either, asking
const { packageManager } = await inquirerPrompt({
type: 'list',
name: 'packageManager',
Expand All @@ -168,6 +182,7 @@ export const installPackageDependencies = async (c, failOnError = false) => {
});
if (packageManager === 'yarn') command = 'yarn';
}

logTask('installPackageDependencies', `packageManager:(${command})`);

try {
Expand Down