Skip to content

Commit

Permalink
support pnpm4
Browse files Browse the repository at this point in the history
  • Loading branch information
Artoria2e5 committed Oct 18, 2019
1 parent 272b687 commit 61c1781
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const updateAll = require('./out/update-all');
const debug = require('./state/debug');
const pkgDir = require('pkg-dir');
const detectPreferredPM = require('preferred-pm');
const execa = require('execa')

updateNotifier({pkg}).notify();

Expand Down Expand Up @@ -136,7 +137,11 @@ const SUPPORTED_INSTALLERS = ['npm', 'pnpm', 'ied', 'yarn'];
function detectPreferredInstaller(cwd) {
return detectPreferredPM(cwd)
.then(preferredPM => {
return preferredPM && SUPPORTED_INSTALLERS.indexOf(preferredPM.name) !== -1 ?
let pm = preferredPM && SUPPORTED_INSTALLERS.indexOf(preferredPM.name) !== -1 ?
preferredPM.name : 'npm';
// Suffix the major version for pnpm@4.
if (pm === 'pnpm' && preferredPM.version === '>=3')
pm = 'pnpm@' + execa.sync('pnpm', ['--version']).stdout.toString().split('.')[0];
return pm;
})
}
9 changes: 6 additions & 3 deletions lib/out/pm-speaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ function pmCli(packages, currentState, action = 'install') {
const installer = currentState.get('installer');
const global = currentState.get('global');
const isYarn = installer === 'yarn';
const isPnpm4 = installler === 'pnpm@4';
const actions = {
install: isYarn ? 'add' : 'install',
install: (installer === 'ied') ? 'install' : 'add',
remove: isYarn ? 'remove' : 'uninstall'
}
actions.update = actions.install;
Expand All @@ -53,7 +54,7 @@ function pmCli(packages, currentState, action = 'install') {
} else {
save = {
dev: isYarn ? ['--save-dev'] : ['--dev'],
normal: isYarn ? [] : ['--save']
normal: (isYarn || isPnpm4) ? [] : ['--save']
};
}

Expand All @@ -73,14 +74,16 @@ module.exports.pmCli = pmCli;
*/
function pmCli1(package, currentState, action = 'install') {
const args = pmCli([package], currentState, action);
return args.find(x => x != null);
const installer = currentState.get('installer').split['@'][0];
return [installer].concat(args.find(x => x != null)).split['@'][0];
}
module.exports.pmCli1 = pmCli1;

function doInstall(installer, args) {
if (args === null)
return;

installer = installer.split['@'][0];
console.log('');
console.log(`$ ${chalk.green(installer)} ${chalk.green(args.join(' '))}`);
const spinner = ora(`Installing using ${chalk.green(installer)}...`);
Expand Down

0 comments on commit 61c1781

Please sign in to comment.