From 61c178151890f171ffc759464a6419ade8b0da15 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Fri, 18 Oct 2019 17:50:41 +0800 Subject: [PATCH] support pnpm4 --- lib/cli.js | 7 ++++++- lib/out/pm-speaker.js | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 2dabe187..b9d850f8 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -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(); @@ -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; }) } diff --git a/lib/out/pm-speaker.js b/lib/out/pm-speaker.js index b216ee17..184ab87a 100644 --- a/lib/out/pm-speaker.js +++ b/lib/out/pm-speaker.js @@ -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; @@ -53,7 +54,7 @@ function pmCli(packages, currentState, action = 'install') { } else { save = { dev: isYarn ? ['--save-dev'] : ['--dev'], - normal: isYarn ? [] : ['--save'] + normal: (isYarn || isPnpm4) ? [] : ['--save'] }; } @@ -73,7 +74,8 @@ 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; @@ -81,6 +83,7 @@ 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)}...`);