From 80f6479d94f74f5b9c6608e7c4af2d5117a2adbd Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 12 Jan 2018 01:54:53 +0000 Subject: [PATCH] Switch to Yarn Workspaces (#3755) * Switch to Yarn Workspaces * Feedback * Move flowconfig * Use publish script * Keep git status check * Fix Flow without perf penalty * Remove Flow from package.json "test" * Try running it from script directly (?) * Try magic incantations * lol flow COME ON * Try to skip Flow on AppVeyor * -df * -df * -df * Try to fix CI * Revert unrelated changes * Update CONTRIBUTING.md --- .yarnrc | 1 + CONTRIBUTING.md | 18 +++--- bootstrap.js | 67 ----------------------- lerna.json | 9 ++- package.json | 15 +++-- packages/react-error-overlay/.flowconfig | 14 +++-- packages/react-error-overlay/flow/env.js | 19 +++++++ packages/react-error-overlay/package.json | 2 +- tasks/e2e-installs.sh | 4 +- tasks/e2e-kitchensink.sh | 4 +- tasks/e2e-simple.sh | 10 +++- tasks/{release.sh => publish.sh} | 9 +-- 12 files changed, 65 insertions(+), 107 deletions(-) create mode 100644 .yarnrc delete mode 100644 bootstrap.js create mode 100644 packages/react-error-overlay/flow/env.js rename tasks/{release.sh => publish.sh} (84%) diff --git a/.yarnrc b/.yarnrc new file mode 100644 index 00000000000..acaaffdb73e --- /dev/null +++ b/.yarnrc @@ -0,0 +1 @@ +--install.no-lockfile true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8957c0c3de6..62908c39b6b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -75,20 +75,18 @@ All functionality must be retained (and configuration given to the user) if they 1. Clone the repo with `git clone https://github.com/facebookincubator/create-react-app` -2. Run `npm install` in the root `create-react-app` folder. +2. Run `yarn` in the root `create-react-app` folder. -Once it is done, you can modify any file locally and run `npm start`, `npm test` or `npm run build` just like in a generated project. +Once it is done, you can modify any file locally and run `yarn start`, `yarn test` or `yarn build` just like in a generated project. If you want to try out the end-to-end flow with the global CLI, you can do this too: ``` -npm run create-react-app my-app +yarn create-react-app my-app cd my-app ``` -and then run `npm start` or `npm run build`. - -*Note: if you are using yarn, we suggest that you use `yarn install --no-lockfile` instead of the bare `yarn` or `yarn install` because we [intentionally](https://github.com/facebookincubator/create-react-app/pull/2014#issuecomment-300811661) do not ignore or add yarn.lock to our repo.* +and then run `yarn start` or `yarn build`. ## Contributing to E2E (end to end) tests @@ -104,8 +102,8 @@ The scripts in tasks folder and other scripts in `package.json` will not work in A good step by step guide can be found [here](https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/) -### Install Node.js and npm -Even if you have node and npm installed on your windows, it would not be accessible from the bash shell. You would have to install it again. Installing via [`nvm`](https://github.com/creationix/nvm#install-script) is recommended. +### Install Node.js and yarn +Even if you have node and yarn installed on your windows, it would not be accessible from the bash shell. You would have to install it again. Installing via [`nvm`](https://github.com/creationix/nvm#install-script) is recommended. ### Line endings @@ -119,11 +117,11 @@ By default git would use `CRLF` line endings which would cause the scripts to fa 4. Note that files in `packages/create-react-app` should be modified with extreme caution. Since it’s a global CLI, any version of `create-react-app` (global CLI) including very old ones should work with the latest version of `react-scripts`. 5. Create a change log entry for the release: * You'll need an [access token for the GitHub API](https://help.github.com/articles/creating-an-access-token-for-command-line-use/). Save it to this environment variable: `export GITHUB_AUTH="..."` - * Run `npm run changelog`. The command will find all the labeled pull requests merged since the last release and group them by the label and affected packages, and create a change log entry with all the changes and links to PRs and their authors. Copy and paste it to `CHANGELOG.md`. + * Run `yarn changelog`. The command will find all the labeled pull requests merged since the last release and group them by the label and affected packages, and create a change log entry with all the changes and links to PRs and their authors. Copy and paste it to `CHANGELOG.md`. * Add a four-space indented paragraph after each non-trivial list item, explaining what changed and why. For each breaking change also write who it affects and instructions for migrating existing code. * Maybe add some newlines here and there. Preview the result on GitHub to get a feel for it. Changelog generator output is a bit too terse for my taste, so try to make it visually pleasing and well grouped. 6. Make sure to include “Migrating from ...” instructions for the previous release. Often you can copy and paste them. -7. **Do not run `npm publish`. Instead, run `npm run publish`.** +7. Run `yarn run publish`. (Don’t forget the `run` there.) 8. Wait for a long time, and it will get published. Don’t worry that it’s stuck. In the end the publish script will prompt for versions before publishing the packages. 9. After publishing, create a GitHub Release with the same text as the changelog entry. See previous Releases for inspiration. diff --git a/bootstrap.js b/bootstrap.js deleted file mode 100644 index b54a1ed9f36..00000000000 --- a/bootstrap.js +++ /dev/null @@ -1,67 +0,0 @@ -'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)); diff --git a/lerna.json b/lerna.json index 1673f8a3187..f1d78d84bae 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,7 @@ { - "lerna": "2.0.0", + "lerna": "2.6.0", + "npmClient": "yarn", + "useWorkspaces": true, "version": "independent", "changelog": { "repo": "facebookincubator/create-react-app", @@ -12,8 +14,5 @@ "tag: internal": ":house: Internal" }, "cacheDir": ".changelog" - }, - "packages": [ - "packages/*" - ] + } } diff --git a/package.json b/package.json index 9cf2f50f14f..15f463a10d5 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,26 @@ { "private": true, + "workspaces": [ + "packages/*" + ], "scripts": { - "build": "node packages/react-scripts/scripts/build.js", + "build": "cd packages/react-scripts && node scripts/build.js", "changelog": "lerna-changelog", "create-react-app": "node tasks/cra.js", "e2e": "tasks/e2e-simple.sh", "e2e:docker": "tasks/local-test.sh", - "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", + "postinstall": "cd packages/react-error-overlay/ && yarn build:prod", + "publish": "tasks/publish.sh", + "start": "cd packages/react-scripts && node scripts/start.js", "screencast": "svg-term --cast hItN7sl5yfCPTHxvFg5glhhfp --out screencast.svg --window", - "test": "node packages/react-scripts/scripts/test.js --env=jsdom", + "test": "cd packages/react-scripts && node scripts/test.js --env=jsdom", "format": "prettier --trailing-comma es5 --single-quote --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'", "precommit": "lint-staged" }, "devDependencies": { "eslint": "^4.4.1", "husky": "^0.13.2", - "lerna": "^2.0.0", + "lerna": "^2.6.0", "lerna-changelog": "^0.6.0", "lint-staged": "^3.3.1", "prettier": "1.6.1", diff --git a/packages/react-error-overlay/.flowconfig b/packages/react-error-overlay/.flowconfig index 8d7de784e29..c976167c2a9 100644 --- a/packages/react-error-overlay/.flowconfig +++ b/packages/react-error-overlay/.flowconfig @@ -1,9 +1,15 @@ -[ignore] -.*/node_modules/eslint-plugin-jsx-a11y/.* - [include] -src/**/*.js +/src/**/*.js + +[ignore] +.*/node_modules/.* +.*/.git/.* +.*/__test__/.* +.*/fixtures/.* [libs] +flow/ [options] +module.file_ext=.js +sharedmemory.hash_table_pow=19 diff --git a/packages/react-error-overlay/flow/env.js b/packages/react-error-overlay/flow/env.js new file mode 100644 index 00000000000..12b151f5e4b --- /dev/null +++ b/packages/react-error-overlay/flow/env.js @@ -0,0 +1,19 @@ +declare module 'anser' { + declare module.exports: any; +} + +declare module 'babel-code-frame' { + declare module.exports: any; +} + +declare module 'html-entities' { + declare module.exports: any; +} + +declare module 'settle-promise' { + declare module.exports: any; +} + +declare module 'source-map' { + declare module.exports: any; +} diff --git a/packages/react-error-overlay/package.json b/packages/react-error-overlay/package.json index f2148885c1f..9808a9da81d 100644 --- a/packages/react-error-overlay/package.json +++ b/packages/react-error-overlay/package.json @@ -6,7 +6,7 @@ "scripts": { "prepublishOnly": "npm run build:prod && npm test", "start": "cross-env NODE_ENV=development node build.js --watch", - "test": "flow && cross-env NODE_ENV=test jest", + "test": "cross-env NODE_ENV=test jest", "build": "cross-env NODE_ENV=development node build.js", "build:prod": "cross-env NODE_ENV=production node build.js" }, diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index 9d7a0e99daa..bcd616f3601 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -99,8 +99,8 @@ yarn config set registry "$custom_registry_url" npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_registry_url" --quotes # Publish the monorepo -git clean -f -./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest +git clean -df +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest # ****************************************************************************** # Test --scripts-version with a version number diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index 9dc2370dafc..d73c45ddbfa 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -91,8 +91,8 @@ yarn config set registry "$custom_registry_url" npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_registry_url" --quotes # Publish the monorepo -git clean -f -./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest +git clean -df +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest # ****************************************************************************** # Now that we have published them, create a clean app folder and install them. diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 98941f25661..b566ae37a3d 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -107,6 +107,12 @@ npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_reg cd packages/react-error-overlay/ ./node_modules/.bin/eslint --max-warnings 0 src/ yarn test + +if [ $APPVEYOR != 'True' ]; then + # Flow started hanging on AppVeyor after we moved to Yarn Workspaces :-( + yarn flow +fi + cd ../.. cd packages/react-dev-utils/ yarn test @@ -134,8 +140,8 @@ CI=true yarn test # Test local start command yarn start --smoke-test -git clean -f -./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest +git clean -df +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest # ****************************************************************************** # Install react-scripts prerelease via create-react-app prerelease. diff --git a/tasks/release.sh b/tasks/publish.sh similarity index 84% rename from tasks/release.sh rename to tasks/publish.sh index 0f11bb0d60c..c1cae86c200 100755 --- a/tasks/release.sh +++ b/tasks/publish.sh @@ -26,21 +26,14 @@ set -x cd .. root_path=$PWD -# You can only release with npm >= 3 -if [ $(npm -v | head -c 1) -lt 3 ]; then - echo "Releasing requires npm >= 3. Aborting."; - exit 1; -fi; - if [ -n "$(git status --porcelain)" ]; then echo "Your git status is not clean. Aborting."; exit 1; fi -cd "$root_path" # Compile cd packages/react-error-overlay/ npm run build:prod cd ../.. # Go! -./node_modules/.bin/lerna publish --independent "$@" +./node_modules/.bin/lerna publish --independent "$@" \ No newline at end of file