@@ -5,6 +5,7 @@ const glob = require('glob');
55const path = require ( 'path' ) ;
66const chalk = require ( 'chalk' ) ;
77const EventEmitter = require ( 'events' ) . EventEmitter ;
8+ const hasYarn = require ( 'has-yarn' ) ;
89
910/**
1011 * @name log
@@ -95,13 +96,16 @@ const copyWithPattern = (cwd, pattern, dest) => wrapAsync(function*() {
9596 * @param {string } [url] - A URL which will be used to fetch the package from
9697 */
9798const fetchPackage = ( packageName , url ) => wrapAsync ( function * ( ) {
99+ const useYarn = hasYarn ( ) ;
100+ const pm = useYarn ? 'yarn' : 'npm' ;
101+ const installCmd = useYarn ? 'add' : 'install' ;
98102 try {
99103 if ( packageName || url ) {
100- const cmd = yield spawn ( 'npm' , [ 'install' , url || packageName ] ) ;
104+ const cmd = yield spawn ( pm , [ installCmd , url || packageName ] ) ;
101105 error ( cmd . stderr ) ;
102106 }
103107 } catch ( err ) {
104- error ( `patternlab→ fetchPackage: Fetching required dependencies from NPM failed for ${ packageName } with ${ err } ` ) ;
108+ error ( `fetchPackage: Fetching required dependencies from ${ pm } failed for ${ packageName } with ${ err } ` ) ;
105109 throw err ; // Rethrow error
106110 }
107111} ) ;
@@ -118,7 +122,7 @@ const checkAndInstallPackage = (packageName, url) => wrapAsync(function*() {
118122 require . resolve ( packageName ) ;
119123 return true ;
120124 } catch ( err ) {
121- debug ( `patternlab→ checkAndInstallPackage: ${ packageName } not installed. Fetching it now from NPM …` ) ;
125+ debug ( `checkAndInstallPackage: ${ packageName } not installed. Fetching it now …` ) ;
122126 yield fetchPackage ( packageName , url ) ;
123127 return false ;
124128 }
0 commit comments