@samitouri / QOS-React / commits / 4008f6d37d

Validate built bundles with a few ESLint rules (#11432)

Dan Abramov committed Nov 2, 2017 at 15:50 UTC 4008f6d37d45dc81705b8615c3d1bd21319f7b09
7 files changed +169
scripts/circleci/build.sh
+3
@@ -5,6 +5,9 @@ set -e
5 yarn build --extract-errors
6 git checkout -- scripts/error-codes/codes.json
7
8 +# Do a sanity check on bundles
9 +node ./scripts/rollup/validate/index
10 +
11 # Check that the standalone reconciler isn't borked
12 cd fixtures/reconciler
13 yarn
scripts/rollup/validate/eslintignore new
+4
@@ -0,0 +1,4 @@
1 +# Don't validate noop renderer bundle.
2 +# Unlike others, it currently uses ES6 syntax (generators).
3 +# We also don't use or publish it.
4 +**/react-noop-renderer/**
\ No newline at end of file
scripts/rollup/validate/eslintrc.cjs.js new
+29
@@ -0,0 +1,29 @@
1 +'use strict';
2 +
3 +module.exports = {
4 + env: {
5 + commonjs: true,
6 + browser: true,
7 + },
8 + globals: {
9 + // ES 6
10 + Map: true,
11 + Set: true,
12 + Proxy: true,
13 + Symbol: true,
14 + WeakMap: true,
15 + // Vendor specific
16 + MSApp: true,
17 + __REACT_DEVTOOLS_GLOBAL_HOOK__: true,
18 + // CommonJS / Node
19 + process: true,
20 + },
21 + parserOptions: {
22 + ecmaVersion: 5,
23 + sourceType: 'script',
24 + },
25 + rules: {
26 + 'no-undef': 'error',
27 + 'no-shadow-restricted-names': 'error',
28 + },
29 +};
scripts/rollup/validate/eslintrc.fb.js new
+29
@@ -0,0 +1,29 @@
1 +'use strict';
2 +
3 +module.exports = {
4 + env: {
5 + commonjs: true,
6 + browser: true,
7 + },
8 + globals: {
9 + // ES6
10 + Map: true,
11 + Set: true,
12 + Symbol: true,
13 + Proxy: true,
14 + WeakMap: true,
15 + // Vendor specific
16 + MSApp: true,
17 + __REACT_DEVTOOLS_GLOBAL_HOOK__: true,
18 + // FB
19 + __DEV__: true,
20 + },
21 + parserOptions: {
22 + ecmaVersion: 5,
23 + sourceType: 'script',
24 + },
25 + rules: {
26 + 'no-undef': 'error',
27 + 'no-shadow-restricted-names': 'error',
28 + },
29 +};
scripts/rollup/validate/eslintrc.rn.js new
+29
@@ -0,0 +1,29 @@
1 +'use strict';
2 +
3 +module.exports = {
4 + env: {
5 + commonjs: true,
6 + browser: true,
7 + },
8 + globals: {
9 + // ES6
10 + Map: true,
11 + Set: true,
12 + Symbol: true,
13 + Proxy: true,
14 + WeakMap: true,
15 + // Vendor specific
16 + MSApp: true,
17 + __REACT_DEVTOOLS_GLOBAL_HOOK__: true,
18 + // FB
19 + __DEV__: true,
20 + },
21 + parserOptions: {
22 + ecmaVersion: 5,
23 + sourceType: 'script',
24 + },
25 + rules: {
26 + 'no-undef': 'error',
27 + 'no-shadow-restricted-names': 'error',
28 + },
29 +};
scripts/rollup/validate/eslintrc.umd.js new
+33
@@ -0,0 +1,33 @@
1 +'use strict';
2 +
3 +module.exports = {
4 + env: {
5 + browser: true,
6 + },
7 + globals: {
8 + // ES6
9 + Map: true,
10 + Set: true,
11 + Symbol: true,
12 + Proxy: true,
13 + WeakMap: true,
14 + // Vendor specific
15 + MSApp: true,
16 + __REACT_DEVTOOLS_GLOBAL_HOOK__: true,
17 + // UMD wrapper code
18 + // TODO: this is too permissive.
19 + // Ideally we should only allow these *inside* the UMD wrapper.
20 + module: true,
21 + define: true,
22 + require: true,
23 + global: true,
24 + },
25 + parserOptions: {
26 + ecmaVersion: 5,
27 + sourceType: 'script',
28 + },
29 + rules: {
30 + 'no-undef': 'error',
31 + 'no-shadow-restricted-names': 'error',
32 + },
33 +};
scripts/rollup/validate/index.js new
+42
@@ -0,0 +1,42 @@
1 +'use strict';
2 +
3 +const chalk = require('chalk');
4 +const path = require('path');
5 +const spawnSync = require('child_process').spawnSync;
6 +
7 +const extension = process.platform === 'win32' ? '.cmd' : '';
8 +
9 +// Performs sanity checks on bundles *built* by Rollup.
10 +// Helps catch Rollup regressions.
11 +function run(format, filePatterns) {
12 + console.log(`Linting ${format} bundles...`);
13 + const result = spawnSync(
14 + path.join('node_modules', '.bin', 'eslint' + extension),
15 + [
16 + filePatterns,
17 + '--config',
18 + path.join(__dirname, `eslintrc.${format}.js`),
19 + // Disregard our ESLint rules that apply to the source.
20 + '--no-eslintrc',
21 + // Use a different ignore file.
22 + '--ignore-path',
23 + path.join(__dirname, 'eslintignore'),
24 + ],
25 + {
26 + // Allow colors to pass through
27 + stdio: 'inherit',
28 + }
29 + );
30 + if (result.status !== 0) {
31 + console.error(chalk.red(`Linting of ${format} bundles has failed.`));
32 + process.exit(result.status);
33 + } else {
34 + console.log(chalk.green(`Linted ${format} bundles successfully!`));
35 + console.log();
36 + }
37 +}
38 +
39 +run('fb', `./build/facebook-www/*.js`);
40 +run('rn', `./build/{react-cs,react-native,react-rt}/*.js`);
41 +run('umd', `./build/packages/*/umd/*.js`);
42 +run('cjs', [`./build/packages/*/*.js`, `./build/packages/*/cjs/*.js`]);