@samitouri / QOS-React-1 / commits / 61aa159086

[compiler] Fix up prettier

Our prettier setup is all messed up after the merge, so this PR should fix things ghstack-source-id: f825460ea6637138db6ba08fd6136fac3f7aa001 Pull Request resolved: https://github.com/facebook/react/pull/29213

Lauren Tan committed May 29, 2024 at 11:41 UTC 61aa159086b1a4f1dda987fc4b40e6396d05c5cd
16 files changed +59 -162
.github/workflows/compiler-typescript.yml
+20 -2
@@ -24,6 +24,25 @@ jobs:
24 run: echo "matrix=$(find packages -mindepth 1 -maxdepth 1 -type d | sed 's!packages/!!g' | tr '\n' ',' | sed s/.$// | jq -Rsc '. / "," - [""]')" >> $GITHUB_OUTPUT
25
26 # Hardcoded to improve parallelism for babel-plugin-react-compiler
27 + prettier:
28 + name: Run prettier
29 + runs-on: ubuntu-latest
30 + steps:
31 + - uses: actions/checkout@v4
32 + - uses: actions/setup-node@v4
33 + with:
34 + node-version: 18.x
35 + cache: "yarn"
36 + cache-dependency-path: compiler/yarn.lock
37 + - name: Restore cached node_modules
38 + uses: actions/cache@v4
39 + with:
40 + path: "**/node_modules"
41 + key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
42 + - run: yarn install --frozen-lockfile
43 + - run: yarn prettier:ci
44 +
45 + # Hardcoded to improve parallelism
46 lint:
47 name: Lint babel-plugin-react-compiler
48 runs-on: ubuntu-latest
@@ -40,10 +59,9 @@ jobs:
59 path: "**/node_modules"
60 key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
61 - run: yarn install --frozen-lockfile
43 - - run: yarn workspace babel-plugin-react-compiler prettier:ci
62 - run: yarn workspace babel-plugin-react-compiler lint
63
46 - # Hardcoded to improve parallelism for babel-plugin-react-compiler
64 + # Hardcoded to improve parallelism
65 jest:
66 name: Jest babel-plugin-react-compiler
67 runs-on: ubuntu-latest
compiler/.eslintrc.js renamed
+2 -1
@@ -82,11 +82,12 @@ module.exports = {
82 ],
83 "@typescript-eslint/array-type": ["error", { default: "generic" }],
84 "@typescript-eslint/triple-slash-reference": "off",
85 + "@typescript-eslint/no-var-requires": "off"
86 },
87 parser: "@typescript-eslint/parser",
88 plugins: ["@typescript-eslint"],
89 root: true,
89 - ignorePatterns: ["src/__tests__/**/*", "src/**/*.d.ts", "dist/**/*"],
90 + ignorePatterns: ["**/__tests__/**/*", "**/*.d.ts", "**/dist/**/*"],
91 env: {
92 node: true,
93 },
compiler/.prettierignore
+14 -5
@@ -1,12 +1,21 @@
1 -.fixtures/
2 -bench/
1 **/dist
2 **/__tests__/fixtures/**/*.expect.md
3 **/__tests__/fixtures/**/*.flow.js
4 **/.next
7 -test262/
8 -*.md
5 +
6 +crates
7 +apps/playground/public
8 +
9 +**/LICENSE
10 +.*
11 +*.md*
12 *.json
13 *.css
14 *.webmanifest
12 -packages/js-fuzzer
\ No newline at end of file
15 +*.map
16 +*.sh
17 +*.txt
18 +*.ico
19 +*.svg
20 +*.lock
21 +*.toml
compiler/.prettierrc.js new
+9
@@ -0,0 +1,9 @@
1 +const config = {
2 + requirePragma: false,
3 + parser: "babel-ts",
4 + semi: true,
5 + singleQuote: false,
6 + trailingComma: "es5"
7 +}
8 +
9 +module.exports = config;
compiler/.prettierrc.json deleted
-4
@@ -1,4 +0,0 @@
1 -{
2 - "requirePragma": false,
3 - "parser": "babel-ts"
4 -}
compiler/package.json
+3
@@ -24,6 +24,8 @@
24 "build": "yarn workspaces run build",
25 "dev": "concurrently --kill-others -n compiler,runtime,playground \"yarn workspace babel-plugin-react-compiler run build --watch\" \"yarn workspace react-compiler-runtime run build --watch\" \"wait-on packages/babel-plugin-react-compiler/dist/index.js && yarn workspace playground run dev\"",
26 "test": "yarn workspaces run test",
27 + "prettier:write": "prettier --write . --log-level=warn",
28 + "prettier:ci": "prettier --check . --log-level=warn",
29 "snap": "yarn workspace babel-plugin-react-compiler run snap",
30 "snap:build": "yarn workspace snap run build",
31 "postinstall": "perl -p -i -e 's/react\\.element/react.transitional.element/' packages/snap/node_modules/fbt/lib/FbtReactUtil.js && perl -p -i -e 's/didWarnAboutUsingAct = false;/didWarnAboutUsingAct = true;/' packages/babel-plugin-react-compiler/node_modules/react-dom/cjs/react-dom-test-utils.development.js",
@@ -40,6 +42,7 @@
42 "concurrently": "^7.4.0",
43 "folder-hash": "^4.0.4",
44 "ora": "5.4.1",
45 + "prettier": "^3.2.5",
46 "prompt-promise": "^1.0.3",
47 "rollup": "^4.13.2",
48 "rollup-plugin-banner2": "^1.2.3",
compiler/packages/babel-plugin-react-compiler/.prettierignore deleted
-5
@@ -1,5 +0,0 @@
1 -**/dist
2 -**/__tests__/fixtures/**/*.expect.md
3 -**/__tests__/fixtures/**/*.flow.js
4 -*.md
5 -*.json
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/.prettierrc.json deleted
-4
@@ -1,4 +0,0 @@
1 -{
2 - "requirePragma": false,
3 - "parser": "babel-ts"
4 -}
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/package.json
-4
@@ -15,9 +15,6 @@
15 "snap:build": "yarn workspace snap run build",
16 "snap:ci": "yarn snap:build && yarn snap",
17 "ts:analyze-trace": "scripts/ts-analyze-trace.sh",
18 - "prettier": "node ./scripts/prettier.js write-changed",
19 - "prettier:all": "node ./scripts/prettier.js write",
20 - "prettier:ci": "prettier --check .",
18 "lint": "yarn eslint src"
19 },
20 "dependencies": {
@@ -53,7 +50,6 @@
50 "glob": "^7.1.6",
51 "jest": "^29.0.3",
52 "jest-environment-jsdom": "^29.0.3",
56 - "prettier": "2.8.8",
53 "react": "19.0.0-beta-b498834eab-20240506",
54 "react-dom": "19.0.0-beta-b498834eab-20240506",
55 "rimraf": "^3.0.2",
compiler/packages/babel-plugin-react-compiler/scripts/prettier.js deleted
-79
@@ -1,79 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -
8 -"use strict";
9 -
10 -/*
11 - * Based on similar script in React
12 - * https://github.com/facebook/react/blob/main/scripts/prettier/index.js
13 - */
14 -
15 -const chalk = require("chalk");
16 -const glob = require("glob");
17 -const prettier = require("prettier");
18 -const fs = require("fs");
19 -const listChangedFiles = require("./shared/list-changed-files");
20 -const prettierConfigPath = require.resolve("../.prettierrc");
21 -
22 -const mode = process.argv[2] || "check";
23 -const shouldWrite = mode === "write" || mode === "write-changed";
24 -const onlyChanged = mode === "check-changed" || mode === "write-changed";
25 -
26 -const changedFiles = onlyChanged ? listChangedFiles() : null;
27 -let didWarn = false;
28 -let didError = false;
29 -
30 -const files = glob
31 - .sync("**/*.{js,ts,tsx,jsx}", {
32 - ignore: ["**/node_modules/**", "**/__tests__/fixtures/**/*.flow.js"],
33 - })
34 - .filter((f) => !onlyChanged || changedFiles.has(f));
35 -if (!files.length) {
36 - return;
37 -}
38 -
39 -files.forEach((file) => {
40 - const options = prettier.resolveConfig.sync(file, {
41 - config: prettierConfigPath,
42 - });
43 - try {
44 - const input = fs.readFileSync(file, "utf8");
45 - if (shouldWrite) {
46 - const output = prettier.format(input, options);
47 - if (output !== input) {
48 - fs.writeFileSync(file, output, "utf8");
49 - }
50 - } else {
51 - if (!prettier.check(input, options)) {
52 - if (!didWarn) {
53 - console.log(
54 - "\n" +
55 - chalk.red(
56 - ` This project uses prettier to format all JavaScript code.\n`
57 - ) +
58 - chalk.dim(` Please run `) +
59 - chalk.reset("yarn prettier:all") +
60 - chalk.dim(
61 - ` and add changes to files listed below to your commit:`
62 - ) +
63 - `\n\n`
64 - );
65 - didWarn = true;
66 - }
67 - console.log(file);
68 - }
69 - }
70 - } catch (error) {
71 - didError = true;
72 - console.log("\n\n" + error.message);
73 - console.log(file);
74 - }
75 -});
76 -
77 -if (didWarn || didError) {
78 - process.exitCode = 1;
79 -}
compiler/packages/babel-plugin-react-compiler/scripts/shared/list-changed-files.js deleted
-39
@@ -1,39 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -
8 -"use strict";
9 -
10 -const execFileSync = require("child_process").execFileSync;
11 -
12 -const exec = (command, args) => {
13 - console.log("> " + [command].concat(args).join(" "));
14 - const options = {
15 - cwd: process.cwd(),
16 - env: process.env,
17 - stdio: "pipe",
18 - encoding: "utf-8",
19 - };
20 - return execFileSync(command, args, options);
21 -};
22 -
23 -const execGitCmd = (args) => exec("git", args).trim().toString().split("\n");
24 -
25 -const listChangedFiles = () => {
26 - const mergeBase = execGitCmd(["merge-base", "HEAD", "main"]);
27 - return new Set([
28 - ...execGitCmd([
29 - "diff",
30 - "--name-only",
31 - "--relative",
32 - "--diff-filter=ACMRTUB",
33 - mergeBase,
34 - ]),
35 - ...execGitCmd(["ls-files", "--others", "--exclude-standard"]),
36 - ]);
37 -};
38 -
39 -module.exports = listChangedFiles;
compiler/packages/make-read-only-util/package.json
-1
@@ -17,7 +17,6 @@
17 "@types/jest": "^28.1.6",
18 "@types/node": "^20.2.5",
19 "jest": "^28.1.3",
20 - "prettier": "2.8.8",
20 "ts-jest": "^28.0.7",
21 "ts-node": "^10.9.2"
22 }
compiler/packages/snap/package.json
-2
@@ -31,7 +31,6 @@
31 "glob": "^10.3.10",
32 "hermes-parser": "^0.19.1",
33 "jsdom": "^22.1.0",
34 - "prettier": "2.8.8",
34 "react": "19.0.0-beta-b498834eab-20240506",
35 "react-dom": "19.0.0-beta-b498834eab-20240506",
36 "readline": "^1.3.0",
@@ -50,7 +49,6 @@
49 "@types/node": "^18.7.18",
50 "@typescript-eslint/eslint-plugin": "^7.4.0",
51 "@typescript-eslint/parser": "^7.4.0",
53 - "prettier": "2.8.8",
52 "rimraf": "^3.0.2"
53 },
54 "resolutions": {
compiler/packages/snap/src/compiler.ts
+5 -5
@@ -271,8 +271,8 @@ function getEvaluatorPresets(
271 );
272 return presets;
273 }
274 -function format(inputCode: string, language: "typescript" | "flow"): string {
275 - return prettier.format(inputCode, {
274 +async function format(inputCode: string, language: "typescript" | "flow"): Promise<string> {
275 + return await prettier.format(inputCode, {
276 semi: true,
277 parser: language === "typescript" ? "babel-ts" : "flow",
278 });
@@ -288,13 +288,13 @@ export type TransformResult = {
288 } | null;
289 };
290
291 -export function transformFixtureInput(
291 +export async function transformFixtureInput(
292 input: string,
293 fixturePath: string,
294 parseConfigPragmaFn: typeof ParseConfigPragma,
295 plugin: BabelCore.PluginObj,
296 includeEvaluator: boolean
297 -): { kind: "ok"; value: TransformResult } | { kind: "err"; msg: string } {
297 +): Promise<{ kind: "ok"; value: TransformResult } | { kind: "err"; msg: string }> {
298 // Extract the first line to quickly check for custom test directives
299 const firstLine = input.substring(0, input.indexOf("\n"));
300
@@ -398,7 +398,7 @@ export function transformFixtureInput(
398 return {
399 kind: "ok",
400 value: {
401 - forgetOutput: format(forgetOutput, language),
401 + forgetOutput: await format(forgetOutput, language),
402 evaluatorCode,
403 },
404 };
compiler/packages/snap/src/runner-worker.ts
+5 -5
@@ -33,16 +33,16 @@ export function clearRequireCache() {
33 });
34 }
35
36 -function compile(
36 +async function compile(
37 input: string,
38 fixturePath: string,
39 compilerVersion: number,
40 shouldLog: boolean,
41 includeEvaluator: boolean
42 -): {
42 +): Promise<{
43 error: string | null;
44 compileResult: TransformResult | null;
45 -} {
45 +}> {
46 const seenConsoleErrors: Array<string> = [];
47 console.error = (...messages: Array<string>) => {
48 seenConsoleErrors.push(...messages);
@@ -68,7 +68,7 @@ function compile(
68 // only try logging if we filtered out all but one fixture,
69 // since console log order is non-deterministic
70 toggleLogging(shouldLog);
71 - const result = transformFixtureInput(
71 + const result = await transformFixtureInput(
72 input,
73 fixturePath,
74 parseConfigPragma,
@@ -147,7 +147,7 @@ export async function transformFixture(
147 unexpectedError: null,
148 };
149 }
150 - const { compileResult, error } = compile(
150 + const { compileResult, error } = await compile(
151 input,
152 fixture.fixturePath,
153 compilerVersion,
compiler/yarn.lock
+1 -6
@@ -8423,16 +8423,11 @@ prelude-ls@~1.1.2:
8423 resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
8424 integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==
8425
8426 -prettier@*:
8426 +prettier@*, prettier@^3.2.5:
8427 version "3.2.5"
8428 resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
8429 integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
8430
8431 -prettier@2.8.8:
8432 - version "2.8.8"
8433 - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
8434 - integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
8435 -
8431 prettier@3.0.3:
8432 version "3.0.3"
8433 resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"