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
This commit is contained in:
Dan Abramov
2018-01-12 01:54:53 +00:00
committed by GitHub
parent 3f7851deab
commit 0aeffe62ef
12 changed files with 65 additions and 107 deletions

1
.yarnrc Normal file
View File

@@ -0,0 +1 @@
--install.no-lockfile true

View File

@@ -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 its 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`. (Dont forget the `run` there.)
8. Wait for a long time, and it will get published. Dont worry that its 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.

67
bootstrap.js vendored
View File

@@ -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));

View File

@@ -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/*"
]
}
}

View File

@@ -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",

View File

@@ -1,9 +1,15 @@
[ignore]
.*/node_modules/eslint-plugin-jsx-a11y/.*
[include]
src/**/*.js
<PROJECT_ROOT>/src/**/*.js
[ignore]
.*/node_modules/.*
.*/.git/.*
.*/__test__/.*
.*/fixtures/.*
[libs]
flow/
[options]
module.file_ext=.js
sharedmemory.hash_table_pow=19

View File

@@ -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;
}

View File

@@ -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"
},

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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 "$@"