diff --git a/compiler/packages/babel-plugin-react-forget/src/index.ts b/compiler/packages/babel-plugin-react-forget/src/index.ts index 4882d6ffdd..b314f6925c 100644 --- a/compiler/packages/babel-plugin-react-forget/src/index.ts +++ b/compiler/packages/babel-plugin-react-forget/src/index.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +export { runReactForgetBabelPlugin } from "./Babel/RunReactForgetBabelPlugin"; export { CompilerError, CompilerErrorDetail, diff --git a/compiler/packages/health-check/src/index.ts b/compiler/packages/health-check/src/index.ts index a23e2c0502..65b22af1bd 100644 --- a/compiler/packages/health-check/src/index.ts +++ b/compiler/packages/health-check/src/index.ts @@ -5,9 +5,54 @@ * LICENSE file in the root directory of this source tree. */ +import { + runReactForgetBabelPlugin, + type PluginOptions, +} from "babel-plugin-react-forget/src"; +import { LoggerEvent } from "babel-plugin-react-forget/src/Entrypoint"; import { glob } from "fast-glob"; +import * as fs from "fs/promises"; import yargs from "yargs/yargs"; +const SUCCESS: Array = []; +const FAILURES: Array = []; + +const logger = { + logEvent(_: string | null, event: LoggerEvent) { + switch (event.kind) { + case "CompileSuccess": { + SUCCESS.push(event); + return; + } + case "CompileError": { + FAILURES.push(event); + return; + } + case "CompileDiagnostic": + case "PipelineError": + // TODO(gsn): Silenty fail? + } + }, +}; + +const COMPILER_OPTIONS: Partial = { + noEmit: true, + compilationMode: "infer", + panicThreshold: "critical_errors", + logger, +}; + +function compile(sourceCode: string, filename: string) { + try { + runReactForgetBabelPlugin( + sourceCode, + filename, + "typescript", + COMPILER_OPTIONS + ); + } catch {} +} + async function main() { const argv = yargs(process.argv.slice(2)) .scriptName("healthcheck") @@ -41,8 +86,12 @@ async function main() { }; for (const path of await glob(src, globOptions)) { - console.log(path); + const source = await fs.readFile(path, "utf-8"); + compile(source, path); } + + console.log(`Successful compilation: ${SUCCESS.length}`); + console.log(`Failed compilation: ${FAILURES.length}`); } main();