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

Support yarn #343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 12 additions & 7 deletions lib/out/install-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions lib/out/interactive-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down
24 changes: 21 additions & 3 deletions lib/out/static-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = _([
Expand All @@ -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 ${packageName} --save${pkg.devDependency ? '-dev' : ''}`
)}`
] : '',
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) : ''
Expand Down
11 changes: 6 additions & 5 deletions lib/out/update-all.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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');
}
}

Expand Down