WICG / import-maps

How to control the behavior of JavaScript imports
https://html.spec.whatwg.org/multipage/webappapis.html#import-maps
Other
2.66k stars 69 forks source link

Pattern vs prefix matching #232

Closed jkrems closed 2 years ago

jkrems commented 3 years ago

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 that some/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.

guybedford commented 3 years ago

For further reference here:

As @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.

LarsDenBakker commented 3 years ago

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.

domenic commented 2 years ago

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.