Comments (9)
I am on vacation through April 1, but would be happy to review PRs clarifying this or other aspects in the meantime.
from import-maps.
Since a scope defines a path and is a prefix of the refererURL, it makes sense to me that paths within a scope are relative to the path of the scope.
As you point out, you can refer outside of the scope path by using ../
:
{
"path_prefix": "https://foo.bar",
"packages": {
"A": { "path": "A@1", "main": "index.js" },
"B": { "path": "B@1", "main": "index.js" }
},
"scopes": {
"A": {
"packages": {
"C": { "path": "../C@1", "main": "index.js" }
}
},
"B": {
"packages": {
"C": { "path": "../C@2", "main": "index.js" }
}
}
}
}
from import-maps.
I find it really confusing, especially considering that this rule behavior is ambiguous in itself. Module names are not strictly correlated to the filesystem paths, so why make the scopes package paths relative to the scope names rather than the scopes paths? ie has a user, I could expect the following:
https://foo.bar/A@1/C@2/index.js
https://foo.bar/B@1/C@2/index.js
But not really this, since I never specified that A
and B
were valid URLs:
https://foo.bar/A/C@2/index.js
https://foo.bar/B/C@2/index.js
I can guess that the main argument for this behavior is that it's much simpler to just use the scope name rather than the package paths, but my point is that automatically composing path is a confusing behavior in itself, which counterbalances the "less repetition" argument. I'd prefer things to be explicit rather than implicit and subject to varying expectations.
from import-maps.
Scopes are independent from packages and don't have names - they are very explicitly and only paths. The reason is the role of a scope: it's used to look up a map based on the refererURL.
from import-maps.
I'm not sure I understand. Does that make my example above wrong, and should be this instead: ?
{
...,
"scopes": {
"A@1": {
...,
},
"B@1": {
...,
}
}
}
from import-maps.
Ah, yes. Though we should be careful to be clear with statements like "Resolving C from A". The "from" part really should be a path to be most clear.
from import-maps.
I see - if the scopes keys are URLs/paths, then I think the relative behavior semantically makes much more sense, thanks!
from import-maps.
cc @domenic for the discussion. Emphasizing that scopes are path-keyed and never referring to "scope name" would probably be helpful.
from import-maps.
This tripped me up too and seems like a common catch from the way the examples are described.
from import-maps.
Related Issues (20)
- Default JSON filename for external tooling support. HOT 1
- "parse a URL-like import specifier", the term "import specifier" is a little bit confusing HOT 3
- Spec doesn't clearly define onerror must be called if import map is added after the 1st module load HOT 4
- In "the scriptโs type", the โ is actually an unicode U+2019, instead of an ascii ' HOT 2
- Typo in "A import map is a struct with two items:" HOT 2
- An empty map was create twice if "imports" or "scopes" exists HOT 2
- Modulepreload error caching HOT 9
- Should HTMLScriptElement.supports("importmap") return true? HOT 1
- Fire a load event or an error event when the script element of the import map is from an external file? HOT 2
- preparation-time document check should be done first at #register-an-import-map HOT 2
- Throwing TypeError in resolve a module specifier? HOT 2
- calling onerror of the script element if the import map string cannot be parsed HOT 1
- What should 'parse an import map string' return when it throws an Error? HOT 8
- Speculatively parsing with import map if there's a dynmic import before, HOT 4
- Official file extension? HOT 2
- Support stars in imports besides trailing slashes HOT 1
- `importmap` cannot resolve dependencies entered relatively. HOT 3
- [feat] `script.integrity` and import map HOT 2
- Specification is not restricting address from containing query- or fragment parts not ending with "/" HOT 3
- global variables (f.e. map `"jquery"` specifier to `globalThis.jquery` variable) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from import-maps.