Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap with Yarn #2673

Merged
merged 6 commits into from
Jun 29, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check OS and npm concurrency ability
  • Loading branch information
Timer committed Jun 28, 2017
commit a69ede5c1be7703ebb2e6c7977beb547124267cc
26 changes: 24 additions & 2 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { execSync, spawn } = require('child_process');
const { resolve } = require('path');
const { existsSync } = require('fs');
const { platform } = require('os');

function shouldUseYarn() {
try {
Expand All @@ -13,6 +14,17 @@ function shouldUseYarn() {
}
}

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 lerna = resolve(__dirname, 'node_modules', '.bin', 'lerna');
if (!existsSync(lerna)) {
Expand All @@ -28,11 +40,21 @@ if (!existsSync(lerna)) {

let child;
if (yarn) {
child = spawn(lerna, ['bootstrap', '--npm-client=yarn'], {
// Yarn does not support concurrency
child = spawn(lerna, ['bootstrap', '--npm-client=yarn', '--concurrency=1'], {
stdio: 'inherit',
});
} else {
child = spawn(lerna, ['bootstrap'], { stdio: 'inherit' });
let args = ['bootstrap'];
if (
// The Window's filesystem does not handle concurrency well
platform() === 'win32' ||
// Only certain npm versions support concurrency
!shouldUseNpmConcurrently()
) {
args.push('--concurrency=1');
}
child = spawn(lerna, args, { stdio: 'inherit' });
}

child.on('close', code => process.exit(code));