mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[healthcheck] Compile sources
Run the compiler on the globbed soruces. The logger is used to capture the success and failure compilation cases at the component level. (If we were to compile the entire file directly, we wouldn't get this granularity) For now, we just log the number of success and failures. In the future, we can provide a better report building on this. ghstack-source-id: 6d2d918190b6ed5d42b795491bbce29a950b9741 Pull Request resolved: https://github.com/facebook/react-forget/pull/2888
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
export { runReactForgetBabelPlugin } from "./Babel/RunReactForgetBabelPlugin";
|
||||
export {
|
||||
CompilerError,
|
||||
CompilerErrorDetail,
|
||||
|
||||
@@ -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<LoggerEvent> = [];
|
||||
const FAILURES: Array<LoggerEvent> = [];
|
||||
|
||||
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<PluginOptions> = {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user