import-maps icon indicating copy to clipboard operation
import-maps copied to clipboard

Supporting bare addresses

Open guybedford opened this issue 6 years ago • 11 comments

I'm glad to see that recursive resolution is no longer being provided.

Given this, should we consider supporting bare addresses? This would allow:

{
  "imports": {
    "x": "./x.js"
  }
}

to be equivalent to:

{
  "imports": {
    "x": "x.js"
  }
}

I'd be glad to put a PR together as well if this would be useful.

guybedford avatar Jan 11 '19 19:01 guybedford

Hmm. I think you're right this is possible.

I lean toward the conservativism of requiring the ./ prefix, and vaguely it feels like there might be a rule of "when using URLs in module-ey contexts, use the ./ prefix". But my reasoning here isn't very strong.

I'd be OK with changing this, but I wouldn't rush into it. Does anyone else have an opinion?

domenic avatar Jan 11 '19 21:01 domenic

Do you think some users would expect recursive application to work if they see a bare import as the map target?

zenparsing avatar Jan 11 '19 21:01 zenparsing

That's a good question. My initial instinct is it would depend on what else was nearby in the import map. If it were a bunch of URL-ey things they might see a "bare" relative URL as what it is (i.e. a URL). Similarly, the OP has a .js extension, which helps indicate that it'd be a URL-ey thing. But if it were a small import map without obvious extensions, then it might be more confusing...

domenic avatar Jan 11 '19 21:01 domenic

I think these arguments #80 apply here too; soft failures should be preferred over permissive reinterpretation, just as they should be preferred over hard failures.

The probability that people will want to prescribe new meaning to bare addresses in the future may seem low, but it's surely non-zero, and I don't think supporting them in this way actually buys anything in the meantime.

eliasvasylenko avatar Feb 01 '19 14:02 eliasvasylenko

Given the goal to allow a specifier to resolve to a built-in module, it would be better to require ./. Taking the example from the readme:

{
  "imports": {
    "@std/kv-storage": [
      "@std/kv-storage",
      "/node_modules/kvs-polyfill/index.mjs"
    ]
  }
}

If a mapping to x.js should resolve to ./x.js, then the mapping to @std/kv-storage could be read as resolving to ./@std/kv-storage.

rictic avatar Feb 25 '19 05:02 rictic

@rictic your argument makes sense, but to me it argues for a simpler solution: use URL-like built-in module specifiers, like std:kv-storage, instead of bare-specifier-like ones, like @std/kv-storage. Then the addresses (i.e. the right hand sides) are always URLs, and we can have confidence that we would interpret x.js or @std/kv-storage the same as ./x.js or ./@std/kv-storage.

domenic avatar Mar 11 '19 21:03 domenic

Banning adjacent // in paths would allow you to use //@std/kv-storage to move the std out of the path component without introducing something that looks like a scheme or a Windows volume.

I know that module specifiers aren't URLs and import: URLs aren't hierarchical, but the less work code that produces and mixes&matches import maps can do with existing URL libraries, the easier it will be to adopt them.

mikesamuel avatar Mar 22 '19 19:03 mikesamuel

Now that we have a pretty solid foundation, I'd be happy to take a PR for the spec/tests adding support for this.

domenic avatar Jul 03 '19 17:07 domenic

I was just looking at the spec at https://wicg.github.io/import-maps/#sort-and-normalize-a-specifier-map, and according to the outline there this is already supported I believe since there are no explicit checks for ./ anymore.

I think we can close this then?

guybedford avatar Aug 02 '19 01:08 guybedford

I think we'd need tests at the very least. Also, this may change if #137 happens; that proposes that the right-hand side no longer be URLs, but instead module specifiers.

domenic avatar Aug 02 '19 16:08 domenic

I'll consider this blocked on multiple import maps and the work on #137. Since multiple import maps are no longer part of the MVP, moving the milestone.

domenic avatar Sep 23 '19 08:09 domenic