Skip to content

Commit

Permalink
Use Yarn to install packages by default (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
donysukardi authored and KyleAMathews committed Apr 11, 2017
1 parent a034e91 commit 1fbc633
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/gatsby/lib/utils/init-starter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
/* @flow weak */
import { exec } from "child_process"
import { exec, execSync } from "child_process"
import fs from "fs-extra"
import sysPath from "path"

let logger = console

// Checks the existence of yarn package
// We use yarnpkg instead of yarn to avoid conflict with Hadoop yarn
// Refer to https://github.com/yarnpkg/yarn/issues/673
//
// Returns true if yarn exists, false otherwise
const shouldUseYarn = () => {
try {
execSync(`yarnpkg --version`, { stdio: `ignore` })
return true
} catch (e) {
return false
}
}

// Executes `npm install` and `bower install` in rootPath.
//
// rootPath - String. Path to directory in which command will be executed.
Expand All @@ -15,7 +29,7 @@ const install = (rootPath, callback) => {
const prevDir = process.cwd()
logger.log(`Installing packages...`)
process.chdir(rootPath)
const installCmd = `npm install`
const installCmd = shouldUseYarn ? `yarnpkg` : `npm install`
exec(installCmd, (error, stdout, stderr) => {
process.chdir(prevDir)
if (stdout) console.log(stdout.toString())
Expand Down

0 comments on commit 1fbc633

Please sign in to comment.