From 1f3329bb4ed7f579252983aa98d963c120438afc Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Wed, 6 Nov 2024 05:27:13 -0800 Subject: [PATCH] Multiple import maps Import maps currently have to load before any ES module and there can only be a single import map per document. That makes them fragile and potentially slow to use in real-life scenarios: Any module that loads before them breaks the entire app, and in apps with many modules the become a large blocking resource, as the entire map for all possible modules needs to load first. This implements https://github.com/whatwg/html/pull/10528 to solve that. Change-Id: I54e1b9cdfe989d61c85d73a5fd384f860273ad9a Bug: 358379381 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5776262 Commit-Queue: Yoav Weiss (@Shopify) Reviewed-by: Kouhei Ueno Cr-Commit-Position: refs/heads/main@{#1378943} --- import-maps/acquiring/dynamic-import.html | 9 +-- .../acquiring/modulepreload-link-header.html | 8 +- import-maps/acquiring/modulepreload.html | 8 +- import-maps/acquiring/script-tag-inline.html | 13 +-- import-maps/acquiring/script-tag.html | 8 +- .../already-resolved-dropped.html | 26 ++++++ import-maps/multiple-import-maps/basic.html | 6 +- .../conflict-first-persists.html | 49 +++++++++++ ...ion-consistency-in-module-tree-inline.html | 45 +++++++++++ ...resolution-consistency-in-module-tree.html | 33 ++++++++ .../url-resolution-conflict.html | 32 ++++++++ .../multiple-import-maps/with-errors.html | 8 +- import-maps/not-overridden/dynamic.html | 40 +++++++++ .../external-script-bare-descendent.html | 52 ++++++++++++ ...external-script-descendent-with-scope.html | 81 +++++++++++++++++++ .../external-script-descendent.html | 40 +++++++++ .../not-overridden/failed-resolution.html | 60 ++++++++++++++ import-maps/not-overridden/integrity.html | 38 +++++++++ .../modulepreload-header.html.headers | 2 + import-maps/not-overridden/prefix.html | 40 +++++++++ .../not-overridden/script-descendent.html | 33 ++++++++ .../url-resolution-conflict.html | 28 +++++++ import-maps/resources/importer.sub.js | 1 + import-maps/resources/in-scope-test.js | 3 + import-maps/resources/log.sub.js | 2 + import-maps/resources/test-helper.js | 8 ++ resources/out-of-scope-test.js | 5 ++ 27 files changed, 637 insertions(+), 41 deletions(-) create mode 100644 import-maps/multiple-import-maps/already-resolved-dropped.html create mode 100644 import-maps/multiple-import-maps/conflict-first-persists.html create mode 100644 import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html create mode 100644 import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html create mode 100644 import-maps/multiple-import-maps/url-resolution-conflict.html create mode 100644 import-maps/not-overridden/dynamic.html create mode 100644 import-maps/not-overridden/external-script-bare-descendent.html create mode 100644 import-maps/not-overridden/external-script-descendent-with-scope.html create mode 100644 import-maps/not-overridden/external-script-descendent.html create mode 100644 import-maps/not-overridden/failed-resolution.html create mode 100644 import-maps/not-overridden/integrity.html create mode 100644 import-maps/not-overridden/modulepreload-header.html.headers create mode 100644 import-maps/not-overridden/prefix.html create mode 100644 import-maps/not-overridden/script-descendent.html create mode 100644 import-maps/not-overridden/url-resolution-conflict.html create mode 100644 import-maps/resources/importer.sub.js create mode 100644 import-maps/resources/in-scope-test.js create mode 100644 import-maps/resources/log.sub.js create mode 100644 resources/out-of-scope-test.js diff --git a/import-maps/acquiring/dynamic-import.html b/import-maps/acquiring/dynamic-import.html index 49d8a701da2e43..2521b2fb7f4dec 100644 --- a/import-maps/acquiring/dynamic-import.html +++ b/import-maps/acquiring/dynamic-import.html @@ -3,8 +3,6 @@ - diff --git a/import-maps/acquiring/modulepreload-link-header.html b/import-maps/acquiring/modulepreload-link-header.html index dde8cabb9323f0..5d3eaabd8f5217 100644 --- a/import-maps/acquiring/modulepreload-link-header.html +++ b/import-maps/acquiring/modulepreload-link-header.html @@ -3,11 +3,9 @@ - diff --git a/import-maps/acquiring/modulepreload.html b/import-maps/acquiring/modulepreload.html index 68b66a8ae330e4..0571c7dcbe4c4f 100644 --- a/import-maps/acquiring/modulepreload.html +++ b/import-maps/acquiring/modulepreload.html @@ -3,12 +3,10 @@ - diff --git a/import-maps/acquiring/script-tag-inline.html b/import-maps/acquiring/script-tag-inline.html index 683ce83c3a4b35..602ddc41a257b1 100644 --- a/import-maps/acquiring/script-tag-inline.html +++ b/import-maps/acquiring/script-tag-inline.html @@ -3,18 +3,11 @@ - diff --git a/import-maps/acquiring/script-tag.html b/import-maps/acquiring/script-tag.html index 2792c2a31d9718..e03f24dc0afb45 100644 --- a/import-maps/acquiring/script-tag.html +++ b/import-maps/acquiring/script-tag.html @@ -3,12 +3,10 @@ - diff --git a/import-maps/multiple-import-maps/already-resolved-dropped.html b/import-maps/multiple-import-maps/already-resolved-dropped.html new file mode 100644 index 00000000000000..631af5dc3ce39a --- /dev/null +++ b/import-maps/multiple-import-maps/already-resolved-dropped.html @@ -0,0 +1,26 @@ + + + + + + + + + diff --git a/import-maps/multiple-import-maps/basic.html b/import-maps/multiple-import-maps/basic.html index 9ab03ddc302af1..1c55e09e79f42e 100644 --- a/import-maps/multiple-import-maps/basic.html +++ b/import-maps/multiple-import-maps/basic.html @@ -22,15 +22,13 @@ } diff --git a/import-maps/multiple-import-maps/conflict-first-persists.html b/import-maps/multiple-import-maps/conflict-first-persists.html new file mode 100644 index 00000000000000..2e197244be55c6 --- /dev/null +++ b/import-maps/multiple-import-maps/conflict-first-persists.html @@ -0,0 +1,49 @@ + + + + + + + + diff --git a/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html b/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html new file mode 100644 index 00000000000000..a248977b90dd9e --- /dev/null +++ b/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + diff --git a/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html b/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html new file mode 100644 index 00000000000000..e0767a6c61056d --- /dev/null +++ b/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + diff --git a/import-maps/multiple-import-maps/url-resolution-conflict.html b/import-maps/multiple-import-maps/url-resolution-conflict.html new file mode 100644 index 00000000000000..e8d06bdf524897 --- /dev/null +++ b/import-maps/multiple-import-maps/url-resolution-conflict.html @@ -0,0 +1,32 @@ + + + + + + + + diff --git a/import-maps/multiple-import-maps/with-errors.html b/import-maps/multiple-import-maps/with-errors.html index a93ecaaeff5b32..3ba9b073592532 100644 --- a/import-maps/multiple-import-maps/with-errors.html +++ b/import-maps/multiple-import-maps/with-errors.html @@ -18,15 +18,11 @@ } diff --git a/import-maps/not-overridden/dynamic.html b/import-maps/not-overridden/dynamic.html new file mode 100644 index 00000000000000..dbc839a928c0cb --- /dev/null +++ b/import-maps/not-overridden/dynamic.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/external-script-bare-descendent.html b/import-maps/not-overridden/external-script-bare-descendent.html new file mode 100644 index 00000000000000..bff33f8d6abc2b --- /dev/null +++ b/import-maps/not-overridden/external-script-bare-descendent.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/external-script-descendent-with-scope.html b/import-maps/not-overridden/external-script-descendent-with-scope.html new file mode 100644 index 00000000000000..9f04548cc2d749 --- /dev/null +++ b/import-maps/not-overridden/external-script-descendent-with-scope.html @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/external-script-descendent.html b/import-maps/not-overridden/external-script-descendent.html new file mode 100644 index 00000000000000..122e8204f18fce --- /dev/null +++ b/import-maps/not-overridden/external-script-descendent.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/failed-resolution.html b/import-maps/not-overridden/failed-resolution.html new file mode 100644 index 00000000000000..eae6febddf157b --- /dev/null +++ b/import-maps/not-overridden/failed-resolution.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/integrity.html b/import-maps/not-overridden/integrity.html new file mode 100644 index 00000000000000..7770899728706c --- /dev/null +++ b/import-maps/not-overridden/integrity.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/modulepreload-header.html.headers b/import-maps/not-overridden/modulepreload-header.html.headers new file mode 100644 index 00000000000000..785378622d4d81 --- /dev/null +++ b/import-maps/not-overridden/modulepreload-header.html.headers @@ -0,0 +1,2 @@ +Link: <../resources/log.js?pipe=sub&name=A>;rel=modulepreload + diff --git a/import-maps/not-overridden/prefix.html b/import-maps/not-overridden/prefix.html new file mode 100644 index 00000000000000..99449b890e6021 --- /dev/null +++ b/import-maps/not-overridden/prefix.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/script-descendent.html b/import-maps/not-overridden/script-descendent.html new file mode 100644 index 00000000000000..4d1e08d41298e4 --- /dev/null +++ b/import-maps/not-overridden/script-descendent.html @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/import-maps/not-overridden/url-resolution-conflict.html b/import-maps/not-overridden/url-resolution-conflict.html new file mode 100644 index 00000000000000..d0708632164393 --- /dev/null +++ b/import-maps/not-overridden/url-resolution-conflict.html @@ -0,0 +1,28 @@ + + + + + + + + + + diff --git a/import-maps/resources/importer.sub.js b/import-maps/resources/importer.sub.js new file mode 100644 index 00000000000000..6b55546d0d9a5c --- /dev/null +++ b/import-maps/resources/importer.sub.js @@ -0,0 +1 @@ +import "{{GET[name]}}"; diff --git a/import-maps/resources/in-scope-test.js b/import-maps/resources/in-scope-test.js new file mode 100644 index 00000000000000..aa64e89514c698 --- /dev/null +++ b/import-maps/resources/in-scope-test.js @@ -0,0 +1,3 @@ +// Testing that the resolution is correct using `resolve`, as you can't import +// the same module twice. +window.inscope_test_result = import.meta.resolve("a"); diff --git a/import-maps/resources/log.sub.js b/import-maps/resources/log.sub.js new file mode 100644 index 00000000000000..3588867d52cc96 --- /dev/null +++ b/import-maps/resources/log.sub.js @@ -0,0 +1,2 @@ +log.push("log:{{GET[name]}}"); + diff --git a/import-maps/resources/test-helper.js b/import-maps/resources/test-helper.js index f12e84c685d548..258d8f4afe93f5 100644 --- a/import-maps/resources/test-helper.js +++ b/import-maps/resources/test-helper.js @@ -244,3 +244,11 @@ function doTests(importMapString, importMapBaseURL, tests) { }); }, { explicit_done: true }); } + +function test_loaded(specifier, expected_log, description) { + promise_test(async t => { + log = []; + await import(specifier); + assert_array_equals(log, expected_log); + }, description); +}; diff --git a/resources/out-of-scope-test.js b/resources/out-of-scope-test.js new file mode 100644 index 00000000000000..ce24124646dc83 --- /dev/null +++ b/resources/out-of-scope-test.js @@ -0,0 +1,5 @@ +// Testing that the resolution is correct using `resolve`, as you can't import +// the same module twice. +window.outscope_test_result = import.meta.resolve("a"); +window.outscope_test_result2 = import.meta.resolve("../resources/log.sub.js?name=E"); +