-
Notifications
You must be signed in to change notification settings - Fork 84
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
Avoid circular dependencies #645
Conversation
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.
Hey @fubhy, while we have them, we might just as well make use of the barrels to make our own imports slightly more readable.
But the import you describe in #644 is a bug. I pushed up a commit that disallows cyclic imports via an eslint plugin.
It looks like one import got left behind 🙂
src/protocol-connect/validate-response.ts(76,22): error TS2304: Cannot find name 'Compression'
Hi @timostamm! Definitely your call but personally I'd still recommend to avoid barrel files internally. Especially given the excellent code navigation tools in the IDE landscape these days I personally prefer explicit direct imports instead of opaque More significantly, In addition to the risk of accidentally introducing circular dependencies (which can be avoided with linting rules indeed), I've also seen weird behavior with bundlers in the past. Code splitting in particular. |
(That said, I'm happy to revert those changes if you'd prefer to keep the barrel file imports regardless.) |
TL;DR Disadvantages:
... That's probably not all. Will add more here if more comes to mind ;-) |
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.
Make sure to run make bench
, the changes will affect the code size benchmark.
Making it tougher for bundlers to process & optimize things
Would be interested to know what situation that was.
IDEs now offer multiple options for importing the same symbol.
I'm aware, believe me 😆. But we're okay as long as the DX for the user is good.
Co-authored-by: Timo Stamm <ts@timostamm.de>
Painfully aware? :-P Yeah... It's not the end of the world but it does annoy me sometimes.
Found it. The problem was with wildcard imports / exports. Code splitting doesn't (didn't?) work with SWC in a Next.js project with those. Even with Anyways, I'm happy with whatever you want to accept within the scope of this PR. Just thought I'd share my opinion ;-) |
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.
The problem was with wildcard imports / exports
👍 I'm not sure it's relevant for users of connect-es, but it doesn't hurt to be cautious. We'd also love to idiomatically support Deno at some point, so this is the right direction.
The browserstack test failure is expected on a fork. The tests passed locally. LGTM.
Thank you for the fix 🙂
Fixes #644
This removes internal imports from barrel files throughout.