@@ -5,6 +5,7 @@ const glob = require('glob');
5
5
const path = require ( 'path' ) ;
6
6
const chalk = require ( 'chalk' ) ;
7
7
const EventEmitter = require ( 'events' ) . EventEmitter ;
8
+ const hasYarn = require ( 'has-yarn' ) ;
8
9
9
10
/**
10
11
* @name log
@@ -95,13 +96,16 @@ const copyWithPattern = (cwd, pattern, dest) => wrapAsync(function*() {
95
96
* @param {string } [url] - A URL which will be used to fetch the package from
96
97
*/
97
98
const fetchPackage = ( packageName , url ) => wrapAsync ( function * ( ) {
99
+ const useYarn = hasYarn ( ) ;
100
+ const pm = useYarn ? 'yarn' : 'npm' ;
101
+ const installCmd = useYarn ? 'add' : 'install' ;
98
102
try {
99
103
if ( packageName || url ) {
100
- const cmd = yield spawn ( 'npm' , [ 'install' , url || packageName ] ) ;
104
+ const cmd = yield spawn ( pm , [ installCmd , url || packageName ] ) ;
101
105
error ( cmd . stderr ) ;
102
106
}
103
107
} 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 } ` ) ;
105
109
throw err ; // Rethrow error
106
110
}
107
111
} ) ;
@@ -118,7 +122,7 @@ const checkAndInstallPackage = (packageName, url) => wrapAsync(function*() {
118
122
require . resolve ( packageName ) ;
119
123
return true ;
120
124
} catch ( err ) {
121
- debug ( `patternlab→ checkAndInstallPackage: ${ packageName } not installed. Fetching it now from NPM …` ) ;
125
+ debug ( `checkAndInstallPackage: ${ packageName } not installed. Fetching it now …` ) ;
122
126
yield fetchPackage ( packageName , url ) ;
123
127
return false ;
124
128
}
0 commit comments