html
html copied to clipboard
Add basic import maps support
This imports much of the specification from https://wicg.github.io/import-maps/. The main deltas are:
-
Does not include support for external import maps, since nobody has implemented these yet. This allows a good deal of simplification, such as by changing "acquiring import maps" + "pending import map script" + "wait for import maps" to a single "import maps allowed" boolean, or integrating "register an import map" into "execute the script element". If a src="" attribute is present on an importmap script element, then an error event is fired.
-
Does not include any support for non-Window import maps. The spec draft included stub support for those, with other globals always having an empty import map. This instead ties import maps to Windows directly. If we revisit that in the future we can refactor, but keeping always-empty import maps around on the other globals was clumsy.
-
Adds introductory text and examples.
-
Adds conformance requirements, both on the script element and on the import map JSON.
-
Fixes a few minor specification issues: https://github.com/WICG/import-maps/issues/267, https://github.com/WICG/import-maps/issues/268, https://github.com/WICG/import-maps/issues/270, https://github.com/WICG/import-maps/issues/276, https://github.com/WICG/import-maps/issues/277.
Review from @hiroshige-g and @allstarschh appreciated. The new flow in "prepare the script element" and "execute the script element" in particular needs careful review.
- [x] At least two implementers are interested (and none opposed):
- Chromium has implemented and shipped this
- Gecko, per https://github.com/mozilla/standards-positions/issues/146
- [x] Tests are written and can be reviewed and commented upon at: https://github.com/web-platform-tests/wpt/tree/master/import-maps . Maybe should be moved into html/
- [x] Implementation bugs are filed:
- Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=848607
- Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1688879
- Safari: https://bugs.webkit.org/show_bug.cgi?id=220823
- Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): already supported, https://deno.land/manual/linking_to_external_code/import_maps
- Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): https://github.com/nodejs/modules/issues/477
(See WHATWG Working Mode: Changes for more details.)
/acknowledgements.html ( diff ) /index.html ( diff ) /infrastructure.html ( diff ) /references.html ( diff ) /scripting.html ( diff ) /webappapis.html ( diff )
I think webkit has feature bug already? https://bugs.webkit.org/show_bug.cgi?id=220823
@domenic Could you explain when the preparation-time document check will fail for import-maps? As the import map doesn't support external, neither it supports 'async' nor 'defer', the 'execute the script element' part should be run immediately after 'prepare the script element' for inline import maps, so the 'preparation-time document check' should always succeed. Should the 'register an import map' be done in 'prepare the script element' ?
I agree the preparation-time document check will never fail for import maps. This is a general programming pattern where you put shared logic inside a shared function (in this case "execute the script element"), even if for some inputs to that function, the logic is not necessary.
I don't think it's a good idea to restructure the specification so that execution of the import map happens during the preparation phase, instead of the execution phase. Even if the results are observably the same, it makes the specification much harder to read and follow.
Sorry for delay, LGTM. My comments are editorial except for https://github.com/whatwg/html/pull/8075#discussion_r934986200.
Thanks for the review @hiroshige-g! I think I have addressed everything.
Since there is no big rush, I will wait for co-editor review from @annevk when he gets back, before merging. In the meantime I can do a bit of work on tidying up the tests.
is it intended it got merged into task-source-for-script
rather than main
?
Nope, sorting that out now over in https://github.com/whatwg/html/pull/8072.