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
Show file tree
Hide file tree
Changes from all commits
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
67 changes: 67 additions & 0 deletions bootstrap.js
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));
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "2.0.0-beta.38",
"lerna": "2.0.0-rc.5",
"version": "independent",
"changelog": {
"repo": "facebookincubator/create-react-app",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"create-react-app": "tasks/cra.sh",
"e2e": "tasks/e2e-simple.sh",
"e2e:docker": "tasks/local-test.sh",
"postinstall": "lerna bootstrap && cd packages/react-error-overlay/ && npm run build:prod",
"postinstall": "node bootstrap.js && cd packages/react-error-overlay/ && npm run build:prod",
"publish": "tasks/release.sh",
"start": "node packages/react-scripts/scripts/start.js",
"test": "node packages/react-scripts/scripts/test.js --env=jsdom",
Expand All @@ -16,7 +16,7 @@
"devDependencies": {
"eslint": "3.19.0",
"husky": "^0.13.2",
"lerna": "2.0.0-beta.38",
"lerna": "2.0.0-rc.5",
"lerna-changelog": "^0.2.3",
"lint-staged": "^3.3.1",
"prettier": "^1.5.2"
Expand Down
8 changes: 4 additions & 4 deletions tasks/e2e-installs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ then
# AppVeyor uses an old version of yarn.
# Once updated to 0.24.3 or above, the workaround can be removed
# and replaced with `yarnpkg cache clean`
# Issues:
# Issues:
# https://github.com/yarnpkg/yarn/issues/2591
# https://github.com/appveyor/ci/issues/1576
# https://github.com/facebookincubator/create-react-app/pull/2400
Expand All @@ -98,9 +98,9 @@ then
npm cache clean
fi

# Prevent lerna bootstrap, we only want top-level dependencies
# Prevent bootstrap, we only want top-level dependencies
cp package.json package.json.bak
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
grep -v "postinstall" package.json > temp && mv temp package.json
npm install
mv package.json.bak package.json

Expand All @@ -112,7 +112,7 @@ then
fi

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

cd packages/react-error-overlay/
npm run build:prod
Expand Down
8 changes: 4 additions & 4 deletions tasks/e2e-kitchensink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ then
# AppVeyor uses an old version of yarn.
# Once updated to 0.24.3 or above, the workaround can be removed
# and replaced with `yarnpkg cache clean`
# Issues:
# Issues:
# https://github.com/yarnpkg/yarn/issues/2591
# https://github.com/appveyor/ci/issues/1576
# https://github.com/facebookincubator/create-react-app/pull/2400
Expand All @@ -90,9 +90,9 @@ then
npm cache clean
fi

# Prevent lerna bootstrap, we only want top-level dependencies
# Prevent bootstrap, we only want top-level dependencies
cp package.json package.json.bak
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
grep -v "postinstall" package.json > temp && mv temp package.json
npm install
mv package.json.bak package.json

Expand All @@ -104,7 +104,7 @@ then
fi

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

cd packages/react-error-overlay/
npm run build:prod
Expand Down
12 changes: 6 additions & 6 deletions tasks/e2e-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ then
# AppVeyor uses an old version of yarn.
# Once updated to 0.24.3 or above, the workaround can be removed
# and replaced with `yarnpkg cache clean`
# Issues:
# Issues:
# https://github.com/yarnpkg/yarn/issues/2591
# https://github.com/appveyor/ci/issues/1576
# https://github.com/facebookincubator/create-react-app/pull/2400
Expand All @@ -89,9 +89,9 @@ then
npm cache clean
fi

# Prevent lerna bootstrap, we only want top-level dependencies
# Prevent bootstrap, we only want top-level dependencies
cp package.json package.json.bak
grep -v "lerna bootstrap" package.json > temp && mv temp package.json
grep -v "postinstall" package.json > temp && mv temp package.json
npm install
mv package.json.bak package.json

Expand All @@ -111,16 +111,16 @@ then
[[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1
fi

# We removed the postinstall, so do it manually here
./node_modules/.bin/lerna bootstrap --concurrency=1

if [ "$USE_YARN" = "yes" ]
then
# Install Yarn so that the test can use it to install packages.
npm install -g yarn
yarn cache clean
fi

# We removed the postinstall, so do it manually here
node bootstrap.js

# Lint own code
./node_modules/.bin/eslint --max-warnings 0 packages/babel-preset-react-app/
./node_modules/.bin/eslint --max-warnings 0 packages/create-react-app/
Expand Down