Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60afa3c

Browse files
authored
Lint bundles using the bundle config instead of scanning for files (facebook#19025)
* Lint bundles using the bundle config instead of scanning for files This ensures that we look for all the files that we expect to see there. If something doesn't get built we wouldn't detect it. However, this doesn't find files that aren't part of our builds such as indirection files in the root. This will need to change with ESM anyway since indirection files doesn't work. Everything should be built anyway. This ensures that we can use the bundles.js config to determine special cases instead of relying on file system conventions. * Run lint with flag
1 parent 518ce9c commit 60afa3c

File tree

6 files changed

+161
-120
lines changed

6 files changed

+161
-120
lines changed

.circleci/config.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ jobs:
364364
- run: yarn lint-build
365365
- run: scripts/circleci/check_minified_errors.sh
366366

367+
RELEASE_CHANNEL_stable_yarn_lint_build:
368+
docker: *docker
369+
environment: *environment
370+
steps:
371+
- checkout
372+
- attach_workspace: *attach_workspace
373+
- *restore_yarn_cache
374+
- *run_yarn
375+
- run:
376+
environment:
377+
RELEASE_CHANNEL: stable
378+
command: yarn lint-build
379+
- run: scripts/circleci/check_minified_errors.sh
380+
367381
RELEASE_CHANNEL_stable_yarn_test_build:
368382
docker: *docker
369383
environment: *environment
@@ -500,7 +514,7 @@ workflows:
500514
- sizebot_stable:
501515
requires:
502516
- RELEASE_CHANNEL_stable_yarn_build
503-
- yarn_lint_build:
517+
- RELEASE_CHANNEL_stable_yarn_lint_build:
504518
requires:
505519
- RELEASE_CHANNEL_stable_yarn_build
506520
- RELEASE_CHANNEL_stable_yarn_test_build:

scripts/rollup/build.js

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const {
6262
RN_FB_PROFILING,
6363
} = Bundles.bundleTypes;
6464

65+
const {getFilename} = Bundles;
66+
6567
function parseRequestedNames(names, toCase) {
6668
let result = [];
6769
for (let i = 0; i < names.length; i++) {
@@ -258,37 +260,6 @@ function getFormat(bundleType) {
258260
}
259261
}
260262

261-
function getFilename(name, globalName, bundleType) {
262-
// we do this to replace / to -, for react-dom/server
263-
name = name.replace('/index.', '.').replace('/', '-');
264-
switch (bundleType) {
265-
case UMD_DEV:
266-
return `${name}.development.js`;
267-
case UMD_PROD:
268-
return `${name}.production.min.js`;
269-
case UMD_PROFILING:
270-
return `${name}.profiling.min.js`;
271-
case NODE_DEV:
272-
return `${name}.development.js`;
273-
case NODE_PROD:
274-
return `${name}.production.min.js`;
275-
case NODE_PROFILING:
276-
return `${name}.profiling.min.js`;
277-
case FB_WWW_DEV:
278-
case RN_OSS_DEV:
279-
case RN_FB_DEV:
280-
return `${globalName}-dev.js`;
281-
case FB_WWW_PROD:
282-
case RN_OSS_PROD:
283-
case RN_FB_PROD:
284-
return `${globalName}-prod.js`;
285-
case FB_WWW_PROFILING:
286-
case RN_FB_PROFILING:
287-
case RN_OSS_PROFILING:
288-
return `${globalName}-profiling.js`;
289-
}
290-
}
291-
292263
function isProductionBundleType(bundleType) {
293264
switch (bundleType) {
294265
case UMD_DEV:
@@ -558,7 +529,7 @@ async function createBundle(bundle, bundleType) {
558529
return;
559530
}
560531

561-
const filename = getFilename(bundle.entry, bundle.global, bundleType);
532+
const filename = getFilename(bundle, bundleType);
562533
const logKey =
563534
chalk.white.bold(filename) + chalk.dim(` (${bundleType.toLowerCase()})`);
564535
const format = getFormat(bundleType);
@@ -765,17 +736,11 @@ async function buildEverything() {
765736
[bundle, FB_WWW_PROFILING],
766737
[bundle, RN_OSS_DEV],
767738
[bundle, RN_OSS_PROD],
768-
[bundle, RN_OSS_PROFILING]
739+
[bundle, RN_OSS_PROFILING],
740+
[bundle, RN_FB_DEV],
741+
[bundle, RN_FB_PROD],
742+
[bundle, RN_FB_PROFILING]
769743
);
770-
771-
if (__EXPERIMENTAL__) {
772-
// FB-specific RN builds are experimental-only.
773-
bundles.push(
774-
[bundle, RN_FB_DEV],
775-
[bundle, RN_FB_PROD],
776-
[bundle, RN_FB_PROFILING]
777-
);
778-
}
779744
}
780745

781746
if (!shouldExtractErrors && process.env.CIRCLE_NODE_TOTAL) {

scripts/rollup/bundles.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ const bundles = [
356356

357357
/******* React Native *******/
358358
{
359-
bundleTypes: [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING],
359+
bundleTypes: __EXPERIMENTAL__
360+
? [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING]
361+
: [],
360362
moduleType: RENDERER,
361363
entry: 'react-native-renderer',
362364
global: 'ReactNativeRenderer',
@@ -384,7 +386,9 @@ const bundles = [
384386

385387
/******* React Native Fabric *******/
386388
{
387-
bundleTypes: [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING],
389+
bundleTypes: __EXPERIMENTAL__
390+
? [RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING]
391+
: [],
388392
moduleType: RENDERER,
389393
entry: 'react-native-renderer/fabric',
390394
global: 'ReactFabric',
@@ -793,9 +797,43 @@ deepFreeze(bundles);
793797
deepFreeze(bundleTypes);
794798
deepFreeze(moduleTypes);
795799

800+
function getFilename(bundle, bundleType) {
801+
let name = bundle.entry;
802+
const globalName = bundle.global;
803+
// we do this to replace / to -, for react-dom/server
804+
name = name.replace('/index.', '.').replace('/', '-');
805+
switch (bundleType) {
806+
case UMD_DEV:
807+
return `${name}.development.js`;
808+
case UMD_PROD:
809+
return `${name}.production.min.js`;
810+
case UMD_PROFILING:
811+
return `${name}.profiling.min.js`;
812+
case NODE_DEV:
813+
return `${name}.development.js`;
814+
case NODE_PROD:
815+
return `${name}.production.min.js`;
816+
case NODE_PROFILING:
817+
return `${name}.profiling.min.js`;
818+
case FB_WWW_DEV:
819+
case RN_OSS_DEV:
820+
case RN_FB_DEV:
821+
return `${globalName}-dev.js`;
822+
case FB_WWW_PROD:
823+
case RN_OSS_PROD:
824+
case RN_FB_PROD:
825+
return `${globalName}-prod.js`;
826+
case FB_WWW_PROFILING:
827+
case RN_FB_PROFILING:
828+
case RN_OSS_PROFILING:
829+
return `${globalName}-profiling.js`;
830+
}
831+
}
832+
796833
module.exports = {
797834
fbBundleExternalsMap,
798835
bundleTypes,
799836
moduleTypes,
800837
bundles,
838+
getFilename,
801839
};

scripts/rollup/validate/eslintignore

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/rollup/validate/eslintrc.cjs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ module.exports = {
3737
// Flight Webpack
3838
__webpack_chunk_load__: true,
3939
__webpack_require__: true,
40+
41+
// jest
42+
expect: true,
4043
},
4144
parserOptions: {
4245
ecmaVersion: 5,

scripts/rollup/validate/index.js

Lines changed: 96 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,110 @@
11
'use strict';
22

3-
const chalk = require('chalk');
43
const path = require('path');
5-
const spawnSync = require('child_process').spawnSync;
6-
const glob = require('glob');
74

8-
const extension = process.platform === 'win32' ? '.cmd' : '';
5+
const {ESLint} = require('eslint');
6+
7+
const {bundles, getFilename, bundleTypes} = require('../bundles');
8+
const Packaging = require('../packaging');
9+
10+
const {
11+
UMD_DEV,
12+
UMD_PROD,
13+
UMD_PROFILING,
14+
NODE_DEV,
15+
NODE_PROD,
16+
NODE_PROFILING,
17+
FB_WWW_DEV,
18+
FB_WWW_PROD,
19+
FB_WWW_PROFILING,
20+
RN_OSS_DEV,
21+
RN_OSS_PROD,
22+
RN_OSS_PROFILING,
23+
RN_FB_DEV,
24+
RN_FB_PROD,
25+
RN_FB_PROFILING,
26+
} = bundleTypes;
27+
28+
function getFormat(bundleType) {
29+
switch (bundleType) {
30+
case UMD_DEV:
31+
case UMD_PROD:
32+
case UMD_PROFILING:
33+
return 'umd';
34+
case NODE_DEV:
35+
case NODE_PROD:
36+
case NODE_PROFILING:
37+
return 'cjs';
38+
case FB_WWW_DEV:
39+
case FB_WWW_PROD:
40+
case FB_WWW_PROFILING:
41+
return 'fb';
42+
case RN_OSS_DEV:
43+
case RN_OSS_PROD:
44+
case RN_OSS_PROFILING:
45+
case RN_FB_DEV:
46+
case RN_FB_PROD:
47+
case RN_FB_PROFILING:
48+
return 'rn';
49+
}
50+
throw new Error('unknown bundleType');
51+
}
52+
53+
function getESLintInstance(format) {
54+
return new ESLint({
55+
useEslintrc: false,
56+
overrideConfigFile: path.join(__dirname, `eslintrc.${format}.js`),
57+
ignore: false,
58+
});
59+
}
60+
61+
const esLints = {
62+
cjs: getESLintInstance('cjs'),
63+
rn: getESLintInstance('rn'),
64+
fb: getESLintInstance('fb'),
65+
umd: getESLintInstance('umd'),
66+
};
967

1068
// Performs sanity checks on bundles *built* by Rollup.
1169
// Helps catch Rollup regressions.
12-
function lint({format, filePatterns}) {
13-
console.log(`Linting ${format} bundles...`);
14-
const result = spawnSync(
15-
path.join('node_modules', '.bin', 'eslint' + extension),
16-
[
17-
...filePatterns,
18-
'--config',
19-
path.join(__dirname, `eslintrc.${format}.js`),
20-
// Disregard our ESLint rules that apply to the source.
21-
'--no-eslintrc',
22-
// Use a different ignore file.
23-
'--ignore-path',
24-
path.join(__dirname, 'eslintignore'),
25-
],
26-
{
27-
// Allow colors to pass through
28-
stdio: 'inherit',
29-
}
70+
async function lint(bundle, bundleType) {
71+
const filename = getFilename(bundle, bundleType);
72+
const format = getFormat(bundleType);
73+
const eslint = esLints[format];
74+
75+
const packageName = Packaging.getPackageName(bundle.entry);
76+
const mainOutputPath = Packaging.getBundleOutputPath(
77+
bundleType,
78+
filename,
79+
packageName
3080
);
31-
if (result.status !== 0) {
32-
console.error(chalk.red(`Linting of ${format} bundles has failed.`));
33-
process.exit(result.status);
34-
} else {
35-
console.log(chalk.green(`Linted ${format} bundles successfully!`));
36-
console.log();
81+
82+
const results = await eslint.lintFiles([mainOutputPath]);
83+
if (
84+
results.some(result => result.errorCount > 0 || result.warningCount > 0)
85+
) {
86+
process.exitCode = 1;
87+
console.log(`Failed ${mainOutputPath}`);
88+
const formatter = await eslint.loadFormatter('stylish');
89+
const resultText = formatter.format(results);
90+
console.log(resultText);
3791
}
3892
}
3993

40-
function checkFilesExist(bundle) {
41-
const {format, filePatterns} = bundle;
42-
filePatterns.forEach(pattern => {
43-
console.log(`Checking if files exist in ${pattern}...`);
44-
const files = glob.sync(pattern);
45-
if (files.length === 0) {
46-
console.error(chalk.red(`Found no ${format} bundles in ${pattern}`));
47-
process.exit(1);
48-
} else {
49-
console.log(chalk.green(`Found ${files.length} bundles.`));
50-
console.log();
94+
async function lintEverything() {
95+
console.log(`Linting known bundles...`);
96+
let promises = [];
97+
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
98+
for (const bundle of bundles) {
99+
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
100+
for (const bundleType of bundle.bundleTypes) {
101+
promises.push(lint(bundle, bundleType));
51102
}
52-
});
53-
return bundle;
103+
}
104+
await Promise.all(promises);
54105
}
55106

56-
const bundles = [
57-
{
58-
format: 'rn',
59-
filePatterns: [`./build/react-native/implementations/*.js`],
60-
},
61-
{
62-
format: 'umd',
63-
filePatterns: [`./build/node_modules/*/umd/*.js`],
64-
},
65-
{
66-
format: 'cjs',
67-
filePatterns: [
68-
`./build/node_modules/*/*.js`,
69-
`./build/node_modules/*/cjs/*.js`,
70-
],
71-
},
72-
{
73-
format: 'fb',
74-
filePatterns: [`./build/facebook-www/*.js`],
75-
},
76-
];
77-
78-
bundles.map(checkFilesExist).map(lint);
107+
lintEverything().catch(error => {
108+
process.exitCode = 1;
109+
console.error(error);
110+
});

0 commit comments

Comments
 (0)