From 3917b55d08d8531f0c68fae6f7e3011d68508af6 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 28 Jun 2017 17:31:56 -0400 Subject: [PATCH 1/6] Bootstrap with Yarn if we can --- bootstrap.js | 38 ++++++++++++++++++++++++++++++++++++++ lerna.json | 2 +- package.json | 4 ++-- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 bootstrap.js diff --git a/bootstrap.js b/bootstrap.js new file mode 100644 index 00000000000..de26993e87a --- /dev/null +++ b/bootstrap.js @@ -0,0 +1,38 @@ +'use strict'; + +const { execSync, spawn } = require('child_process'); +const { resolve } = require('path'); +const { existsSync } = require('fs'); + +function shouldUseYarn() { + try { + execSync('yarnpkg --version', { stdio: 'ignore' }); + return true; + } catch (e) { + return false; + } +} + +const yarn = shouldUseYarn(); +const lerna = resolve(__dirname, 'node_modules', '.bin', '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) { + child = spawn(lerna, ['bootstrap', '--npm-client=yarn'], { + stdio: 'inherit', + }); +} else { + child = spawn(lerna, ['bootstrap'], { stdio: 'inherit' }); +} + +child.on('close', code => process.exit(code)); diff --git a/lerna.json b/lerna.json index e2429777df4..7ca916a8569 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "lerna": "2.0.0-beta.38", + "lerna": "2.0.0-rc.5", "version": "independent", "changelog": { "repo": "facebookincubator/create-react-app", diff --git a/package.json b/package.json index 0cef9dc029e..b9abb1ce865 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" From bd13800a9939aff9404ba53e965267fc0a7513f5 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 28 Jun 2017 17:35:02 -0400 Subject: [PATCH 2/6] Update test scripts --- tasks/e2e-installs.sh | 8 ++++---- tasks/e2e-kitchensink.sh | 8 ++++---- tasks/e2e-simple.sh | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index 7ea70fac6c3..67f4f2ad584 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -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 @@ -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 @@ -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 diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index fcd687e4b0d..ea2da27c384 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -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 @@ -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 @@ -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 diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 163bec0818a..02af79d8413 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -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 @@ -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 @@ -112,7 +112,7 @@ then fi # We removed the postinstall, so do it manually here -./node_modules/.bin/lerna bootstrap --concurrency=1 +node bootstrap.js if [ "$USE_YARN" = "yes" ] then From a69ede5c1be7703ebb2e6c7977beb547124267cc Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 28 Jun 2017 17:48:28 -0400 Subject: [PATCH 3/6] Check OS and npm concurrency ability --- bootstrap.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index de26993e87a..6bb168e9614 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -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 { @@ -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)) { @@ -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)); From 5265339286b661dbbbaee8e40da52ea0a14b6b5d Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 28 Jun 2017 17:52:08 -0400 Subject: [PATCH 4/6] Windows support --- bootstrap.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 6bb168e9614..b4e7d874eaa 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -26,7 +26,14 @@ function shouldUseNpmConcurrently() { } const yarn = shouldUseYarn(); -const lerna = resolve(__dirname, 'node_modules', '.bin', 'lerna'); +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`.'); @@ -48,7 +55,7 @@ if (yarn) { let args = ['bootstrap']; if ( // The Window's filesystem does not handle concurrency well - platform() === 'win32' || + windows || // Only certain npm versions support concurrency !shouldUseNpmConcurrently() ) { From e876b7d1f4a19cd970196e31463598cdca0a154e Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 28 Jun 2017 17:57:53 -0400 Subject: [PATCH 5/6] Update bootstrap.js --- bootstrap.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index b4e7d874eaa..b54a1ed9f36 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -54,9 +54,9 @@ if (yarn) { } else { let args = ['bootstrap']; if ( - // The Window's filesystem does not handle concurrency well + // The Windows filesystem does not handle concurrency well windows || - // Only certain npm versions support concurrency + // Only newer npm versions support concurrency !shouldUseNpmConcurrently() ) { args.push('--concurrency=1'); From 4b6dde79f8b4cb69039fdfd903236c62e7083c43 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 28 Jun 2017 23:48:56 -0400 Subject: [PATCH 6/6] Install yarn before bootstrap --- tasks/e2e-simple.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 02af79d8413..5ac040c696b 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -111,9 +111,6 @@ then [[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1 fi -# We removed the postinstall, so do it manually here -node bootstrap.js - if [ "$USE_YARN" = "yes" ] then # Install Yarn so that the test can use it to install packages. @@ -121,6 +118,9 @@ then 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/