-
Notifications
You must be signed in to change notification settings - Fork 28
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
Support index-modules in exports #229
Conversation
"types": "./declarations/*.d.ts", | ||
"default": "./dist/*.js" | ||
"types": ["./declarations/*.d.ts", "./declarations/*/index.d.ts"], | ||
"default": ["./dist/*.js", "./dist/*/index.js"] | ||
},<% } else { %> | ||
".": "./dist/index.js", | ||
"./*": "./dist/*.js",<% } %> |
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.
does this syntax support the array form?
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.
Not sure what exactly you mean here? Support for arrays in general is given as backed by the above links. You mean in this particular place, like L109?
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.
yeah, like, if we add /index
stuff, it should be both for and without the TS exports
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.
Ah right! Not sure why I didn't even think about it. I'll add it, should we agree to actually go forward with this!
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.
I mean, you have my vote!
(not that this is a democracy, since we need to convince everyone the technical merits of a thing lol)
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.
But what about vite? My understanding is this will fail under vite. Unless we can convince vite maintainers to change course? (not too likely?)
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.
Why's vite matter here?
The need to declare something about index for ember's conventions helps all packagers
I don't think this is part of Node's spec for package.json exports. I just tried it and Node only attempts to resolve the first thing. I'd rather not diverge from Node. We already auto-generate the |
Closing this, as we agreed to not do this change in the team meeting. The question if we should make our rollup tooling auto-generate this didn't really come to any definite conclusion. We can discuss pros and cons again... |
This is not necessarily something I expect to get merged immediately, more so to start a conversation...
The problem this is addressing is that index-files, which are supported in v1 addons and the default node module resolution, are not working ootb in v2 addons, due to our explicit
exports
mapping. Say you put afoo/index.js
module into/src
, then currently the only way to import that is byimport foo from 'addon/foo/index'
, which I think is pretty much unexpected.This is especially annoying when migrating from v1 addons. For example a common suggestion would be to move your addon's
addon-test-support
tosrc/test-support
. But again that does not allow you to import fromaddon/test-support
as expected, so makes this a breaking change.Ideally I think, we would allow alternatives, so that
import foo from 'addon/foo'
can be satisfied either bysrc/foo.js
orsrc/foo/index.js
.And actually this seems to be possible, with the changes in this PR. Both webpack (docs)and TypeScript seem to support an array of alternative modules in
exports
. And TypeScript has supported that for long intypesVersions
, which is also what the v1 blueprint does!The only problem: vite supports array-based alternatives, but does no file-check, just takes whatever matches first AFAIU, see vitejs/vite#4439 (comment). Which is not what we need to support this use case.
The alternative to this "just works" approach would be to force users to explicitly define the
exports
mapping. But this also does not seem good, becauseexports
and how they work I think. And if resolving an index-module does not work, you won't get a really helpful error message like saying "tweak your exports".Thoughts?