-
Notifications
You must be signed in to change notification settings - Fork 612
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
Add configuration option to suppress require cycle warnings #707
Conversation
c5202ac
to
540f82a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hsource this is awesome, thanks for the PR! There are some details to discuss but I love the idea of making this warning less noisy and more actionable.
- I would go further and ignore require cycles in
node_modules
by default. It's a safe assumption that users don't have direct control over cycles in third-party modules, and that code that's already published to npm was at least minimally tested so the warning is a false positive there. - I wouldn't limit the filtering capability to prefixes. How about changing this to accept regexes? (We can call it e.g.
requireCycleIgnorePatterns
.) That way we can check fornode_modules
anywhere in the project, not just at the root. - Let's make sure this works out of the box for Windows paths. One way would be to use regexes as per (2), and make the default pattern check for both forward and backward slashes around
node_modules
. - I wonder if we should check all the modules in a cycle against the patterns (and suppress the warning if there are any matches?) or whether checking just the first module is enough. We can start with the current solution, though.
`__IGNORE_REQUIRE_CYCLE_PREFIXES__=${JSON.stringify( | ||
ignoreRequireCyclePrefixes, | ||
)}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is dev-only, I would avoid injecting this variable if isDev
is false.
Also, let's make sure this name starts with __METRO
, e.g.
`__IGNORE_REQUIRE_CYCLE_PREFIXES__=${JSON.stringify( | |
ignoreRequireCyclePrefixes, | |
)}`, | |
`__METRO_IGNORE_REQUIRE_CYCLE_PREFIXES__=${JSON.stringify( | |
ignoreRequireCyclePrefixes, | |
)}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the latest change!
@motiz88 Thanks for the review and sorry for the delay. I had some spare time and just cleaned up this PR. I applied all of your changes. The default RegExp looks a bit messy, but I've verified that it works with both slashes and backslashes. Can you take another look? |
@hsource Thank you for your work 💚, any update on it? |
I think it's just awaiting a pull. @motiz88 or anyone else can take a look when they have time! |
@hsource bump? |
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Tests are failing because we verify that the transformed bundle parses as ES5 -
That's breaking on the |
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi @hsource - sorry for the delay with this and thanks again for the contribution. After I imported this we had some further review suggestions internally:
I made these changes over at robhogan@eeb286b but since it's a non-trivial change to the proposal I wanted to check with you before pushing to this branch. Am I ok to pull that change in to your PR here and re-import for review? |
@robhogan Yes! Go for it. Thanks a ton for improving on this |
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary
In many projects there are require cycles in the node_modules dependencies that don't really need to be fixed and that don't seem to affect the functioning of the app. This change adds an option to let users selectively suppress them.
Unlike many of the workarounds in #287, this requires opting in per-package, so that you're never blindsided by bugs caused by require cycles in subpackages you own or maintain.
Closes #287
Test plan
yarn build && yarn lerna run prepare-release
react-native start
with the extra config belowBefore
After
No warnings