WICG / import-maps

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

Question regarding imports sorting #178

Closed dmail closed 4 years ago

dmail commented 4 years ago

Hello,

I would like to use importMap to be able to scope import to a given folder. That folder is in fact the node_modules folder containing the files.

To achieve this I would create the following importMap:

{
  "scopes" : {
    "/node_modules/whatever/": {
     "/node_modules/whatever/": "/node_modules/whatever/",
      "/": "/node_modules/whatever/"
    }
  }
}

For the record I need both "/node_modules/whatever/" and "/" remapping to ensure import will be either:

Until here, it would work perfectly.

But, if I understand the specs right, imports matching depends on the specifier length. It makes me fear that most remapping would loose to "/node_modules/whatever/": "/node_modules/whatever/".

For instance, adding a remapping like "foo": "bar" in the importMap results into:

{
  "scopes" : {
    "/node_modules/whatever/": {
     "foo": "bar",
     "/node_modules/whatever/": "/node_modules/whatever/",
      "/": "/node_modules/whatever/"
    }
  }
}

But with the reference implementation importMap would be sorted and "foo": "bar" could not work as expected ?

dmail commented 4 years ago

Now I have written all that it seems only an import like

import "/node_modules/whatever/file.js"

Inside a node module source file itself would be remapped by the importMap above. Despites "/node_modules/whatever/file.js" import specifier being strange to have in a node module source, the resulting remapping would make sense without breaking the node module folder scoping.

Feel free to close without any comment, I got my answer.

I don't close issue myself immediatly in case this use case or my reflexion might be valuable or wrong.