Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spec for "update an import map" #150

Merged
merged 2 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,67 @@ A <dfn>import map</dfn> is a [=struct=] with two [=struct/items=]:
An <dfn>empty import map</dfn> is an [=/import map=] with its [=import map/imports=] and [=import map/scopes=] both being empty maps.

<div algorithm>
To <dfn>update an import map</dfn> |import map| with a second [=/import map=] |new import map|:
To <dfn>update an import map</dfn> |importMap| with a second [=/import map=] |newImportMap|:

1. Assert: |import map| is not null.
1. Assert: |new import map| is not null.
1. <p class="note">TODO: Implement merging. This merges |new import map| into |import map| and thus updates |import map| in-place.</p>
1. For each |specifier| → |addresses| of |newImportMap|'s [=import map/imports=], [=map/set=] |importMap|'s [=import map/imports=][|specifier|] to |addresses|.
1. For each |url| → |specifierMap| of |newImportMap|'s [=import map/scopes=], [=map/set=] |importMap|'s [=import map/scopes=][|url|] to |specifierMap|.
1. Set |importMap|'s [=import map/imports=] to the result of [=map/sorting=] |importMap|'s [=import map/imports=], with an entry |a| being less than an entry |b| if |a|'s [=map/key=] is [=longer or code unit less than=] |b|'s [=map/key=].
1. Set |importMap|'s [=import map/scopes=] to the result of [=map/sorting=] |importMap|'s [=import map/scopes=], with an entry |a| being less than an entry |b| if |a|'s [=map/key=] is [=longer or code unit less than=] |b|'s [=map/key=].
</div>

<div class="example" id="example-merging">
[=Update an import map=] merges the two import maps in a very simple way, not performing any deep merging beyond the top level of the "`imports`" and "`scopes`" keys. For example,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I feel a little inconsistent (because the specifier map as import map's imports is merged while specifier maps inside import map's scopes are overwritten, not merged), basically this behavior is fine with me.
If there are any discussions / analyses behind this decision, it will be helpful to reference them.

(In any cases, there might be still "unexpected" behavior around merging, because parts of different import maps can be applied to different parts of a single module script, but so far I have no idea for such kind of unexpected behavior, and probably we have to wait for user feedbacks.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too much besides just a general drive for simplicity. I would be OK with slightly deeper merging. I will open an issue to discuss, but we should decide soon.


<xmp highlight="html">
<script type="importmap">
{
"imports": {
"a": "/a-1.mjs",
"b": "/b-1.mjs",
"std:kv-storage": ["std:kv-storage", "/kvs-1.mjs"]
},
"scopes": {
"/scope1/": {
"a": "/a-2.mjs"
}
}
}
</script>
<script type="importmap">
{
"imports": {
"b": null,
"std:kv-storage": "kvs-2.mjs"
},
"scopes": {
"/scope1/": {
"b": "/b-2.mjs"
}
}
}
</script>
</xmp>

is equivalent to

<xmp highlight="html">
<script type="importmap">
{
"imports": {
"a": "/a-1.mjs",
"b": null,
"std:kv-storage": "kvs-2.mjs"
},
"scopes": {
"/scope1/": {
"b": "/b-2.mjs"
}
}
}
</script>
</xmp>

Notice how the definition for "`/scope1/`" was completely overridden, so there is no longer a redirection for the "`a`" module specifier within that scope.
</div>

<h2 id="acquiring">Acquiring import maps</h2>
Expand Down
32 changes: 0 additions & 32 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@

The spec for import maps is located at https://wicg.github.io/import-maps/. This document contains notes on things that will eventually be formalized and make their way into the spec.

## Merging import maps

We're looking to do the minimal thing that could work here. As such, I propose the following:

Given two import maps _A_ and _B_, the merged import map is a new import map whose imports are the result of merging _A_'s imports and _B_'s imports, and whose scopes are the result of merging _A_'s scopes and _B_'s scopes. Here, merging two maps means appending their entries to each other, with any conflicting keys from the first map removed.

Example:

```json
{
"imports": { "a": "1", "b": "2" }
}
```

+

```json
{
"imports": { "a": "3" }
}
```

=

```json
{
"imports": { "b": "2", "a": "3" }
}
```

Note that we do not introspect the scopes. If there's two conflicting definitions of how things behave inside a scope, then the last one wins.

## `import:` URL fetches

_Unlike in previous import map proposals, `import:` URLs no longer involve changes to the URL parser._
Expand Down