mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[healthcheck] Fix build
runReactBabelPluginReactCompiler brings in fbt which is unnecessary for
OSS so I removed it.
Also makes it so healthckeck is installed as an executable
ghstack-source-id: ec6c76f8be
Pull Request resolved: https://github.com/facebook/react-forget/pull/2955
This commit is contained in:
@@ -2,13 +2,16 @@
|
||||
"name": "healthcheck",
|
||||
"version": "0.0.0",
|
||||
"description": "Health check script to test violations of the rules of react.",
|
||||
"main": "dist/index.js",
|
||||
"bin": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
|
||||
"test": "echo 'no tests'"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-plugin-react-compiler": "*",
|
||||
"@babel/core": "^7.24.4",
|
||||
"@babel/parser": "^7.24.4",
|
||||
"zod": "^3.22.4",
|
||||
"zod-validation-error": "^3.0.3",
|
||||
"chalk": "4",
|
||||
"fast-glob": "^3.3.2",
|
||||
"ora": "5.4.1",
|
||||
|
||||
@@ -15,7 +15,16 @@ import terser from "@rollup/plugin-terser";
|
||||
import prettier from "rollup-plugin-prettier";
|
||||
import banner2 from "rollup-plugin-banner2";
|
||||
|
||||
const NO_INLINE = new Set([]);
|
||||
const NO_INLINE = new Set([
|
||||
"@babel/core",
|
||||
"@babel/parser",
|
||||
"chalk",
|
||||
"fast-glob",
|
||||
"ora",
|
||||
"yargs",
|
||||
"zod",
|
||||
"zod-validation-error",
|
||||
]);
|
||||
|
||||
const DEV_ROLLUP_CONFIG = {
|
||||
input: "src/index.ts",
|
||||
@@ -48,7 +57,9 @@ const DEV_ROLLUP_CONFIG = {
|
||||
}),
|
||||
prettier(),
|
||||
banner2(
|
||||
() => `/**
|
||||
() => `#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {
|
||||
import type * as BabelCore from "@babel/core";
|
||||
import { transformFromAstSync } from "@babel/core";
|
||||
import * as BabelParser from "@babel/parser";
|
||||
import BabelPluginReactCompiler, {
|
||||
ErrorSeverity,
|
||||
runBabelPluginReactCompiler,
|
||||
type CompilerErrorDetailOptions,
|
||||
type PluginOptions,
|
||||
} from "babel-plugin-react-compiler/src";
|
||||
@@ -63,6 +65,32 @@ function isActionableDiagnostic(detail: CompilerErrorDetailOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
function runBabelPluginReactCompiler(
|
||||
text: string,
|
||||
file: string,
|
||||
language: "flow" | "typescript",
|
||||
options: Partial<PluginOptions> | null
|
||||
): BabelCore.BabelFileResult {
|
||||
const ast = BabelParser.parse(text, {
|
||||
sourceFilename: file,
|
||||
plugins: [language, "jsx"],
|
||||
sourceType: "module",
|
||||
});
|
||||
const result = transformFromAstSync(ast, text, {
|
||||
filename: file,
|
||||
highlightCode: false,
|
||||
retainLines: true,
|
||||
plugins: [[BabelPluginReactCompiler, options]],
|
||||
sourceType: "module",
|
||||
});
|
||||
if (result?.code == null) {
|
||||
throw new Error(
|
||||
`Expected BabelPluginReactForget to codegen successfully, got: ${result}`
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function compile(sourceCode: string, filename: string) {
|
||||
try {
|
||||
runBabelPluginReactCompiler(
|
||||
@@ -71,7 +99,9 @@ function compile(sourceCode: string, filename: string) {
|
||||
"typescript",
|
||||
COMPILER_OPTIONS
|
||||
);
|
||||
} catch {}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
const JsFileExtensionRE = /(js|ts|jsx|tsx|mjs)$/;
|
||||
|
||||
Reference in New Issue
Block a user