diff --git a/lib/cli.js b/lib/cli.js index 35129702..4cac447b 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -131,7 +131,7 @@ Promise.resolve() process.exit(1); }); -const SUPPORTED_INSTALLERS = ['npm', 'pnpm', 'ied']; +const SUPPORTED_INSTALLERS = ['npm', 'pnpm', 'ied', 'yarn']; function detectPreferredInstaller(cwd) { return detectPreferredPM(cwd) diff --git a/lib/out/install-packages.js b/lib/out/install-packages.js index a960f191..f31a5b50 100644 --- a/lib/out/install-packages.js +++ b/lib/out/install-packages.js @@ -10,24 +10,29 @@ function install(packages, currentState) { } const installer = currentState.get('installer'); - const installGlobal = currentState.get('global') ? '--global' : null; - const saveExact = currentState.get('saveExact') ? '--save-exact' : null; + const saveExact = currentState.get('saveExact') + + const isYarn = installer === 'yarn'; + const exact = saveExact ? (isYarn ? '--exact' : '--save-exact') : null; const color = chalk.supportsColor ? '--color=always' : null; - const npmArgs = ['install'] - .concat(installGlobal) - .concat(saveExact) + const install = [isYarn ? 'add' : 'install']; + if (currentState.get('global')) { + isYarn ? install.unshift('global') : install.push('--global'); + } + const args = install .concat(packages) + .concat(exact) .concat(color) .filter(Boolean); console.log(''); - console.log(`$ ${chalk.green(installer)} ${chalk.green(npmArgs.join(' '))}`); + console.log(`$ ${chalk.green(installer)} ${chalk.green(args.join(' '))}`); const spinner = ora(`Installing using ${chalk.green(installer)}...`); spinner.enabled = spinner.enabled && currentState.get('spinner'); spinner.start(); - return execa(installer, npmArgs, {cwd: currentState.get('cwd')}).then(output => { + return execa(installer, args, {cwd: currentState.get('cwd')}).then(output => { spinner.stop(); console.log(output.stdout); console.log(output.stderr); diff --git a/lib/out/interactive-update.js b/lib/out/interactive-update.js index 71174d22..d75c6bd9 100644 --- a/lib/out/interactive-update.js +++ b/lib/out/interactive-update.js @@ -145,13 +145,17 @@ function interactive(currentState) { const updatedPackages = packagesToUpdate .map(pkg => pkg.moduleName + '@' + pkg.latest).join(', '); + const isYarn = currentState.get('installer') === 'yarn'; + if (!currentState.get('global')) { if (saveDependencies.length) { - saveDependencies.unshift('--save'); + !isYarn && saveDependencies.push('--save'); } if (saveDevDependencies.length) { - saveDevDependencies.unshift('--save-dev'); + isYarn + ? saveDevDependencies.push('--dev') + : saveDevDependencies.push('--save-dev'); } } diff --git a/lib/out/static-output.js b/lib/out/static-output.js index 7eee0f69..6707e28e 100644 --- a/lib/out/static-output.js +++ b/lib/out/static-output.js @@ -14,8 +14,22 @@ function render(pkg, currentState) { const rows = []; const indent = ' ' + emoji(' '); - const flags = currentState.get('global') ? '--global' : `--save${pkg.devDependency ? '-dev' : ''}`; - const upgradeCommand = `npm install ${flags} ${packageName}@${pkg.latest}`; + const installer = currentState.get('installer'); + const isYarn = installer === 'yarn'; + + const args = [isYarn ? 'add' : 'install']; + if (currentState.get('global')) { + isYarn ? args.unshift('global') : args.push('--global'); + } + + const flags = []; + if (isYarn) { + pkg.devDependency && flags.push('--dev'); + } else { + pkg.devDependency ? flags.push('--save-dev') : flags.push('--save'); + } + + const upgradeCommand = `${installer} ${args.join(' ')} ${packageName}@${pkg.latest} ${flags.join(' ')}`; const upgradeMessage = `${chalk.green(upgradeCommand)} to go from ${pkg.installed} to ${pkg.latest}`; // DYLAN: clean this up const status = _([ @@ -35,7 +49,11 @@ function render(pkg, currentState) { indent + `Depcheck did not find code similar to ${chalk.green(`require('${packageName}')`)} or ${chalk.green(`import from '${packageName}'`)}.`, indent + `Check your code before removing as depcheck isn't able to foresee all ways dependencies can be used.`, indent + `Use ${chalk.green('--skip-unused')} to skip this check.`, - indent + `To remove this package: ${chalk.green(`npm uninstall --save${pkg.devDependency ? '-dev' : ''} ${packageName}`)}` + indent + `To remove this package: ${chalk.green( + isYarn + ? `yarn remove ${packageName} ${pkg.devDependency ? '--dev' : ''}` + : `npm uninstall --save${pkg.devDependency ? '-dev' : ''} ${packageName}` + )}` ] : '', pkg.mismatch && !pkg.bump ? chalk.bgRed.yellow.bold(emoji(' :interrobang: ') + ' MISMATCH ') + ' Installed version does not match package.json. ' + pkg.installed + ' ≠ ' + pkg.packageJson : '', pkg.regError ? chalk.bgRed.white.bold(emoji(' :no_entry: ') + ' NPM ERR! ') + ' ' + chalk.red(pkg.regError) : '' diff --git a/lib/out/update-all.js b/lib/out/update-all.js index 9a38be6c..b2c67120 100644 --- a/lib/out/update-all.js +++ b/lib/out/update-all.js @@ -1,9 +1,6 @@ 'use strict'; -const _ = require('lodash'); -const inquirer = require('inquirer'); const chalk = require('chalk'); -const table = require('text-table'); const installPackages = require('./install-packages'); const emoji = require('./emoji'); @@ -32,13 +29,17 @@ function updateAll(currentState) { const updatedPackages = packagesToUpdate .map(pkg => pkg.moduleName + '@' + pkg.latest).join(', '); + const isYarn = currentState.get('installer') === 'yarn'; + if (!currentState.get('global')) { if (saveDependencies.length) { - saveDependencies.unshift('--save'); + !isYarn && saveDependencies.push('--save'); } if (saveDevDependencies.length) { - saveDevDependencies.unshift('--save-dev'); + isYarn + ? saveDevDependencies.push('--dev') + : saveDevDependencies.push('--save-dev'); } }