-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
Export core events constants as named exports #5186
Conversation
The solution here provides backwards compatibility with what the CommonJS module was providing but it's a bit bulky and kinda weird. If I were to choose a cleaner solution it would be to not export the enum and instead only have named exports. This would allow consumers to do either of these: import * as Events from '@storybook/core-events';
import { FOO } from '@storybook/core-events'; The downside is that it is a breaking change as this no longer works: import Events from '@storybook/core-events'; The implication of going with just named exports is that this patch would also need to include changes to the rest of this repository to use either named imports or Public non-
|
One more perspective on this. I just did a search through the this repository's If picking a single import pattern to support is desired then exporting the enum as the default export and not exporting named exports would be the least invasive. |
That's interesting. On the I think given that it's safe to assume that most external uses will be via the |
I think it's probably best to maintain compatibility for 4.x. The Storybook 5.0 release would be a good time to assert a single export format. I've added a test file to ensure that all previously supported import variants are still supported. |
Codecov Report
@@ Coverage Diff @@
## next #5186 +/- ##
==========================================
+ Coverage 29.85% 30.24% +0.39%
==========================================
Files 613 613
Lines 8883 8887 +4
Branches 1217 1217
==========================================
+ Hits 2652 2688 +36
+ Misses 5558 5527 -31
+ Partials 673 672 -1
Continue to review full report at Codecov.
|
I cherry picked b870091 into |
Let me know if you need anything else from me on this. |
@dandean no this looks really great, thank you for this. I will just wait to hear from @ndelangen before deciding what to do. We are looking at merging 5.0 into |
I think this means by now this change is already on next? |
@ndelangen I cherry-picked a single commit from this branch. We should probably merge the entire branch as it includes tests etc. |
# Conflicts: # lib/core-events/src/index.ts
@dandean @ndelangen @tmeasday Removing the |
Issue: #5130 #5140
What I did
The PR #5140 introduced a regression as noted by @tmeasday here #5140 (comment)
This looks like the result of incompatibilities between the module systems where
module.exports = { ... }
would provide both a default export and named exports associated with the keys of the exported object.That PR broke that duality by only exporting the enum as the default export and not also exporting named exports.
This PR declares named exports associated with each of the keys of the events enum.
How to test