mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
This commit is a follow-up to https://github.com/facebook/react/pull/15604, which explains more of the rationale behind moving React Native to path-based imports and the work needed in the React repository. In that linked PR, the generated renderers were updated but not the shims; this commit updates the shims. The problem is that FB needs a different copy of the built renderers than the OSS versions so we need a way for FB code to import different modules than in OSS. This was previously done with Haste, but with the removal of Haste from RN, we need another mechanism. Talking with cpojer, we are using a `.fb.js` extension that Metro can be configured to prioritize over `.js`. This commit generates FB's renderers with the `.fb.js` extension and OSS renderers with just `.js`. This way, FB can internally configure Metro to use the `.fb.js` implementations and OSS will use the `.js` ones, letting us swap out which implementation gets bundled. Test Plan: Generated the renderers and shims with `yarn build` and then verified that the generated shims don't contain any Haste-style imports. Copied the renderers and shims into RN manually and launched the RNTester app to verify it loads end-to-end. Added `.fb.js` to the extensions in `metro.config.js` and verified that the FB-specific bundles loaded.
79 lines
2.0 KiB
JavaScript
79 lines
2.0 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/implementations/*.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);
|