File tree Expand file tree Collapse file tree 4 files changed +40
-16
lines changed Expand file tree Collapse file tree 4 files changed +40
-16
lines changed Original file line number Diff line number Diff line change @@ -10,24 +10,29 @@ function install(packages, currentState) {
1010 }
1111
1212 const installer = currentState . get ( 'installer' ) ;
13- const installGlobal = currentState . get ( 'global' ) ? '--global' : null ;
14- const saveExact = currentState . get ( 'saveExact' ) ? '--save-exact' : null ;
13+ const saveExact = currentState . get ( 'saveExact' )
14+
15+ const isYarn = installer === 'yarn' ;
16+ const exact = saveExact ? ( isYarn ? '--exact' : '--save-exact' ) : null ;
1517 const color = chalk . supportsColor ? '--color=always' : null ;
1618
17- const npmArgs = [ 'install' ]
18- . concat ( installGlobal )
19- . concat ( saveExact )
19+ const install = [ isYarn ? 'add' : 'install' ] ;
20+ if ( currentState . get ( 'global' ) ) {
21+ isYarn ? install . unshift ( 'global' ) : install . push ( '--global' ) ;
22+ }
23+ const args = install
2024 . concat ( packages )
25+ . concat ( exact )
2126 . concat ( color )
2227 . filter ( Boolean ) ;
2328
2429 console . log ( '' ) ;
25- console . log ( `$ ${ chalk . green ( installer ) } ${ chalk . green ( npmArgs . join ( ' ' ) ) } ` ) ;
30+ console . log ( `$ ${ chalk . green ( installer ) } ${ chalk . green ( args . join ( ' ' ) ) } ` ) ;
2631 const spinner = ora ( `Installing using ${ chalk . green ( installer ) } ...` ) ;
2732 spinner . enabled = spinner . enabled && currentState . get ( 'spinner' ) ;
2833 spinner . start ( ) ;
2934
30- return execa ( installer , npmArgs , { cwd : currentState . get ( 'cwd' ) } ) . then ( output => {
35+ return execa ( installer , args , { cwd : currentState . get ( 'cwd' ) } ) . then ( output => {
3136 spinner . stop ( ) ;
3237 console . log ( output . stdout ) ;
3338 console . log ( output . stderr ) ;
Original file line number Diff line number Diff line change @@ -145,13 +145,17 @@ function interactive(currentState) {
145145 const updatedPackages = packagesToUpdate
146146 . map ( pkg => pkg . moduleName + '@' + pkg . latest ) . join ( ', ' ) ;
147147
148+ const isYarn = currentState . get ( 'installer' ) === 'yarn' ;
149+
148150 if ( ! currentState . get ( 'global' ) ) {
149151 if ( saveDependencies . length ) {
150- saveDependencies . unshift ( '--save' ) ;
152+ ! isYarn && saveDependencies . push ( '--save' ) ;
151153 }
152154
153155 if ( saveDevDependencies . length ) {
154- saveDevDependencies . unshift ( '--save-dev' ) ;
156+ isYarn
157+ ? saveDevDependencies . push ( '--dev' )
158+ : saveDevDependencies . push ( '--save-dev' ) ;
155159 }
156160 }
157161
Original file line number Diff line number Diff line change @@ -14,8 +14,22 @@ function render(pkg, currentState) {
1414 const rows = [ ] ;
1515
1616 const indent = ' ' + emoji ( ' ' ) ;
17- const flags = currentState . get ( 'global' ) ? '--global' : `--save${ pkg . devDependency ? '-dev' : '' } ` ;
18- const upgradeCommand = `npm install ${ flags } ${ packageName } @${ pkg . latest } ` ;
17+ const installer = currentState . get ( 'installer' ) ;
18+ const isYarn = installer === 'yarn' ;
19+
20+ const args = [ isYarn ? 'add' : 'install' ] ;
21+ if ( currentState . get ( 'global' ) ) {
22+ isYarn ? args . unshift ( 'global' ) : args . push ( '--global' ) ;
23+ }
24+
25+ const flags = [ ] ;
26+ if ( isYarn ) {
27+ pkg . devDependency && flags . push ( '--dev' ) ;
28+ } else {
29+ pkg . devDependency ? flags . push ( '--save-dev' ) : flags . push ( '--save' ) ;
30+ }
31+
32+ const upgradeCommand = `${ installer } ${ args . join ( ' ' ) } ${ packageName } @${ pkg . latest } ${ flags . join ( ' ' ) } ` ;
1933 const upgradeMessage = `${ chalk . green ( upgradeCommand ) } to go from ${ pkg . installed } to ${ pkg . latest } ` ;
2034 // DYLAN: clean this up
2135 const status = _ ( [
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const _ = require ( 'lodash' ) ;
4- const inquirer = require ( 'inquirer' ) ;
53const chalk = require ( 'chalk' ) ;
6- const table = require ( 'text-table' ) ;
74const installPackages = require ( './install-packages' ) ;
85const emoji = require ( './emoji' ) ;
96
@@ -32,13 +29,17 @@ function updateAll(currentState) {
3229 const updatedPackages = packagesToUpdate
3330 . map ( pkg => pkg . moduleName + '@' + pkg . latest ) . join ( ', ' ) ;
3431
32+ const isYarn = currentState . get ( 'installer' ) === 'yarn' ;
33+
3534 if ( ! currentState . get ( 'global' ) ) {
3635 if ( saveDependencies . length ) {
37- saveDependencies . unshift ( '--save' ) ;
36+ ! isYarn && saveDependencies . push ( '--save' ) ;
3837 }
3938
4039 if ( saveDevDependencies . length ) {
41- saveDevDependencies . unshift ( '--save-dev' ) ;
40+ isYarn
41+ ? saveDevDependencies . push ( '--dev' )
42+ : saveDevDependencies . push ( '--save-dev' ) ;
4243 }
4344 }
4445
You can’t perform that action at this time.
0 commit comments