-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 external imports whitelist logic to nx-enforce-module-boundaries (i.e. allowedExternalImports option) #12870
Comments
Thanks @yjaaidi, After thinking more about this, I think it makes sense. Despite having the possibility to use regex, I think that would be too complex for most folks. We need something that is simple and easy to read, and Please note that |
Feel free to implement this feature and ping me if you need any help. |
Cool! I'll submit a PR as soon as I can... expect some questions 😊 First one is about your remark:
Is this related to |
True, it doesn't matter in the opposite direction. Sorry for the confusion |
Hey @yjaaidi, do you plan to work on this? |
Hey @meeroslav! Yes ! Sorry that I couldn't take care of it before. I'll take care of by next week. |
eslint's enforce-module-boundaries' allowedExternalImports option will only allow the project to import npm packages matching the string or wildcard nrwl#12870
eslint's enforce-module-boundaries' allowedExternalImports option will only allow the project to import npm packages matching the string or wildcard Closes nrwl#12870
Hey @meeroslav! I finally managed to take some time and send a PR #13891 🎉 I was about to send a distinct PR for the docs as I thought that this would require a major rewrite of the "Ban External Imports" recipe but I managed to just add a chapter at the end with some examples. Let me know what you think of this and if you want me to squash everything. Good job for the |
Implemented with #13891 |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Description
nx-enforce-module-boundaries
should allow a deny-all + whitelist logic in addition to the blacklist logic.Motivation
There are use cases where users might need more restrictive rules and only whitelist some external imports instead of explicitly banning them.
Here is one, when implementing something similar hexagonal, onion, or clean architecture, it is safer to use whitelists.
For instance, a library tagged as "type:core" will not be able to import anything using something like this
allowedExternalImports: []
, while a "platform:backend" & "type:data-access" will be allowed to use libraries that can communicate with databases or remote services:allowedExternalImports: ['mongo', '@google-cloud/*', ...]
or something like this.Suggested Implementation
We could implement this using an
allowedExternalImports
orwhitelistedExternalImports
option.allowedExternalImports
is exclusive withbannedExternalImports
. We can't use both on the same rule.Alternate Implementations
Meanwhile, here is the workaround:
Special thanks @meeroslav for the hint 😉
cf. #6727 (comment)
cc. @mlebarron
The text was updated successfully, but these errors were encountered: