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

fix: Run flutter analyze for flutter packages #793

Merged
merged 3 commits into from
Nov 16, 2024

Conversation

mnayef95
Copy link
Contributor

Description

Current melos analyze command is running dart analyze instead of flutter analyze on flutter projects
#792

Type of Change

  • feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

Copy link

docs-page bot commented Nov 15, 2024

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/melos~793

Documentation is deployed and generated using docs.page.

@CLAassistant
Copy link

CLAassistant commented Nov 15, 2024

CLA assistant check
All committers have signed the CLA.

@spydon
Copy link
Collaborator

spydon commented Nov 15, 2024

How come you need to run flutter analyze instead of dart analyze? It should result in the same warnings/errors?

@mahmuttaskiran
Copy link
Contributor

How come you need to run flutter analyze instead of dart analyze? It should result in the same warnings/errors?

Let me clarify. For Flutter projects using Melos, when neither melos bootstrap nor flutter pub get is executed for the packages, dart analyze will fail. This happens because it does not run pub get, and since dependencies are not resolved, dart analyze complains about import statements that refer to any unresolved dependencies. (This is just one case; there can be many others, such as referring to a class that belongs to a dependency.)

However, flutter analyze ensures that pub get is executed before running the analysis, which resolves this issue.

You can reproduce this issue in any Flutter repository using Melos by running melos clean and then attempting to analyze the code without bootstrapping the packages.


Note: With this fix, do not try to reproduce this issue and understand the problem in the Melos repository itself, as it is not a Flutter workspace and will always use dart analyze, which does not run pub get.

@mnayef95
Copy link
Contributor Author

mnayef95 commented Nov 15, 2024

Hello @spydon, I hope you are doing well. According to the Flutter documentation, we should use flutter analyze instead of dart analyze for flutter projects. Additionally, as stated by @mahmuttaskiran, flutter analyze will also run pub get, making it unnecessary to run bootstrap—especially for large projects with over 100 packages.

Screenshot 2024-11-15 at 5 19 32 PM

@mnayef95 mnayef95 changed the title Check if the workspace is flutter & run flutter analyze instead of dart analyze fix: Check if the workspace is flutter & run flutter analyze instead of dart analyze Nov 15, 2024
@mnayef95 mnayef95 force-pushed the enhancement/analyze branch from 1f69aef to adb6939 Compare November 15, 2024 13:29
@spydon
Copy link
Collaborator

spydon commented Nov 15, 2024

Hello @spydon, I hope you are doing well. According to the Flutter documentation, we should use flutter analyze instead of dart analyze for flutter projects. Additionally, as stated by @mahmuttaskiran, flutter analyze will also run pub get, making it unnecessary to run bootstrap—especially for large projects with over 100 packages.

Screenshot 2024-11-15 at 5 19 32 PM

If that is the case that flutter analyze is recommended over dart analyze for flutter projects (which isn't actually stated in the docs like you say), we should also follow it the other way around, Dart packages should be using dart analyze. But in this PR flutter will be used for all pure dart packages too if there is a flutter package present in the repo.

@spydon
Copy link
Collaborator

spydon commented Nov 15, 2024

For Flutter projects using Melos, when neither melos bootstrap nor flutter pub get is executed for the packages, dart analyze will fail.

If you don't run bootstrap your monorepo won't be properly set up anyways, so interdependencies in the repo will resolve to pub instead of to their local counterparts, so that dart analyze doesn't run pub get is not concerning imo.

@mnayef95
Copy link
Contributor Author

@spydon

If that is the case that flutter analyze is recommended over dart analyze for flutter projects (which isn't actually stated in the docs like you say), we should also follow it the other way around, Dart packages should be using dart analyze. But in this PR flutter will be used for all pure dart packages too if there is a flutter package present in the repo.

They are saying use instead of dart analyze as stated in the screenshot, we can change it to run flutter analyze for flutter packages and dart analyze for dart packages if you agree to the proposed solution

If you don't run bootstrap your monorepo won't be properly set up anyways, so interdependencies in the repo will resolve to pub instead of to their local counterparts, so that dart analyze doesn't run pub get is not concerning IMO.

We are working on a substantial project that includes 287 packages. In our CI pipeline, we run static analysis as a separate job parallel to other tasks like unit testing and application building. To minimize CI time, we prefer not to execute melos bootstrap specifically for the static analysis job, as it has previously increased our CI time when we tried it.

To address this, we have opted to use flutter analyze instead of dart analyze. Our current solution is:

melos exec -- flutter analyze

While this works, we would prefer to achieve the same outcome using melos analyze.

@spydon
Copy link
Collaborator

spydon commented Nov 15, 2024

They are saying use instead of dart analyze as stated in the screenshot

Sorry, my bad. I still don't think there is a difference anymore though more than that it runs pub get and that if you haven't defined a analysis options file it defaults to different rulesets, but I have checked with some others if they know.

To minimize CI time, we prefer not to execute melos bootstrap specifically for the static analysis job, as it has previously increased our CI time when we tried it.

Are your packages not using each other in your repository? If they are and you aren't manually setting path dependencies you won't be running static analysis properly on the actual state of the repo, since it will be pulling down released versions instead.

@spydon
Copy link
Collaborator

spydon commented Nov 15, 2024

Sorry, my bad. I still don't think there is a difference anymore though more than that it runs pub get and that if you haven't defined an analysis options file it defaults to different rulesets, but I have checked with some others if they know.

Apparently it is doing some platform specific stuff too, so it could indeed be worth running it instead of dart analyze, but then it should probably still run dart analyze for dart packages. So if you are relying on pub get to run for your dart packages too that wouldn't solve your problem.

Once the workspace feature from the pub team has been released it won't be a problem anymore though.

@mnayef95
Copy link
Contributor Author

Are your packages not using each other in your repository? If they are and you aren't manually setting path dependencies you won't be running static analysis properly on the actual state of the repo, since it will be pulling down released versions instead.

Yes, the packages are interdependent, and we are using path dependencies. We tried running flutter analyze and dart analyze. dart analyze fails because some URIs can't be resolved unless pub get is run first, so we tried flutter analyze, and it worked as it will do pub get and that what we need for static analysis CI step.

I've updated the PR to include the check for Dart packages. I don't think it's an optimal solution, but it's what I could do with the current implementation.

@mnayef95 mnayef95 changed the title fix: Check if the workspace is flutter & run flutter analyze instead of dart analyze fix: Run flutter analyze instead of dart analyze on flutter packages Nov 15, 2024
Copy link
Collaborator

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm, thanks for your contribution!

@spydon spydon changed the title fix: Run flutter analyze instead of dart analyze on flutter packages fix: Run flutter analyze for flutter packages Nov 16, 2024
@spydon spydon merged commit e804822 into invertase:main Nov 16, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants