Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Codegen] Extract the buildSchema function in the parsers-commons.js #35158

Closed

Conversation

MaeIg
Copy link
Contributor

@MaeIg MaeIg commented Nov 1, 2022

Summary

This PR aims to extract the buildSchema function into parsers-commons that is shared between typescript and flow. It is a task of #34872:

Extract the buildSchema function (Flow, TypeScript) in the parsers-commons.js file to a top level buildSchema function which takes additional parameters to properly parse the content, get the config type and to build the schema, based on the language used.

Changelog

[Internal] [Changed] - Extract the buildSchema function in the parsers-commons.js

Test Plan

yarn test:
image

yarn flow:
image

yarn lint:
image

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 1, 2022
@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 1, 2022

Hello @cipolleschi,

I don't know what to do to move forward.

I extracted the buildSchema function and used the new parser which implements Parser interface. The problem is that ~15 tests do something like this:
image
image

I changed the buildSchema params so I would have to adapt the tests but parseFile has very few logic:
image

So, for me, parseFile should be moved to FlowParser and TypescriptParser (it seems easier to do it now rather than changing parseFile and all tests to respect new buildSchema interface). So we can do something like:

const schema = RealFlowParser.parsefile(`${FIXTURE_DIR}/${fixture}`);

instead of:

const schema = parseFile(
      `${FIXTURE_DIR}/${fixture}`,
      DeprecatedFlowParser.buildSchema,
    );

What do you think of that ?

For me the best plan is:

  1. I open a new PR to move parseFile in FlowParser and TypeScriptParser
  2. Once the new PR is merged, I rebase this branch on main and I adapt parseFile from FlowParser and TypeScriptParser
  3. All tests should pass and parseFile don't need to take 5 extra args to pass it to buildSchema 🎉

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job! 👏
I left a few comments to improve typing, but I love how we are putting code together.

packages/react-native-codegen/src/parsers/parser.js Outdated Show resolved Hide resolved
packages/react-native-codegen/src/parsers/flow/parser.js Outdated Show resolved Hide resolved
@cipolleschi
Copy link
Contributor

Could you also verify why it is failing in CI? 🙏

@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 1, 2022

Thanks the review! 😃 I will address the comments!

Could you also verify why it is failing in CI? 🙏

@cipolleschi I explained why it's failing here: #35158 (comment)
I would like to have your opinion on what I proposed when you have time to read it.

@MaeIg MaeIg force-pushed the refactor/extract-buildSchema-function branch from e9ed4ac to 656b486 Compare November 10, 2022 12:28
@cipolleschi
Copy link
Contributor

Hi @MaeIg, sorry for the long delay. :(

The plan sounds good and reasonable. parseFile is also general enough that we may be able not to repeat the implementation in the two parsers, but perhaps keep it as an high-level function in the parsers-commons.js file. What do you think?

The reason why I haven't suggested that is because I believe parseFile, with that signature and from that path, is used in some other files and potentially also internally. That's why it could be tricky to move it.

Could you create another pr with just that change? In that way, I can import it and see what get broken...

Thank you so much for this effort! 🙏

@cipolleschi
Copy link
Contributor

The fix for the circular references landed, so you can rebase, fix the conflict and we can push this forward! :D

MaeIg added a commit to MaeIg/react-native that referenced this pull request Nov 25, 2022
It avoid circular dependencies and it is temporary
It will be moved again in facebook#35158
MaeIg added a commit to MaeIg/react-native that referenced this pull request Nov 28, 2022
It avoid circular dependencies and it is temporary
It will be moved again in facebook#35158
MaeIg added a commit to MaeIg/react-native that referenced this pull request Nov 28, 2022
It avoid circular dependencies and it is temporary
It will be moved again in facebook#35158
MaeIg added a commit to MaeIg/react-native that referenced this pull request Nov 30, 2022
It avoid circular dependencies and it is temporary
It will be moved again in facebook#35158
MaeIg added a commit to MaeIg/react-native that referenced this pull request Dec 8, 2022
It avoid circular dependencies and it is temporary
It will be moved again in facebook#35158
facebook-github-bot pushed a commit that referenced this pull request Dec 13, 2022
…5318)

Summary:
This PR aims to extract  the parseFile function in the typescript and flow parsers.  This is to solve the problem described [here](#35158 (comment)) and help with the work done in #34872.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract the parseFile function in the typescript and flow parsers

Pull Request resolved: #35318

Test Plan:
yarn flow:
<img width="496" alt="image" src="https://user-images.githubusercontent.com/40902940/206518024-83084c3d-ab0d-4a04-810a-d40270add4b0.png">

yarn lint:
<img width="495" alt="image" src="https://user-images.githubusercontent.com/40902940/206518076-9e07eafe-db61-4c6e-8aaa-f92f190cf4f3.png">

yarn test:
<img width="389" alt="image" src="https://user-images.githubusercontent.com/40902940/206518118-5633b28c-b79b-4421-80f7-de1e03fb8ff2.png">

Reviewed By: cortinico

Differential Revision: D41248581

Pulled By: cipolleschi

fbshipit-source-id: f5b878a28a7de612fcdd1528f064b44f668503af
@cipolleschi
Copy link
Contributor

Hi @MaeIg! Could you please rebase this PR on top of main? 🙏 Thank you so much.

@MaeIg MaeIg changed the title Draft: [Codegen] Extract the buildSchema function in the parsers-commons.js [Codegen] Extract the buildSchema function in the parsers-commons.js Dec 24, 2022
@MaeIg MaeIg force-pushed the refactor/extract-buildSchema-function branch 2 times, most recently from 6d0ded2 to d7f8749 Compare December 24, 2022 18:21
@MaeIg
Copy link
Contributor Author

MaeIg commented Dec 24, 2022

Hello @cipolleschi,

Sorry for the delay, I was sick :/ I extracted the buildSchema function but there is a circular dependency. I will try to fix it next week!

@analysis-bot
Copy link

analysis-bot commented Dec 26, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: efd39ee
Branch: main

@analysis-bot
Copy link

analysis-bot commented Dec 26, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,464,380 +0
android hermes armeabi-v7a 7,784,752 +0
android hermes x86 8,937,785 +0
android hermes x86_64 8,796,124 +0
android jsc arm64-v8a 9,650,798 +0
android jsc armeabi-v7a 8,384,800 +0
android jsc x86 9,712,790 +0
android jsc x86_64 10,190,369 +0

Base commit: 66927ec
Branch: main

@pull-bot
Copy link

PR build artifact for b5df7e8 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for b5df7e8 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@MaeIg MaeIg force-pushed the refactor/extract-buildSchema-function branch 2 times, most recently from 35fee92 to 1ca77ee Compare December 26, 2022 21:36
@pull-bot
Copy link

PR build artifact for 1ca77ee is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 1ca77ee is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@cipolleschi
Copy link
Contributor

Sorry to bother, but it needs another rebase + conflict fixing. :(

@MaeIg MaeIg force-pushed the refactor/extract-buildSchema-function branch from 1ca77ee to ba1c5d1 Compare January 1, 2023 15:28
@MaeIg
Copy link
Contributor Author

MaeIg commented Jan 1, 2023

Sorry to bother, but it needs another rebase + conflict fixing. :(

Hello @cipolleschi , it's done! 😄

@pull-bot
Copy link

pull-bot commented Jan 1, 2023

PR build artifact for ba1c5d1 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

pull-bot commented Jan 1, 2023

PR build artifact for ba1c5d1 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this.

I left a few comment to simplify the code a bit. The main suggestion to implement, imho, is to have the parseModuleFixture call parseString rather then invoking the buildSchema directly.

Potentially, we can completely get rid of the index.js file.

@MaeIg MaeIg force-pushed the refactor/extract-buildSchema-function branch from ba1c5d1 to f575f2b Compare January 6, 2023 12:48
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 12, 2023
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in dc4d73c.

@MaeIg MaeIg deleted the refactor/extract-buildSchema-function branch January 12, 2023 12:38
facebook-github-bot pushed a commit that referenced this pull request Jan 25, 2023
…d flow parsers (#35928)

Summary:
This PR aims to extract parseString and parseModuleFixture functions into the typescript and flow parsers. This task was proposed in #35158 and helps #34872.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract parseString and parseModuleFixture functions in typescript and flow parsers

Pull Request resolved: #35928

Test Plan:
yarn test:
<img width="386" alt="image" src="https://user-images.githubusercontent.com/40902940/213889984-f0cadaff-4472-42d6-b55b-4901023aad1e.png">

yarn flow:
<img width="166" alt="image" src="https://user-images.githubusercontent.com/40902940/213889974-21ac2483-2731-4cb1-a2b5-195d98619649.png">

yarn lint:
<img width="514" alt="image" src="https://user-images.githubusercontent.com/40902940/213889980-090af354-346f-4a9c-90bc-7006899f0819.png">

Reviewed By: jacdebug

Differential Revision: D42673866

Pulled By: cipolleschi

fbshipit-source-id: f1b5f8a7b3944e7e8223b25c0fb9bf4e8b512aa7
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…cebook#35318)

Summary:
This PR aims to extract  the parseFile function in the typescript and flow parsers.  This is to solve the problem described [here](facebook#35158 (comment)) and help with the work done in facebook#34872.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract the parseFile function in the typescript and flow parsers

Pull Request resolved: facebook#35318

Test Plan:
yarn flow:
<img width="496" alt="image" src="https://user-images.githubusercontent.com/40902940/206518024-83084c3d-ab0d-4a04-810a-d40270add4b0.png">

yarn lint:
<img width="495" alt="image" src="https://user-images.githubusercontent.com/40902940/206518076-9e07eafe-db61-4c6e-8aaa-f92f190cf4f3.png">

yarn test:
<img width="389" alt="image" src="https://user-images.githubusercontent.com/40902940/206518118-5633b28c-b79b-4421-80f7-de1e03fb8ff2.png">

Reviewed By: cortinico

Differential Revision: D41248581

Pulled By: cipolleschi

fbshipit-source-id: f5b878a28a7de612fcdd1528f064b44f668503af
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…35158)

Summary:
This PR aims to extract  the buildSchema function into parsers-commons that is shared between typescript and flow. It is a task of facebook#34872:
> Extract the buildSchema function ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/index.js#L66), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/index.js#L72)) in the parsers-commons.js file to a top level buildSchema function which takes additional parameters to properly parse the content, get the config type and to build the schema, based on the language used.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract the buildSchema function in the parsers-commons.js

Pull Request resolved: facebook#35158

Test Plan:
yarn test:
<img width="380" alt="image" src="https://user-images.githubusercontent.com/40902940/209584411-40f66047-e25d-43d4-975d-af10cd202f24.png">

yarn flow:
<img width="150" alt="image" src="https://user-images.githubusercontent.com/40902940/209584423-4cf2cb5a-a300-40a6-962c-e57934f19ad2.png">

yarn lint:
<img width="510" alt="image" src="https://user-images.githubusercontent.com/40902940/209584440-2d2b2658-73d8-47e2-bb8c-64d4633369a2.png">

Reviewed By: cortinico

Differential Revision: D42386804

Pulled By: cipolleschi

fbshipit-source-id: 2a238f7cec982d8ef3fd57a34dc9f58171e32b53
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…d flow parsers (facebook#35928)

Summary:
This PR aims to extract parseString and parseModuleFixture functions into the typescript and flow parsers. This task was proposed in facebook#35158 and helps facebook#34872.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract parseString and parseModuleFixture functions in typescript and flow parsers

Pull Request resolved: facebook#35928

Test Plan:
yarn test:
<img width="386" alt="image" src="https://user-images.githubusercontent.com/40902940/213889984-f0cadaff-4472-42d6-b55b-4901023aad1e.png">

yarn flow:
<img width="166" alt="image" src="https://user-images.githubusercontent.com/40902940/213889974-21ac2483-2731-4cb1-a2b5-195d98619649.png">

yarn lint:
<img width="514" alt="image" src="https://user-images.githubusercontent.com/40902940/213889980-090af354-346f-4a9c-90bc-7006899f0819.png">

Reviewed By: jacdebug

Differential Revision: D42673866

Pulled By: cipolleschi

fbshipit-source-id: f1b5f8a7b3944e7e8223b25c0fb9bf4e8b512aa7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants