@samitouri / QOS-React / commits / 9a6ce3379d

[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: ec6c76f8be01483d4ca75d9d74037b3966fccbdb Pull Request resolved: https://github.com/facebook/react-forget/pull/2955

Lauren Tan committed May 11, 2024 at 00:19 UTC 9a6ce3379d6390cf4b952e4ce261f9a975ffd8eb
3 files changed +51 -7
compiler/packages/healthcheck/package.json
+5 -2
@@ -2,13 +2,16 @@
2 "name": "healthcheck",
3 "version": "0.0.0",
4 "description": "Health check script to test violations of the rules of react.",
5 - "main": "dist/index.js",
5 + "bin": "dist/index.js",
6 "scripts": {
7 "build": "rimraf dist && rollup --config --bundleConfigAsCjs",
8 "test": "echo 'no tests'"
9 },
10 "dependencies": {
11 - "babel-plugin-react-compiler": "*",
11 + "@babel/core": "^7.24.4",
12 + "@babel/parser": "^7.24.4",
13 + "zod": "^3.22.4",
14 + "zod-validation-error": "^3.0.3",
15 "chalk": "4",
16 "fast-glob": "^3.3.2",
17 "ora": "5.4.1",
compiler/packages/healthcheck/rollup.config.js
+13 -2
@@ -15,7 +15,16 @@ import terser from "@rollup/plugin-terser";
15 import prettier from "rollup-plugin-prettier";
16 import banner2 from "rollup-plugin-banner2";
17
18 -const NO_INLINE = new Set([]);
18 +const NO_INLINE = new Set([
19 + "@babel/core",
20 + "@babel/parser",
21 + "chalk",
22 + "fast-glob",
23 + "ora",
24 + "yargs",
25 + "zod",
26 + "zod-validation-error",
27 +]);
28
29 const DEV_ROLLUP_CONFIG = {
30 input: "src/index.ts",
@@ -48,7 +57,9 @@ const DEV_ROLLUP_CONFIG = {
57 }),
58 prettier(),
59 banner2(
51 - () => `/**
60 + () => `#!/usr/bin/env node
61 +
62 +/**
63 * Copyright (c) Meta Platforms, Inc. and affiliates.
64 *
65 * This source code is licensed under the MIT license found in the
compiler/packages/healthcheck/src/checks/reactCompiler.ts
+33 -3
@@ -5,9 +5,11 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import {
8 +import type * as BabelCore from "@babel/core";
9 +import { transformFromAstSync } from "@babel/core";
10 +import * as BabelParser from "@babel/parser";
11 +import BabelPluginReactCompiler, {
12 ErrorSeverity,
10 - runBabelPluginReactCompiler,
13 type CompilerErrorDetailOptions,
14 type PluginOptions,
15 } from "babel-plugin-react-compiler/src";
@@ -63,6 +65,32 @@ function isActionableDiagnostic(detail: CompilerErrorDetailOptions) {
65 }
66 }
67
68 +function runBabelPluginReactCompiler(
69 + text: string,
70 + file: string,
71 + language: "flow" | "typescript",
72 + options: Partial<PluginOptions> | null
73 +): BabelCore.BabelFileResult {
74 + const ast = BabelParser.parse(text, {
75 + sourceFilename: file,
76 + plugins: [language, "jsx"],
77 + sourceType: "module",
78 + });
79 + const result = transformFromAstSync(ast, text, {
80 + filename: file,
81 + highlightCode: false,
82 + retainLines: true,
83 + plugins: [[BabelPluginReactCompiler, options]],
84 + sourceType: "module",
85 + });
86 + if (result?.code == null) {
87 + throw new Error(
88 + `Expected BabelPluginReactForget to codegen successfully, got: ${result}`
89 + );
90 + }
91 + return result;
92 +}
93 +
94 function compile(sourceCode: string, filename: string) {
95 try {
96 runBabelPluginReactCompiler(
@@ -71,7 +99,9 @@ function compile(sourceCode: string, filename: string) {
99 "typescript",
100 COMPILER_OPTIONS
101 );
74 - } catch {}
102 + } catch (e) {
103 + console.error(e);
104 + }
105 }
106
107 const JsFileExtensionRE = /(js|ts|jsx|tsx|mjs)$/;