[healthcheck] Only count actionable failures
It's not useful to output count of all failures, as it's not actionable for the developer. We'll still capture all failures in case we want to add a rage option to this script. ghstack-source-id: 4d5a1dd6a9616e6fd5e1166bb97fa047829b9273 Pull Request resolved: https://github.com/facebook/react-forget/pull/2889
Sathya Gunsasekaran committed
Apr 23, 2024 at 12:28 UTC
e0dbe47ad6c92380f4ddb80fce0f07bb5104ab9f
2 files changed
+26
-4
compiler/packages/babel-plugin-react-forget/src/index.ts
+1
-1
@@ -11,6 +11,7 @@ export {
11
CompilerErrorDetail,
12
CompilerSuggestionOperation,
13
ErrorSeverity,
14
+ type CompilerErrorDetailOptions,
15
} from "./CompilerError";
16
export {
17
compileFn as compile,
@@ -32,7 +33,6 @@ export {
33
type SourceLocation,
34
} from "./HIR";
35
export { printReactiveFunction } from "./ReactiveScopes";
35
-
36
declare global {
37
let __DEV__: boolean | null | undefined;
38
}
compiler/packages/health-check/src/index.ts
+25
-3
@@ -6,7 +6,9 @@
6
*/
7
8
import {
9
+ ErrorSeverity,
10
runReactForgetBabelPlugin,
11
+ type CompilerErrorDetailOptions,
12
type PluginOptions,
13
} from "babel-plugin-react-forget/src";
14
import { LoggerEvent } from "babel-plugin-react-forget/src/Entrypoint";
@@ -15,7 +17,8 @@ import * as fs from "fs/promises";
17
import yargs from "yargs/yargs";
18
19
const SUCCESS: Array<LoggerEvent> = [];
18
-const FAILURES: Array<LoggerEvent> = [];
20
+const ACTIONABLE_FAILURES: Array<LoggerEvent> = [];
21
+const OTHER_FAILURES: Array<LoggerEvent> = [];
22
23
const logger = {
24
logEvent(_: string | null, event: LoggerEvent) {
@@ -25,7 +28,11 @@ const logger = {
28
return;
29
}
30
case "CompileError": {
28
- FAILURES.push(event);
31
+ if (isActionableDiagnostic(event.detail)) {
32
+ ACTIONABLE_FAILURES.push(event);
33
+ return;
34
+ }
35
+ OTHER_FAILURES.push(event);
36
return;
37
}
38
case "CompileDiagnostic":
@@ -42,6 +49,21 @@ const COMPILER_OPTIONS: Partial<PluginOptions> = {
49
logger,
50
};
51
52
+function isActionableDiagnostic(detail: CompilerErrorDetailOptions) {
53
+ switch (detail.severity) {
54
+ case ErrorSeverity.InvalidReact:
55
+ case ErrorSeverity.InvalidJS:
56
+ return true;
57
+ case ErrorSeverity.InvalidConfig:
58
+ case ErrorSeverity.Invariant:
59
+ case ErrorSeverity.CannotPreserveMemoization:
60
+ case ErrorSeverity.Todo:
61
+ return false;
62
+ default:
63
+ throw new Error("Unhandled error severity");
64
+ }
65
+}
66
+
67
function compile(sourceCode: string, filename: string) {
68
try {
69
runReactForgetBabelPlugin(
@@ -91,7 +113,7 @@ async function main() {
113
}
114
115
console.log(`Successful compilation: ${SUCCESS.length}`);
94
- console.log(`Failed compilation: ${FAILURES.length}`);
116
+ console.log(`Failed compilation: ${ACTIONABLE_FAILURES.length}`);
117
}
118
119
main();