react/scripts/rollup/validate/index.js
Josh Story da6ba53b10
[UMD] Remove umd builds (#28735)
In React 19 React will finally stop publishing UMD builds. This is
motivated primarily by the lack of use of UMD format and the added
complexity of maintaining build infra for these releases. Additionally
with ESM becoming more prevalent in browsers and services like esm.sh
which can host React as an ESM module there are other options for doing
script tag based react loading.

This PR removes all the UMD build configs and forks.

There are some fixtures that still have references to UMD builds however
many of them already do not work (for instance they are using legacy
features like ReactDOM.render) and rather than block the removal on
these fixtures being brought up to date we'll just move forward and fix
or removes fixtures as necessary in the future.
2024-04-17 11:15:27 -07:00

106 lines
2.8 KiB
JavaScript

'use strict';
/* eslint-disable no-for-of-loops/no-for-of-loops */
const path = require('path');
const {promisify} = require('util');
const glob = promisify(require('glob'));
const {ESLint} = require('eslint');
// Lint the final build artifacts. Helps catch bugs in our build pipeline.
function getFormat(filepath) {
if (filepath.includes('facebook')) {
if (filepath.includes('shims')) {
// We don't currently lint these shims. We rely on the downstream Facebook
// repo to transform them.
// TODO: Should we lint them?
return null;
}
return 'fb';
}
if (filepath.includes('react-native')) {
if (filepath.includes('shims')) {
// We don't currently lint these shims. We rely on the downstream Facebook
// repo to transform them.
// TODO: Should we lint them?
return null;
}
return 'rn';
}
if (filepath.includes('cjs')) {
if (
filepath.includes('react-server-dom-webpack-plugin') ||
filepath.includes('react-server-dom-webpack-node-register') ||
filepath.includes('react-suspense-test-utils')
) {
return 'cjs2015';
}
return 'cjs';
}
if (filepath.includes('esm')) {
return 'esm';
}
if (
filepath.includes('oss-experimental') ||
filepath.includes('oss-stable')
) {
// If a file in one of the open source channels doesn't match an earlier,
// more specific rule, then assume it's CommonJS.
return 'cjs';
}
throw new Error('Could not find matching lint format for file: ' + filepath);
}
function getESLintInstance(format) {
return new ESLint({
useEslintrc: false,
overrideConfigFile: path.join(__dirname, `eslintrc.${format}.js`),
ignore: false,
});
}
async function lint(eslint, filepaths) {
const results = await eslint.lintFiles(filepaths);
if (
results.some(result => result.errorCount > 0 || result.warningCount > 0)
) {
process.exitCode = 1;
console.log(`Lint failed`);
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
console.log(resultText);
}
}
async function lintEverything() {
console.log(`Linting build artifacts...`);
const allFilepaths = await glob('build/**/*.js');
const pathsByFormat = new Map();
for (const filepath of allFilepaths) {
const format = getFormat(filepath);
if (format !== null) {
const paths = pathsByFormat.get(format);
if (paths === undefined) {
pathsByFormat.set(format, [filepath]);
} else {
paths.push(filepath);
}
}
}
const promises = [];
for (const [format, filepaths] of pathsByFormat) {
const eslint = getESLintInstance(format);
promises.push(lint(eslint, filepaths));
}
await Promise.all(promises);
}
lintEverything().catch(error => {
process.exitCode = 1;
console.error(error);
});