mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
* Bootstrap with Yarn if we can * Update test scripts * Check OS and npm concurrency ability * Windows support * Update bootstrap.js * Install yarn before bootstrap
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
'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));
|