From 7253e6544b4409841c1527c744f2f08c9ab867ba Mon Sep 17 00:00:00 2001 From: Jamison Dance Date: Wed, 15 Mar 2017 18:20:57 -0600 Subject: [PATCH 1/8] Add React Rally to conferences list (#9179) --- docs/community/conferences.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/community/conferences.md b/docs/community/conferences.md index 1d81d854b1..91b2146567 100644 --- a/docs/community/conferences.md +++ b/docs/community/conferences.md @@ -34,6 +34,10 @@ July 10-11 in Portland, Oregon USA [Website](https://infinite.red/ChainReactConf) - [Twitter](https://twitter.com/chainreactconf) +### React Rally +August 24-25 in Salt Lake City, Utah USA +[Website](http://www.reactrally.com) - [Twitter](https://twitter.com/reactrally) + ### ReactJS Day 2017 October 6th in Verona, Italy From f365e52dd7946d6eeff927623b13b68ec2468583 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 15 Mar 2017 14:20:08 -0700 Subject: [PATCH 2/8] Add prettier script `scripts/prettier/index.js write` will run prettier on source files. Run using `yarn prettier`. `scripts/prettier/index.js` will throw if any source files are not formatted with prettier. We'll use this to block CI. Based on similar script in Jest repo. --- package.json | 3 +- scripts/prettier/index.js | 70 ++++++++++++++++++++++++++++++++++ scripts/prettier/runCommand.js | 40 +++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 scripts/prettier/index.js create mode 100644 scripts/prettier/runCommand.js diff --git a/package.json b/package.json index 3f5070440d..094946a201 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "babylon": "6.15.0", "browserify": "^13.0.0", "bundle-collapser": "^1.1.1", + "chalk": "^1.1.3", "coffee-script": "^1.8.0", "core-js": "^2.2.1", "coveralls": "^2.11.6", @@ -94,7 +95,7 @@ "postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json", "test": "jest", "flow": "flow", - "prettier": "prettier --write --no-bracket-spacing --single-quote --jsx-bracket-same-line --trailing-comma all --print-width 80 \"src/**/!(third_party)/*.js\"" + "prettier": "node ./scripts/prettier/index.js write" }, "jest": { "modulePathIgnorePatterns": [ diff --git a/scripts/prettier/index.js b/scripts/prettier/index.js new file mode 100644 index 0000000000..7864e6edca --- /dev/null +++ b/scripts/prettier/index.js @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +// Based on similar script in Jest +// https://github.com/facebook/jest/blob/master/scripts/prettier.js + +const chalk = require('chalk'); +const glob = require('glob'); +const path = require('path'); +const runCommand = require('./runCommand'); + +const shouldWrite = process.argv[2] === 'write'; +const isWindows = process.platform === 'win32'; +const prettier = isWindows ? 'prettier.cmd' : 'prettier'; +const prettierCmd = path.resolve(__dirname, '../../node_modules/.bin/' + prettier); +const defaultOptions = { + 'bracket-spacing': 'false', + 'single-quote': 'true', + 'jsx-bracket-same-line': 'true', + 'trailing-comma': 'all', + 'print-width': 80, +}; +const config = { + default: { + patterns: ['src/**/*.js'], + ignore: [ + '**/third_party/**', + '**/node_modules/**', + ], + }, +}; + +Object.keys(config).forEach(key => { + const patterns = config[key].patterns; + const options = config[key].options; + const ignore = config[key].ignore; + + const globPattern = patterns.length > 1 + ? `{${patterns.join(',')}}` + : `${patterns.join(',')}`; + const files = glob.sync(globPattern, {ignore}); + + const args = Object.keys(defaultOptions).map( + k => `--${k}=${(options && options[k]) || defaultOptions[k]}` + ); + args.push(`--${shouldWrite ? 'write' : 'l'} {${files.join(' ')}}`); + + try { + runCommand(prettierCmd, args.join(' '), path.resolve(__dirname, '../..')); + } catch (e) { + console.log(e); + if (!shouldWrite) { + console.log( + chalk.red( + ` This project uses prettier to format all JavaScript code.\n` + ) + + chalk.dim(` Please run `) + + chalk.reset('yarn prettier') + + chalk.dim(` and add changes to files listed above to your commit.`) + + `\n` + ); + } + } +}); diff --git a/scripts/prettier/runCommand.js b/scripts/prettier/runCommand.js new file mode 100644 index 0000000000..81e3b9a943 --- /dev/null +++ b/scripts/prettier/runCommand.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2014, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +const chalk = require('chalk'); +const spawn = require('child_process').spawnSync; + +module.exports = function runCommand(cmd, args, cwd) { + if (!cwd) { + cwd = __dirname; + } + + const callArgs = args.split(' '); + console.log( + chalk.dim('$ cd ' + cwd) + + '\n' + + chalk.dim( + ' $ ' + + cmd + + ' ' + + (args.length > 1000 ? args.slice(0, 1000) + '...' : args) + ) + + '\n' + ); + const result = spawn(cmd, callArgs, { + cwd, + stdio: 'inherit', + }); + if (result.error || result.status !== 0) { + const message = 'Error running command.'; + const error = new Error(message); + error.stack = message; + throw error; + } +}; From ecf2e44908cacd25cbef62bcd4a667a51cb26002 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 15 Mar 2017 14:23:43 -0700 Subject: [PATCH 3/8] CI should fail if prettier wasn't run --- scripts/circleci/test_entry_point.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/circleci/test_entry_point.sh b/scripts/circleci/test_entry_point.sh index 9e85002157..d9a2fbf959 100755 --- a/scripts/circleci/test_entry_point.sh +++ b/scripts/circleci/test_entry_point.sh @@ -27,6 +27,7 @@ fi # These seem out of order but extract-errors must be run after jest. if [ $((0 % CIRCLE_NODE_TOTAL)) -eq "$CIRCLE_NODE_INDEX" ]; then COMMANDS_TO_RUN+=('./node_modules/.bin/gulp lint') + COMMANDS_TO_RUN+=('node ./scripts/prettier/index') COMMANDS_TO_RUN+=('./node_modules/.bin/gulp flow') COMMANDS_TO_RUN+=('./node_modules/.bin/grunt build') COMMANDS_TO_RUN+=('./scripts/circleci/test_extract_errors.sh') From 7cf2950ebbd9043077e67a6b9b533cf67446e6ff Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 15 Mar 2017 14:54:07 -0700 Subject: [PATCH 4/8] Pass args as an array --- scripts/prettier/index.js | 14 ++++++++---- scripts/prettier/runCommand.js | 40 ---------------------------------- 2 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 scripts/prettier/runCommand.js diff --git a/scripts/prettier/index.js b/scripts/prettier/index.js index 7864e6edca..e17a799a4b 100644 --- a/scripts/prettier/index.js +++ b/scripts/prettier/index.js @@ -13,7 +13,7 @@ const chalk = require('chalk'); const glob = require('glob'); const path = require('path'); -const runCommand = require('./runCommand'); +const execFileSync = require('child_process').execFileSync; const shouldWrite = process.argv[2] === 'write'; const isWindows = process.platform === 'win32'; @@ -36,6 +36,12 @@ const config = { }, }; +function exec(command, args) { + console.log('> ' + [command].concat(args).join(' ')); + var options = {}; + return execFileSync(command, args, options).toString(); +} + Object.keys(config).forEach(key => { const patterns = config[key].patterns; const options = config[key].options; @@ -49,14 +55,14 @@ Object.keys(config).forEach(key => { const args = Object.keys(defaultOptions).map( k => `--${k}=${(options && options[k]) || defaultOptions[k]}` ); - args.push(`--${shouldWrite ? 'write' : 'l'} {${files.join(' ')}}`); + args.push(`--${shouldWrite ? 'write' : 'l'}`); try { - runCommand(prettierCmd, args.join(' '), path.resolve(__dirname, '../..')); + exec(prettierCmd, [...args, ...files]); } catch (e) { - console.log(e); if (!shouldWrite) { console.log( + '\n' + chalk.red( ` This project uses prettier to format all JavaScript code.\n` ) + diff --git a/scripts/prettier/runCommand.js b/scripts/prettier/runCommand.js deleted file mode 100644 index 81e3b9a943..0000000000 --- a/scripts/prettier/runCommand.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2014, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -'use strict'; - -const chalk = require('chalk'); -const spawn = require('child_process').spawnSync; - -module.exports = function runCommand(cmd, args, cwd) { - if (!cwd) { - cwd = __dirname; - } - - const callArgs = args.split(' '); - console.log( - chalk.dim('$ cd ' + cwd) + - '\n' + - chalk.dim( - ' $ ' + - cmd + - ' ' + - (args.length > 1000 ? args.slice(0, 1000) + '...' : args) - ) + - '\n' - ); - const result = spawn(cmd, callArgs, { - cwd, - stdio: 'inherit', - }); - if (result.error || result.status !== 0) { - const message = 'Error running command.'; - const error = new Error(message); - error.stack = message; - throw error; - } -}; From c71a8ecd00e73e5950c994e9e0e8422edb7889ef Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 15 Mar 2017 17:12:46 -0700 Subject: [PATCH 5/8] Add prettier instructions to PR template and contribution guide --- .github/PULL_REQUEST_TEMPLATE.md | 7 ++++--- docs/contributing/how-to-contribute.md | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4a2bf79a20..5de9012e12 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -5,6 +5,7 @@ 3. If you've changed APIs, update the documentation. 4. Ensure the test suite passes (`npm test`). 5. Make sure your code lints (`npm run lint`). -6. Run the [Flow](https://flowtype.org/) typechecks (`npm run flow`). -7. If you added or removed any tests, run `./scripts/fiber/record-tests` before submitting the pull request, and commit the resulting changes. -8. If you haven't already, complete the [CLA](https://code.facebook.com/cla). +6. Format your code with [prettier](https://github.com/prettier/prettier) (`npm run prettier`). +7. Run the [Flow](https://flowtype.org/) typechecks (`npm run flow`). +8. If you added or removed any tests, run `./scripts/fiber/record-tests` before submitting the pull request, and commit the resulting changes. +9. If you haven't already, complete the CLA. diff --git a/docs/contributing/how-to-contribute.md b/docs/contributing/how-to-contribute.md index 9be878c237..6613a3c74b 100644 --- a/docs/contributing/how-to-contribute.md +++ b/docs/contributing/how-to-contribute.md @@ -81,9 +81,10 @@ The core team is monitoring for pull requests. We will review your pull request 3. If you've changed APIs, update the documentation. 4. Ensure the test suite passes (`npm test`). 5. Make sure your code lints (`npm run lint`). -6. Run the [Flow](https://flowtype.org/) typechecks (`npm run flow`). -7. If you added or removed any tests, run `./scripts/fiber/record-tests` before submitting the pull request, and commit the resulting changes. -8. If you haven't already, complete the CLA. +6. Format your code with [prettier](https://github.com/prettier/prettier) (`npm run prettier`). +7. Run the [Flow](https://flowtype.org/) typechecks (`npm run flow`). +8. If you added or removed any tests, run `./scripts/fiber/record-tests` before submitting the pull request, and commit the resulting changes. +9. If you haven't already, complete the CLA. ### Contributor License Agreement (CLA) From 0e5be287f734adf66ed3b9dc3cde5da00413884e Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 16 Mar 2017 10:58:57 -0700 Subject: [PATCH 6/8] Exit with failing code if prettier throws to ensure CI is blocked --- scripts/prettier/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/prettier/index.js b/scripts/prettier/index.js index e17a799a4b..85af4bcf87 100644 --- a/scripts/prettier/index.js +++ b/scripts/prettier/index.js @@ -71,6 +71,8 @@ Object.keys(config).forEach(key => { chalk.dim(` and add changes to files listed above to your commit.`) + `\n` ); + process.exit(1); } + throw e; } }); From cbdddbeb58ba40619515e38240e4819d00ce051a Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 15 Mar 2017 14:24:27 -0700 Subject: [PATCH 7/8] (test) Commit changes without running prettier to see if CI fails --- src/renderers/shared/fiber/ReactFiberUpdateQueue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js index a246436fff..1474e69e2f 100644 --- a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js +++ b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js @@ -12,7 +12,7 @@ 'use strict'; -import type {Fiber} from 'ReactFiber'; +import type { Fiber } from 'ReactFiber'; import type {PriorityLevel} from 'ReactPriorityLevel'; const { From 8802c20c22ecef9273c61d10ebb23ac858edb33f Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 16 Mar 2017 11:01:26 -0700 Subject: [PATCH 8/8] Run `yarn prettier` to format code CI should now pass --- src/renderers/shared/fiber/ReactFiberUpdateQueue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js index 1474e69e2f..a246436fff 100644 --- a/src/renderers/shared/fiber/ReactFiberUpdateQueue.js +++ b/src/renderers/shared/fiber/ReactFiberUpdateQueue.js @@ -12,7 +12,7 @@ 'use strict'; -import type { Fiber } from 'ReactFiber'; +import type {Fiber} from 'ReactFiber'; import type {PriorityLevel} from 'ReactPriorityLevel'; const {