Skip to content

Commit da86a45

Browse files
misoguygaearon
authored andcommitted
Validate built bundles exists (#11452)
1 parent 028691b commit da86a45

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

scripts/rollup/validate/index.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
const chalk = require('chalk');
44
const path = require('path');
55
const spawnSync = require('child_process').spawnSync;
6+
const glob = require('glob');
67

78
const extension = process.platform === 'win32' ? '.cmd' : '';
89

910
// Performs sanity checks on bundles *built* by Rollup.
1011
// Helps catch Rollup regressions.
11-
function run(format, filePatterns) {
12+
function lint({format, filePatterns}) {
1213
console.log(`Linting ${format} bundles...`);
1314
const result = spawnSync(
1415
path.join('node_modules', '.bin', 'eslint' + extension),
@@ -36,7 +37,43 @@ function run(format, filePatterns) {
3637
}
3738
}
3839

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`]);
40+
function checkFilesExist(bundle) {
41+
const {format, filePatterns} = bundle;
42+
filePatterns.map(pattern => {
43+
console.log(`Check if files exist in ${pattern}`);
44+
const files = glob.sync(pattern);
45+
if (files.length === 0) {
46+
console.error(
47+
chalk.red(
48+
`No files found in glob pattern ${pattern} in ${format} bundle.`
49+
)
50+
);
51+
process.exit();
52+
} else {
53+
console.log(chalk.green(`${files.length} files found.`));
54+
console.log();
55+
}
56+
});
57+
return bundle;
58+
}
59+
60+
const bundles = [
61+
{
62+
format: 'fb',
63+
filePatterns: [`./build/facebook-www/*.js`],
64+
},
65+
{
66+
format: 'rn',
67+
filePatterns: [`./build/{react-cs,react-native,react-rt}/*.js`],
68+
},
69+
{
70+
format: 'umd',
71+
filePatterns: [`./build/packages/*/umd/*.js`],
72+
},
73+
{
74+
format: 'cjs',
75+
filePatterns: [`./build/packages/*/*.js`, `./build/packages/*/cjs/*.js`],
76+
},
77+
];
78+
79+
bundles.map(checkFilesExist).map(lint);

0 commit comments

Comments
 (0)