-
-
Notifications
You must be signed in to change notification settings - Fork 561
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 named exports for all plugins #360
Comments
I am in favor named exports, they create less friction and allow future additions. |
I'd recommend doing this one PR at a time. While tedious, easier to manage the releases and scheduling. |
Hooray! |
I thought this would make at least one person happy. And I see the need for babel. But I am not happy doing this unforced for the other plugins
To explain (2):
and
Now the problem is for Rollup to find the relevant export. So it
For 1., at the moment it would try So if you do this, we need to adjust the logic in Rollup first. PR very much welcome, the logic is very localized in https://github.com/rollup/rollup/blob/master/cli/run/commandPlugins.ts#L66-L73 And then once this is done, Rollup's documentation should be updated quickly, otherwise I see a ton of issues rolling in. |
Babel will not work with cli anyway. We can introduce some other solution like special export export const plugin = () => ({ name: 'plugin' })
export const specialExportWithPluginForCli = plugin |
Why would Babel not work? |
And technically, there should be no reason to have a separate plugin for CLI. CLI even supports plugin parameters. One easy approach could be to keep the default exports as well as the named export and have Rollup CLI check the |
I'd like to keep We can phase this change in slowly and even wait on some PRs until we have other breaking changes to include. |
So we've got two really valid use cases here.
There is a pattern that solves both, even though it's not a purist pattern. In the case of const defaultOptions = {};
const plugin = () => {};
plugin.defaults = Object.freeze(Object.assign({}, defaultOptions));
export default plugin; While it's not as clean as named exports, it works. I've seen it a lot recently. Namely working with PouchDB and Electron. We can also attach types to the default export via export interface MainDatabase {
config: PouchDB.Database;
users: PouchDB.Database;
sync: (uri: string) => void;
} I think the case for default export for use on the CLI is strong. Users had clamored for that for a long while and just recently got that in. I think we can meet the needs of both use cases without causing too much disruption. |
I'm against placing all the exports on the default function for the ES module build. We could do it for the CommonJS build but it would complicate the typings, and I think named exports is more straightforward. |
I suppose I'm still hunting for the cost/benefit here. We're talking about a lot of changes and adding additional complexity to the ecosystem by making these changes. If we're going to move forward with named exports on every plugin then there needs to be clear benefit that outweighs the complexity. |
What is the advantage of this relatively large change? Export purity seems like a terrible argument for all of this work/churn. |
I think @shellscape's should actually work quite well. What we could do is
|
Hopefully this won't land for plugins with single export. After years of using default exports this is a terrible proposal with no real advantages. |
Why not switching instead everything to ES6 (and abolish It is in first place about replacing in the documentation |
-1 on dropping default export for plugins. If plugin maintainers wish to add an additional redundant named export - that's fine. But breaking existing plugins with default export just for questionable API elegance doesn't make sense. I'm glad to see that As mentioned above, the rollup CLI |
This issue is not proposing that we drop default exports, but instead export both named and default exports. ES module files will continue to work exactly the same, this only affects CommonJS. With Lukas' proposed solution we can make this a non-breaking change. |
If that's the case you might consider revising the issue title to reflect that. "Switch to" implies dropping the existing export mechanism and replacing it with a new one. "Add" would be a more apt description. |
Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.# Comment to post when closing a stale issue. ⓘ |
Feature Use Case
Using the
default
export creates issues with CommonJS if we want to export more than one item. When using@rollup/plugin-babel
, the different import styles look like:In contrast, the named exports look more similar:
Note: both formats work today because we export the plugin under
babel
anddefault
.Feature Proposal
As soon as we add any additional exports to a module, as was the case for
@rollup/plugin-node-resolve
, we need to use named exports. I think we should switch to named exports for all plugins for consistency. We can continue to export default as well for the ES module import format, but CJS outputs would have breaking changes.The text was updated successfully, but these errors were encountered: