[fixtures] Run prettier after babel-plugin
This moves prettier formatting into fixture-test-utils instead, so we can remove the dependency on prettier in the babel plugin. I want to do this because I don't want to include prettier in the rolledup artifact when we build the babel plugin.
Lauren Tan committed
Oct 27, 2023 at 14:07 UTC
c72673bd8f1a6a47f8b403f5600959c6d92b1582
2 files changed
+11
-3
compiler/packages/fixture-test-utils/package.json
+1
-1
@@ -11,6 +11,7 @@
11
"dependencies": {
12
"@parcel/watcher": "^2.1.0",
13
"chalk": "4",
14
+ "prettier": "2.8.8",
15
"readline": "^1.3.0",
16
"typescript": "^5.1.0",
17
"yargs": "^17.7.1"
@@ -19,7 +20,6 @@
20
"@types/node": "^18.7.18",
21
"@typescript-eslint/eslint-plugin": "^5.51.0",
22
"@typescript-eslint/parser": "^5.51.0",
22
- "prettier": "2.8.8",
23
"rimraf": "^3.0.2"
24
}
25
}
compiler/packages/fixture-test-utils/src/compiler-utils.ts
+10
-2
@@ -3,6 +3,7 @@ import type { runReactForgetBabelPlugin as RunReactForgetBabelPlugin } from "bab
3
import { CompilationMode } from "babel-plugin-react-forget/src/Entrypoint";
4
import type { Effect, ValueKind } from "babel-plugin-react-forget/src/HIR";
5
import type { parseConfigPragma as ParseConfigPragma } from "babel-plugin-react-forget/src/HIR/Environment";
6
+import prettier from "prettier";
7
8
export function parseLanguage(source: string): "flow" | "typescript" {
9
return source.indexOf("@flow") !== -1 ? "flow" : "typescript";
@@ -58,8 +59,7 @@ export function transformFixtureInput(
59
};
60
}
61
const config = parseConfigPragmaFn(firstLine);
61
-
62
- return pluginFn(
62
+ const result = pluginFn(
63
input,
64
basename,
65
language,
@@ -107,4 +107,12 @@ export function transformFixtureInput(
107
},
108
includeAst
109
);
110
+
111
+ return {
112
+ ...result,
113
+ code: prettier.format(result.code, {
114
+ semi: true,
115
+ parser: language === "typescript" ? "babel-ts" : "flow",
116
+ }),
117
+ };
118
}