Skip to content
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

Pattern vs prefix matching #232

Closed
jkrems opened this issue Oct 23, 2020 · 3 comments
Closed

Pattern vs prefix matching #232

jkrems opened this issue Oct 23, 2020 · 3 comments

Comments

@jkrems
Copy link
Contributor

jkrems commented Oct 23, 2020

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
Copy link
Collaborator

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
Copy link

LarsDenBakker commented Nov 24, 2020

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
Copy link
Collaborator

domenic commented Oct 14, 2021

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 #7.

If I have misunderstood the difference between this issue and #7, please let me know and I can reopen.

@domenic domenic closed this as completed Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants