react/scripts/rollup/validate/index.js
Brian Vaughn 0887c7d56c
Fork React Native renderer into FB and OSS bundles (#12625)
* Added new "native-fb" and "native-fabric-fb" bundles.
* Split RN_DEV and RN_PROD bundle types into RN_OSS_DEV, RN_OSS_PROD, RN_FB_DEV, and RN_FB_PROD. (This is a bit redundant but it seemed the least intrusive way of supporting a forked feature flags file for these bundles.)
* Renamed FB_DEV and FB_PROD bundle types to be more explicitly for www (FB_WWW_DEV and FB_WWW_PROD)
* Removed Haste @providesModule headers from the RB-specific RN renderer bundles to avoid a duplicate name conflicts.
* Remove dynamic values from OSS RN feature flags. (Leave them in FB RN feature flags.)
* Updated the sync script(s) to account for new renderer type.
* Move ReactFeatureFlags.js shim to FB bundle only (since OSS bundle no longer needs dynamic values).
2018-04-18 13:16:50 -07:00

83 lines
2.1 KiB
JavaScript

'use strict';
const chalk = require('chalk');
const path = require('path');
const spawnSync = require('child_process').spawnSync;
const glob = require('glob');
const extension = process.platform === 'win32' ? '.cmd' : '';
// Performs sanity checks on bundles *built* by Rollup.
// Helps catch Rollup regressions.
function lint({format, filePatterns}) {
console.log(`Linting ${format} bundles...`);
const result = spawnSync(
path.join('node_modules', '.bin', 'eslint' + extension),
[
...filePatterns,
'--config',
path.join(__dirname, `eslintrc.${format}.js`),
// Disregard our ESLint rules that apply to the source.
'--no-eslintrc',
// Use a different ignore file.
'--ignore-path',
path.join(__dirname, 'eslintignore'),
],
{
// Allow colors to pass through
stdio: 'inherit',
}
);
if (result.status !== 0) {
console.error(chalk.red(`Linting of ${format} bundles has failed.`));
process.exit(result.status);
} else {
console.log(chalk.green(`Linted ${format} bundles successfully!`));
console.log();
}
}
function checkFilesExist(bundle) {
const {format, filePatterns} = bundle;
filePatterns.forEach(pattern => {
console.log(`Checking if files exist in ${pattern}...`);
const files = glob.sync(pattern);
if (files.length === 0) {
console.error(chalk.red(`Found no ${format} bundles in ${pattern}`));
process.exit(1);
} else {
console.log(chalk.green(`Found ${files.length} bundles.`));
console.log();
}
});
return bundle;
}
const bundles = [
{
format: 'fb',
filePatterns: [`./build/facebook-www/*.js`],
},
{
format: 'rn',
filePatterns: [
`./build/react-native/oss/*.js`,
`./build/react-native/fb/ReactFabric-*.js`,
`./build/react-native/fb/ReactNativeRenderer-*.js`,
],
},
{
format: 'umd',
filePatterns: [`./build/node_modules/*/umd/*.js`],
},
{
format: 'cjs',
filePatterns: [
`./build/node_modules/*/*.js`,
`./build/node_modules/*/cjs/*.js`,
],
},
];
bundles.map(checkFilesExist).map(lint);