forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
118 lines (106 loc) · 2.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
const path = require('path');
const {ESLint} = require('eslint');
const {bundles, getFilename, bundleTypes} = require('../bundles');
const Packaging = require('../packaging');
const {
NODE_ES2015,
NODE_ESM,
UMD_DEV,
UMD_PROD,
UMD_PROFILING,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
FB_WWW_PROFILING,
RN_OSS_DEV,
RN_OSS_PROD,
RN_OSS_PROFILING,
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
} = bundleTypes;
function getFormat(bundleType) {
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
return 'umd';
case NODE_ES2015:
return 'cjs2015';
case NODE_ESM:
return 'esm';
case NODE_DEV:
case NODE_PROD:
case NODE_PROFILING:
return 'cjs';
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
return 'fb';
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROD:
case RN_FB_PROFILING:
return 'rn';
}
throw new Error('unknown bundleType');
}
function getESLintInstance(format) {
return new ESLint({
useEslintrc: false,
overrideConfigFile: path.join(__dirname, `eslintrc.${format}.js`),
ignore: false,
});
}
const esLints = {
cjs: getESLintInstance('cjs'),
cjs2015: getESLintInstance('cjs2015'),
esm: getESLintInstance('esm'),
rn: getESLintInstance('rn'),
fb: getESLintInstance('fb'),
umd: getESLintInstance('umd'),
};
// Performs sanity checks on bundles *built* by Rollup.
// Helps catch Rollup regressions.
async function lint(bundle, bundleType) {
const filename = getFilename(bundle, bundleType);
const format = getFormat(bundleType);
const eslint = esLints[format];
const packageName = Packaging.getPackageName(bundle.entry);
const mainOutputPath = Packaging.getBundleOutputPath(
bundleType,
filename,
packageName
);
const results = await eslint.lintFiles([mainOutputPath]);
if (
results.some(result => result.errorCount > 0 || result.warningCount > 0)
) {
process.exitCode = 1;
console.log(`Failed ${mainOutputPath}`);
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
console.log(resultText);
}
}
async function lintEverything() {
console.log(`Linting known bundles...`);
let promises = [];
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
for (const bundle of bundles) {
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
for (const bundleType of bundle.bundleTypes) {
promises.push(lint(bundle, bundleType));
}
}
await Promise.all(promises);
}
lintEverything().catch(error => {
process.exitCode = 1;
console.error(error);
});