Closed jkrems closed 2 years ago
For further reference here:
/
mappings in Node.js: https://github.com/nodejs/node/pull/35747As @jkrems describes we found for Node.js that because "pkg/path/"
style mappings enforce needing the file extension, this inhibits use cases where the file extension might need to be mapped as an implementation detail (eg .cjs
-> .mjs
or .js
-> .wasm
etc).
Personally I would like us to encourage package authors to define the "exports" field in Node.js (which is designed to integrate with import maps) such that packages dont use extensions when doing import 'pkg/feature'
as opposed to needing to do import 'pkg/feature.js'
.
So this is all implementation feedback from implementing trailing /
matches that might be useful to hear.
I agree hat the node js pattern implementation seems much more flexible:
{
"imports": {
"./features/*": "./dist/features/*.js"
}
}
What's unfortunate now is that import maps and node js export maps now different behavior.
It's too late to remove trailing slash mappings. I think the rest of the issue is a proposal for an addition of more complicated mappings, which I will roll into https://github.com/WICG/import-maps/issues/7.
If I have misunderstood the difference between this issue and #7, please let me know and I can reopen.
Node has been experimenting with remapping bare specifiers and started with the same model as import-maps: Exact match and prefix match. What we discovered was that for some (many?) use cases of prefix matching, a more useful model was limited pattern matching. It's gotten to the point where node is looking to deprecate the prefix matching support.
What we replaced it with is still prefix matching: Only
some/bare/*
is supported which applies to the same specifiers thatsome/bare/
would've applied to. The difference is in the RHS which allows to specify where the postfix appears in the resulting URL.It's fairly late into the process for import maps but I thought it may be good to raise this before it's potentially to late to revise how prefix matches work in import maps.