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 parseFile function in the typescript and flow parsers #35318

Closed
wants to merge 11 commits into from

Conversation

MaeIg
Copy link
Contributor

@MaeIg MaeIg commented Nov 12, 2022

Summary

This PR aims to extract the parseFile function in the typescript and flow parsers. This is to solve the problem described here and help with the work done in #34872.

Changelog

[Internal] [Changed] - Extract the parseFile function in the typescript and flow parsers

Test Plan

yarn flow:
image

yarn lint:
image

yarn test:
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 12, 2022
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.

There are many changes on several files, but it looks very good to me. I like that we are centralizing the shared logic in a specific object.

Thank you so much for taking care of this.

@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.

@cipolleschi
Copy link
Contributor

There is a problem with the BUCK tests, though... :/

@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 12, 2022

I think there is a circular dependency problem :/

When running NODE_OPTIONS="--trace-warnings" yarn lint:
image

@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 12, 2022

There is a problem with the BUCK tests, though... :/

@cipolleschi, I investigated a bit and I think the errors come from circular imports:

  1. In FlowParser, we import buildSchema from packages/react-native-codegen/src/parsers/flow/index.js
  2. In this file, we import buildModuleSchema from packages/react-native-codegen/src/parsers/flow/modules/index.js
  3. In this file, we import FlowParser

It will be solved in #35147. But, I think the problem can come back later and I don't know how to fix it.

Do you know how we could avoid these circular imports? Aren't we importing the parser in too many places? Or, maybe moving parseFile into the FlowParser/Typescript parser was just a bad idea.

@Pranav-yadav

This comment was marked as outdated.

@cipolleschi
Copy link
Contributor

The circular dependency problem has landed on main, you can safely rebase on it and it should fix the problems!

@cipolleschi
Copy link
Contributor

Hi @MaeIg, could you rebase this, whenever you have some time, please? 🙏

@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 18, 2022

Hi @MaeIg, could you rebase this, whenever you have some time, please? 🙏

Hi, sorry I was pretty busy this week. I will do it tomorrow!

@MaeIg MaeIg force-pushed the refactor/move-parseFile-in-parser branch from ad6b929 to f28b428 Compare November 20, 2022 22:31
@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 20, 2022

I rebased but there is still a circular dependency:
image
(there is the same for typescript)

It seems complicated to undo these circular dependencies. I wonder if it's time to extract parseFile in the parser. Maybe I should do the other task without it.

@cipolleschi
Copy link
Contributor

What if we don't require the FlowParser in the flow/module/index.js file, but we just pass it as a parameter to the methods that need it? 🤔 We can just import type, if we want to be stricter with the types, or just ask for a Parser. At this point, the parsers/index.js module can create the FlowParser and pass it to the methods but we break the require depenencies.
What do you think?

@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 21, 2022

What if we don't require the FlowParser in the flow/module/index.js file, but we just pass it as a parameter to the methods that need it? 🤔 We can just import type, if we want to be stricter with the types, or just ask for a Parser. At this point, the parsers/index.js module can create the FlowParser and pass it to the methods but we break the require depenencies. What do you think?

I will try to do it. It will make a lot of changes but this rule should avoid circular dependencies in the future!

@Pranav-yadav

This comment was marked as resolved.

@cipolleschi
Copy link
Contributor

@Pranav-yadav, sorry if I reply here and I haven't replied in the other PR. I understand what you say and it makes a lot of sense. I'm quite scared about how big the file will ends up. It could become very hard to read an navigate. 🤔 That's the main reason why I was pushing to keep the files separated.

However, we currently have a different circular dependency: it is not related to parsers-commons and -primitives but to the Parser itself and the index files.

@MaeIg MaeIg force-pushed the refactor/move-parseFile-in-parser branch from f28b428 to cb0a6be Compare November 25, 2022 12:09
@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 25, 2022

Hi @cipolleschi,

After a hard fight I ended up overcoming these circular dependencies! 🎉

I recommend you to review commit by commit to understand well the refacto 😃

Here's a diagram I created to understand what to do. Maybe it can help you to review!
rn-circular-deps

@analysis-bot
Copy link

analysis-bot commented Nov 25, 2022

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

Base commit: 48966eb
Branch: main

@analysis-bot
Copy link

analysis-bot commented Nov 25, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,110,479 +0
android hermes armeabi-v7a 6,479,306 +0
android hermes x86 7,529,356 +0
android hermes x86_64 7,387,603 +0
android jsc arm64-v8a 8,976,992 +0
android jsc armeabi-v7a 7,708,149 +0
android jsc x86 9,040,016 +0
android jsc x86_64 9,517,383 +0

Base commit: 48966eb
Branch: main

@pull-bot
Copy link

PR build artifact for 6cede0d 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 6cede0d 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/move-parseFile-in-parser branch from 6cede0d to bf9f2f6 Compare November 28, 2022 16:56
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.

Hi @MaeIg, thank you endlessly for taking care of this and for all these changes. 🙏

I left some comments to improve this even further, but it already looks extremely good to me.

@pull-bot
Copy link

PR build artifact for bf9f2f6 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 bf9f2f6 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/move-parseFile-in-parser branch from bf9f2f6 to eabd58d Compare November 28, 2022 18:52
@pull-bot
Copy link

PR build artifact for eabd58d 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 eabd58d 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.

@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.

@cipolleschi
Copy link
Contributor

This PR needs some changes internally. Unfortunately, I don't think I'll be able to to them today, so we will merge it in a week. I'm sorry for this. :(

@MaeIg MaeIg force-pushed the refactor/move-parseFile-in-parser branch from eabd58d to 6de5740 Compare November 30, 2022 16:24
@MaeIg
Copy link
Contributor Author

MaeIg commented Nov 30, 2022

This PR needs some changes internally. Unfortunately, I don't think I'll be able to to them today, so we will merge it in a week. I'm sorry for this. :(

No problem. Take your time and feel free to ping me if there is anything I can do! :)

I rebased on main!

@pull-bot
Copy link

PR build artifact for 6de5740 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 6de5740 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.

It is already accessible in parser
It avoid circular dependencies and it is temporary
It will be moved again in facebook#35158
At least I tried...
There were still circular dependencies...
(node:58076) Warning: Accessing non-existent property 'getTypes' of module exports inside circular dependency
(node:58076) Warning: Accessing non-existent property 'getValueFromTypes' of module exports inside circular dependency
(node:58076) Warning: Accessing non-existent property 'getValueFromTypes' of module exports inside circular dependency
(node:58076) Warning: Accessing non-existent property 'buildModuleSchema' of module exports inside circular dependency
@MaeIg MaeIg force-pushed the refactor/move-parseFile-in-parser branch from 6de5740 to 29505f7 Compare December 8, 2022 17:08
@MaeIg
Copy link
Contributor Author

MaeIg commented Dec 8, 2022

Hello 👋
I rebased and resolved conflicts. Feel free to ping me if there is anything I can do

@pull-bot
Copy link

pull-bot commented Dec 8, 2022

PR build artifact for 29505f7 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 Dec 8, 2022

PR build artifact for 29505f7 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.

@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.

@github-actions
Copy link

This pull request was successfully merged by @MaeIg in 3f2691c.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Dec 13, 2022
@MaeIg MaeIg deleted the refactor/move-parseFile-in-parser branch December 14, 2022 19:57
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
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.

6 participants