-
Notifications
You must be signed in to change notification settings - Fork 14
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
Proposal: Conditional export maps #14
Comments
This sounds similar to editions, in principle at least. I do like the use of Speaking of that top-level field, I did find it useful at times to overwrite files rather than entrypoints. So maybe this should be a resource override rather than a mapping? |
This seems related to #13. |
This is not related to editions in that it is not trying to detect engine versions. Rather it is providing the environment information, but without versioning - browser / node / react-native / production / development / etc etc. |
@jkrems conditionally rewriting internal requires is interesting yes, but I would be weary of remapping relative specifiers. |
I think exploring this further is worth it... I like the simplicity of it personally but from Geoffrey's dataset, here are all numbers for all fields that are path-like strings and are not a known non-path field: Table
I wanted to do some trend analysis before sharing this table, but if exports can help bring harmony to this space by offering a good alternative for others to adopt, that would be a great success |
Let's redirect discussions around this to the proposal for handling differential mappings: https://github.com/guybedford/proposal-pkg-targets/issues |
I'd like to propose an extension to this proposal to support conditional mappings.
Currently in Node, the "main" is used as the conditional branch in resolution by having different main fields per-environment - "browser", "react-native", "electron", etc.
One limitation of these approaches (amongst others) is that they don't apply for subpath requires, which is exactly what the browserify "browser" field was designed to provide.
The suggestion is that various static condition names could be provided to selectively map both the main and subpaths based on environment conditions.
Conditions could be supported by allowing a mapping into a Condition instead of a simple string.
There are many ways to go about this, but as an illustrative example, consider:
The above would support
import "pkg"
providing a different result between browsers and Node by respecting the exports mapping defined here.Similarly
import "pkg/subpath/x.js"
can be routed to different target folders based on these environment conditions.The list of conditions, would be basically exactly what the different names for "main" are today (except for "module" of course!).
I think these kind of possibilities are absolutely necessary for the platform, and this spec can open up some exciting opportunities here.
The text was updated successfully, but these errors were encountered: