Skip to content

Commit 295b83f

Browse files
feat(check_peer_dependencies): don't require --yarn or --npm command line, infer it from package-lock.json or yarn.lock
1 parent 6c9cc3e commit 295b83f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

check_peer_dependencies.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const yargs = require('yargs')
2525
.check(argv => {
2626
if (argv.yarn && argv.npm) {
2727
throw new Error('Specify either --yarn or --npm but not both');
28-
} else if (!argv.yarn && !argv.npm) {
29-
throw new Error('Specify either --yarn or --npm');
3028
}
3129
return true;
3230
});
@@ -192,16 +190,24 @@ if (missingPackages.length || incorrectPackages.length) {
192190
console.log();
193191
}
194192

193+
function getPackageManager() {
194+
if (yargs.argv.yarn) return 'yarn';
195+
if (yargs.argv.npm) return 'npm';
196+
if (fs.existsSync('yarn.lock')) return 'yarn';
197+
if (fs.existsSync('package-lock.json')) return 'npm';
198+
}
199+
const packageManager = getPackageManager();
200+
195201
function getCommandLines() {
196202
const commands = [];
197-
if (yargs.argv.yarn) {
203+
if (packageManager === 'yarn') {
198204
if (adds.length) {
199205
commands.push(`yarn add ${adds.join(' ')}`);
200206
}
201207
if (upgrades.length) {
202208
commands.push(`yarn upgrade ${upgrades.join(' ')}`);
203209
}
204-
} else {
210+
} else if (packageManager === 'npm') {
205211
commands.push(`npm install ${adds.concat(upgrades).join(' ')}`)
206212
}
207213
return commands;

0 commit comments

Comments
 (0)