Skip to content

[Codegen] Extract the parseFile function in the typescript and flow parsers#35318

Closed
MaeIg wants to merge 11 commits into
facebook:mainfrom
MaeIg:refactor/move-parseFile-in-parser
Closed

[Codegen] Extract the parseFile function in the typescript and flow parsers#35318
MaeIg wants to merge 11 commits into
facebook:mainfrom
MaeIg:refactor/move-parseFile-in-parser

Conversation

@MaeIg
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@cipolleschi
Copy link
Copy Markdown
Contributor

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

@MaeIg
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@cipolleschi
Copy link
Copy Markdown
Contributor

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

@MaeIg
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

PR build artifact for 6cede0d456f39e3c3c5d60012e5193ad6f250997 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
Copy Markdown

PR build artifact for 6cede0d456f39e3c3c5d60012e5193ad6f250997 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
@MaeIg MaeIg requested a review from cipolleschi November 28, 2022 16:58
Copy link
Copy Markdown
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.

Comment thread packages/eslint-plugin-specs/react-native-modules.js Outdated
Comment thread packages/react-native-codegen/src/parsers/typescript/buildSchema.js Outdated
@pull-bot
Copy link
Copy Markdown

PR build artifact for bf9f2f64817c5a4ddcf706a3b4f18c2a785d0e3a 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
Copy Markdown

PR build artifact for bf9f2f64817c5a4ddcf706a3b4f18c2a785d0e3a 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
@MaeIg MaeIg requested a review from cipolleschi November 28, 2022 19:10
@pull-bot
Copy link
Copy Markdown

PR build artifact for eabd58db6202b9048c6b169cc19dc04b4f2c4b99 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
Copy Markdown

PR build artifact for eabd58db6202b9048c6b169cc19dc04b4f2c4b99 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
Copy Markdown
Contributor

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

@cipolleschi
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

PR build artifact for 6de5740cee0d3c21e001f84ca15f906eda1efb33 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
Copy Markdown

PR build artifact for 6de5740cee0d3c21e001f84ca15f906eda1efb33 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 added 11 commits December 8, 2022 17:49
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
Contributor

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

@github-actions
Copy link
Copy Markdown

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