feat(eslint-plugin-react-hooks): merge rule from eslint-plugin-react-compiler into react-hooks plugin (#32416)

This change merges the `react-compiler` rule from
`eslint-plugin-react-compiler` into the `eslint-plugin-react-hooks`
plugin. In order to do the move in a way that keeps commit history with
the moved files, but also no remove them from their origin until a
future cleanup change can be done, I did the `git mv` first, and then
recreated the files that were moved in their original places, as a
separate commit. Unfortunately GH shows the moved files as new instead
of the ones that are truly new. But in the IDE and `git blame`, commit
history is intact with the moved files.

Since this change adds new dependencies, and one of those dependencies
has a higher `engines` declaration for `node` than what the plugin
currently has, this is technically a breaking change and will have to go
out as part of a major release.

### Related Changes
- https://github.com/facebook/react/pull/32458

---------

Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>
This commit is contained in:
michael faith
2025-03-12 21:43:06 -04:00
committed by GitHub
co-authored by Lauren Tan
parent a8ab2bcb62
commit 5ccfcd17ff
26 changed files with 3607 additions and 582 deletions
@@ -1,12 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`error transform handles deeply nested expressions 1`] = `
"var val = (a, (b, // eslint-disable-next-line react-internal/prod-error-codes
"var val = (a, (b,
// eslint-disable-next-line react-internal/prod-error-codes
new Error('foo')));"
`;
exports[`error transform handles deeply nested expressions 2`] = `
"var val = (a, ( // eslint-disable-next-line react-internal/prod-error-codes
"var val = (a, (
// eslint-disable-next-line react-internal/prod-error-codes
b, new Error('foo')));"
`;
@@ -17,10 +19,11 @@ Error(_formatProdErrorMessage(231, listener, type));"
exports[`error transform handles ignoring errors that are comment-excluded inside ternary expressions 1`] = `
"/*! FIXME (minify-errors-in-prod): Unminified error message in production build!*/
/*! <expected-error-format>"bar"</expected-error-format>*/
var val = someBool ? //eslint-disable-next-line react-internal/prod-error-codes
new Error('foo') : someOtherBool ? new Error('bar') : //eslint-disable-next-line react-internal/prod-error-codes
var val = someBool ?
//eslint-disable-next-line react-internal/prod-error-codes
new Error('foo') : someOtherBool ? new Error('bar') :
//eslint-disable-next-line react-internal/prod-error-codes
new Error('baz');"
`;
@@ -36,7 +39,6 @@ NotAnError();"
exports[`error transform should output FIXME for errors that don't have a matching error code 1`] = `
"/*! FIXME (minify-errors-in-prod): Unminified error message in production build!*/
/*! <expected-error-format>"This is not a real error message."</expected-error-format>*/
Error('This is not a real error message.');"
`;
+6
View File
@@ -7,6 +7,12 @@ module.exports = {
'<rootDir>/scripts/bench/',
],
transform: {
'^.+babel-plugin-react-compiler/dist/index.js$': [
'babel-jest',
{
configFile: require.resolve('../../babel.config-react-compiler.js'),
},
],
'^.+\\.ts$': [
'babel-jest',
{configFile: require.resolve('../../babel.config-ts.js')},
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -eo pipefail
if [[ "$REACT_CLASS_EQUIVALENCE_TEST" == "true" ]]; then
exit 0
fi
echo "Building babel-plugin-react-compiler..."
yarn --cwd compiler install --frozen-lockfile
yarn --cwd compiler workspace babel-plugin-react-compiler build --dts
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -eo pipefail
if [[ "$REACT_CLASS_EQUIVALENCE_TEST" == "true" ]]; then
exit 0
fi
HERE=$(pwd)
cd compiler/packages/babel-plugin-react-compiler && yarn --silent link && cd $HERE
yarn --silent link babel-plugin-react-compiler
+21 -8
View File
@@ -25,6 +25,8 @@ const Packaging = require('./packaging');
const {asyncRimRaf} = require('./utils');
const codeFrame = require('@babel/code-frame').default;
const Wrappers = require('./wrappers');
const commonjs = require('@rollup/plugin-commonjs');
const {getBabelOutputPlugin} = require('@rollup/plugin-babel');
const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL;
@@ -392,6 +394,7 @@ function getPlugins(
};
},
},
bundle.tsconfig != null ? commonjs() : false,
// Shim any modules that need forking in this environment.
useForks(forks),
// Ensure we don't try to bundle any fbjs modules.
@@ -415,13 +418,23 @@ function getPlugins(
bundle
)
),
// Remove 'use strict' from individual source files.
{
name: "remove 'use strict'",
transform(source) {
return source.replace(/['"]use strict["']/g, '');
},
},
// For Meta internal requirements this package needs to be built targeting ES5.
bundle.name === 'eslint-plugin-react-hooks'
? getBabelOutputPlugin({
presets: ['@babel/preset-env'],
})
: false,
// Remove 'use strict' from individual source files. We skip eslint-plugin-react-hooks because
// it bundles compiler-type code that may examine "use strict" used outside of a directive
// context, e.g. as a StringLiteral.
bundle.name !== 'eslint-plugin-react-hooks'
? {
name: "remove 'use strict'",
transform(source) {
return source.replace(/['"]use strict["']/g, '');
},
}
: false,
// Turn __DEV__ and process.env checks into constants.
replace({
preventAssignment: true,
@@ -490,7 +503,7 @@ function getPlugins(
// takes care of it.
renaming: false,
}),
needsMinifiedByClosure &&
(needsMinifiedByClosure || bundle.name === 'eslint-plugin-react-hooks') &&
// Add the whitespace back
prettier({
parser: 'flow',
+1
View File
@@ -1197,6 +1197,7 @@ const bundles = [
wrapWithModuleBoundaries: false,
externals: [],
tsconfig: './packages/eslint-plugin-react-hooks/tsconfig.json',
prebuild: `mkdir -p ./compiler/packages/babel-plugin-react-compiler/dist && echo "module.exports = require('../src/index.ts');" > ./compiler/packages/babel-plugin-react-compiler/dist/index.js`,
},
/******* React Fresh *******/