forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bootstrap with Yarn when available (facebook#2673)
* Bootstrap with Yarn if we can * Update test scripts * Check OS and npm concurrency ability * Windows support * Update bootstrap.js * Install yarn before bootstrap
- Loading branch information
Showing
6 changed files
with
84 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
|
||
const { execSync, spawn } = require('child_process'); | ||
const { resolve } = require('path'); | ||
const { existsSync } = require('fs'); | ||
const { platform } = require('os'); | ||
|
||
function shouldUseYarn() { | ||
try { | ||
execSync('yarnpkg --version', { stdio: 'ignore' }); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
function shouldUseNpmConcurrently() { | ||
try { | ||
const versionString = execSync('npm --version'); | ||
const m = /^(\d+)[.]/.exec(versionString); | ||
// NPM >= 5 support concurrent installs | ||
return Number(m[1]) >= 5; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
const yarn = shouldUseYarn(); | ||
const windows = platform() === 'win32'; | ||
const lerna = resolve( | ||
__dirname, | ||
'node_modules', | ||
'.bin', | ||
windows ? 'lerna.cmd' : 'lerna' | ||
); | ||
|
||
if (!existsSync(lerna)) { | ||
if (yarn) { | ||
console.log('Cannot find lerna. Please run `yarn --check-files`.'); | ||
} else { | ||
console.log( | ||
'Cannot find lerna. Please remove `node_modules` and run `npm install`.' | ||
); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
let child; | ||
if (yarn) { | ||
// Yarn does not support concurrency | ||
child = spawn(lerna, ['bootstrap', '--npm-client=yarn', '--concurrency=1'], { | ||
stdio: 'inherit', | ||
}); | ||
} else { | ||
let args = ['bootstrap']; | ||
if ( | ||
// The Windows filesystem does not handle concurrency well | ||
windows || | ||
// Only newer npm versions support concurrency | ||
!shouldUseNpmConcurrently() | ||
) { | ||
args.push('--concurrency=1'); | ||
} | ||
child = spawn(lerna, args, { stdio: 'inherit' }); | ||
} | ||
|
||
child.on('close', code => process.exit(code)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters