-
Notifications
You must be signed in to change notification settings - Fork 58
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
Change public exports shape #53
Conversation
caccdf4
to
61e9fda
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.
@Andarist Thanks for this PR! I'm taking over from David since he isn't maintaining this, or focus-trap
, or focus-trap-react
anymore. I'm all for making this module more compatible with tree-shaking. I'd just request to not use default exports at all. If you're OK with that, please also update the README changes you're making in order to reflect that.
Also, what, in your opinion, is still missing in this to fully address #39?
src/index.js
Outdated
export default tabbable; | ||
export { isTabbable, isFocusable }; |
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 we bundle as CJS also, I'd like to avoid potential bundling issues and not have a default export. Could we just export all functions as export { tabbable, isTabbable, isFocusable }
?
Rollup actually considers it a bad practice to mix named and default exports in the same module. I'd rather avoid them. 😄
I would have to review this, can do that later this week.
Sure, you can go with named exports only route. |
# Conflicts: # test/tabbable.test.js
Ok, I've adjusted the PR according to your comments - please take a look.
|
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.
This is looking good, thanks for updating to only named exports. What about also marking the module as side-effect-free with sideEffects: false
in package.json? Wouldn't that also help (when using bundlers like Webpack that support it)?
I don't understand this one. Because of the
I'm not seeing how |
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.
This all looks good WRT changing the public exports shape!
Only to some extent - this only helps for ignoring imported files and as you only distribute a single file, it doesn't bring that much value. I would have to recheck but maybe it would help in such a case: // foo.js
import { tabbable } from 'tabbable'
export function A() {
tabbable()
}
export function B() {
console.log()
}
// entry.js
import { B } from './foo'
console.log(B) but it wouldn't help cases like this: // entry.js
import { isTabbable } from 'tabbable'
console.log(isTabbable) If anything gets required from
Yes. Tools don't know what
Like in the first scenario that I have included in this post. It's about transitive dependencies. Tree-shaking (in my opinion) is not purely about scenarios when your library gets actually used but also about scenarios when it stays unused. Like when a |
@Andarist Thanks for taking the time to answer my 3 questions, that's very helpful. This will be good to help with #39. I do think that it would be worth adding Might as well add the |
Why?
Improving tree-shakeability of this package. Usage of static properties like this usually retains the containing object (in this case a function) even if it stays unused. This matters when
tabbable
is being used as transitive dep.Partially fixes #39