Skip to content

Commit bb3a9e5

Browse files
Timerromaindso
authored andcommitted
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
1 parent 9700ddb commit bb3a9e5

6 files changed

+84
-17
lines changed

bootstrap.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
3+
const { execSync, spawn } = require('child_process');
4+
const { resolve } = require('path');
5+
const { existsSync } = require('fs');
6+
const { platform } = require('os');
7+
8+
function shouldUseYarn() {
9+
try {
10+
execSync('yarnpkg --version', { stdio: 'ignore' });
11+
return true;
12+
} catch (e) {
13+
return false;
14+
}
15+
}
16+
17+
function shouldUseNpmConcurrently() {
18+
try {
19+
const versionString = execSync('npm --version');
20+
const m = /^(\d+)[.]/.exec(versionString);
21+
// NPM >= 5 support concurrent installs
22+
return Number(m[1]) >= 5;
23+
} catch (e) {
24+
return false;
25+
}
26+
}
27+
28+
const yarn = shouldUseYarn();
29+
const windows = platform() === 'win32';
30+
const lerna = resolve(
31+
__dirname,
32+
'node_modules',
33+
'.bin',
34+
windows ? 'lerna.cmd' : 'lerna'
35+
);
36+
37+
if (!existsSync(lerna)) {
38+
if (yarn) {
39+
console.log('Cannot find lerna. Please run `yarn --check-files`.');
40+
} else {
41+
console.log(
42+
'Cannot find lerna. Please remove `node_modules` and run `npm install`.'
43+
);
44+
}
45+
process.exit(1);
46+
}
47+
48+
let child;
49+
if (yarn) {
50+
// Yarn does not support concurrency
51+
child = spawn(lerna, ['bootstrap', '--npm-client=yarn', '--concurrency=1'], {
52+
stdio: 'inherit',
53+
});
54+
} else {
55+
let args = ['bootstrap'];
56+
if (
57+
// The Windows filesystem does not handle concurrency well
58+
windows ||
59+
// Only newer npm versions support concurrency
60+
!shouldUseNpmConcurrently()
61+
) {
62+
args.push('--concurrency=1');
63+
}
64+
child = spawn(lerna, args, { stdio: 'inherit' });
65+
}
66+
67+
child.on('close', code => process.exit(code));

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "2.0.0-beta.38",
2+
"lerna": "2.0.0-rc.5",
33
"version": "independent",
44
"changelog": {
55
"repo": "facebookincubator/create-react-app",

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"create-react-app": "tasks/cra.sh",
77
"e2e": "tasks/e2e-simple.sh",
88
"e2e:docker": "tasks/local-test.sh",
9-
"postinstall": "lerna bootstrap && cd packages/react-error-overlay/ && npm run build:prod",
9+
"postinstall": "node bootstrap.js && cd packages/react-error-overlay/ && npm run build:prod",
1010
"publish": "tasks/release.sh",
1111
"start": "node packages/react-scripts/scripts/start.js",
1212
"test": "node packages/react-scripts/scripts/test.js --env=jsdom",
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"eslint": "3.19.0",
1818
"husky": "^0.13.2",
19-
"lerna": "2.0.0-beta.38",
19+
"lerna": "2.0.0-rc.5",
2020
"lerna-changelog": "^0.2.3",
2121
"lint-staged": "^3.3.1",
2222
"prettier": "^1.5.2"

tasks/e2e-installs.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ then
8080
# AppVeyor uses an old version of yarn.
8181
# Once updated to 0.24.3 or above, the workaround can be removed
8282
# and replaced with `yarnpkg cache clean`
83-
# Issues:
83+
# Issues:
8484
# https://github.com/yarnpkg/yarn/issues/2591
8585
# https://github.com/appveyor/ci/issues/1576
8686
# https://github.com/facebookincubator/create-react-app/pull/2400
@@ -102,9 +102,9 @@ then
102102
npm cache clean || npm cache verify
103103
fi
104104

105-
# Prevent lerna bootstrap, we only want top-level dependencies
105+
# Prevent bootstrap, we only want top-level dependencies
106106
cp package.json package.json.bak
107-
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
107+
grep -v "postinstall" package.json > temp && mv temp package.json
108108
npm install
109109
mv package.json.bak package.json
110110

@@ -116,7 +116,7 @@ then
116116
fi
117117

118118
# We removed the postinstall, so do it manually
119-
./node_modules/.bin/lerna bootstrap --concurrency=1
119+
node bootstrap.js
120120

121121
cd packages/react-error-overlay/
122122
npm run build:prod

tasks/e2e-kitchensink.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ then
7272
# AppVeyor uses an old version of yarn.
7373
# Once updated to 0.24.3 or above, the workaround can be removed
7474
# and replaced with `yarnpkg cache clean`
75-
# Issues:
75+
# Issues:
7676
# https://github.com/yarnpkg/yarn/issues/2591
7777
# https://github.com/appveyor/ci/issues/1576
7878
# https://github.com/facebookincubator/create-react-app/pull/2400
@@ -94,9 +94,9 @@ then
9494
npm cache clean || npm cache verify
9595
fi
9696

97-
# Prevent lerna bootstrap, we only want top-level dependencies
97+
# Prevent bootstrap, we only want top-level dependencies
9898
cp package.json package.json.bak
99-
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
99+
grep -v "postinstall" package.json > temp && mv temp package.json
100100
npm install
101101
mv package.json.bak package.json
102102

@@ -108,7 +108,7 @@ then
108108
fi
109109

110110
# We removed the postinstall, so do it manually
111-
./node_modules/.bin/lerna bootstrap --concurrency=1
111+
node bootstrap.js
112112

113113
cd packages/react-error-overlay/
114114
npm run build:prod

tasks/e2e-simple.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ then
7171
# AppVeyor uses an old version of yarn.
7272
# Once updated to 0.24.3 or above, the workaround can be removed
7373
# and replaced with `yarnpkg cache clean`
74-
# Issues:
74+
# Issues:
7575
# https://github.com/yarnpkg/yarn/issues/2591
7676
# https://github.com/appveyor/ci/issues/1576
7777
# https://github.com/facebookincubator/create-react-app/pull/2400
@@ -93,9 +93,9 @@ then
9393
npm cache clean || npm cache verify
9494
fi
9595

96-
# Prevent lerna bootstrap, we only want top-level dependencies
96+
# Prevent bootstrap, we only want top-level dependencies
9797
cp package.json package.json.bak
98-
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
98+
grep -v "postinstall" package.json > temp && mv temp package.json
9999
npm install
100100
mv package.json.bak package.json
101101

@@ -115,16 +115,16 @@ then
115115
[[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1
116116
fi
117117

118-
# We removed the postinstall, so do it manually here
119-
./node_modules/.bin/lerna bootstrap --concurrency=1
120-
121118
if [ "$USE_YARN" = "yes" ]
122119
then
123120
# Install Yarn so that the test can use it to install packages.
124121
npm install -g yarn
125122
yarn cache clean
126123
fi
127124

125+
# We removed the postinstall, so do it manually here
126+
node bootstrap.js
127+
128128
# Lint own code
129129
./node_modules/.bin/eslint --max-warnings 0 packages/babel-preset-react-app/
130130
./node_modules/.bin/eslint --max-warnings 0 packages/create-react-app/

0 commit comments

Comments
 (0)