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

import: URL clarification #149

Closed guybedford closed 2 years ago

guybedford commented 5 years ago

The readme information on import: referrer handling is really excellent, but I just wanted to clarify one case for my own peace of mind which doesn't seem to be mentioned.

If I use an import: URL in a module specifier or dynamic import, will it still be resolved relative to the parent:

import x from 'import:x';
import y from 'x';
const z = await import('import:x');

// Are x,y, z all equal?

In addition, does that mean a dynamic import in a script would be script-relative:

<script src="/path/to/script.js"></script>

script.js

import('import:./dep.js'); // loads /path/to/dep.js?

I would hope that the answer to the above would be yes for consistency, but it doesn't seem to be explicitly detailed from what I could see.

guybedford commented 5 years ago

Perhaps the above shouldn't be supported actually, since we then have the question of import:x maps themselves!?

Either way would be good to know!

domenic commented 5 years ago

Yeah, I guess we never did figure this out. The initial import maps rewrite had this as "TBD".

Making it fail certainly seems simplest. Maybe that would be a bit limiting, because you'll get a URL that sometimes you want to send to one place, and sometime send to import()?

I agree that if we were to allow it then we should basically just strip the leading import:.

guybedford commented 5 years ago

In theory,

Would attempt to resolve ‘import:x’ in the import map so that the default behaviour (silent failure, and supporting mappings) may actually still be desired!

On Wed, Jul 10, 2019 at 15:55 Domenic Denicola notifications@github.com wrote:

Yeah, I guess we never did figure this out. The initial import maps rewrite https://github.com/WICG/import-maps/blob/fad2f0475b2d57a03d70461455e92a96fd9ea595/README.md#import-urls had this as "TBD".

Making it fail certainly seems simplest. Maybe that would be a bit limiting, because you'll get a URL that sometimes you want to send to one place, and sometime send to import()?

I agree that if we were to allow it then we should basically just strip the leading import:.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/WICG/import-maps/issues/149?email_source=notifications&email_token=AAESFSTJPTIG3WMIDEMPLA3P6Y5DBA5CNFSM4H7RAVZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZURWKI#issuecomment-510204713, or mute the thread https://github.com/notifications/unsubscribe-auth/AAESFSVKEMX67KWUYSXISHLP6Y5DBANCNFSM4H7RAVZQ .