-
Notifications
You must be signed in to change notification settings - Fork 72
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
Will module specifiers support query strings? #134
Comments
No; bare specifiers are not URLs, and |
Still, you say nothing on the relevance of the use case nor on why it isn't supported. |
@domenic Could you be so kind to explain why bare specifiers, not being urls, cannot support query strings, or why, in your opinion, the use case is not relevant? |
Bare specifiers are opaque. |
That's by definition, so not a valid reason, imo. Anyway, supporting When resolving the URL corresponding to a given bare specifier, the latter is matched against the longest bare specifier prefix in the consolidated import map. The excess bare specifier segments are then "transformed" into excess text appended to the RHS URL. The way this is done, no knowledge of the structure of a URL is necessary. However, we could argue whether a blind approach is the most useful approach. In some cases we could want to "transform" the excess bare specifiers into additional segments of the path part of the URL, while, in others, we could want to transform these into the value of a specific query parameter (the hash part of the URL is not sent to the server, so its usefulness would be restricted to interpretation by the browser side). Server-side libraries, such as I don't think that import maps should make any assumptions on what constitutes a correctly constructed URL, and the current import mapping abilities only allow mapping to certain URL patterns (that can be constructed by appending the excess segments). To allow more general mappings to URLs, import maps would need to allow specifying where, in the URL of the RHS, the excess bare specifiers would be placed. Edit: added a trailing {
"imports": {
"@my/generator/": "https://my.generator.com/?path={*}"
}
} Then, Recently, another issue was raised, related with Also somewhat related, in that issue, @guybedford raised a possible use case for "cached busting at the module registry" by allowing URLs differing only on the hash part to represent different modules (e.g. |
Also related, a less orthodox mapping: #166 |
+1 to not recognizing
This is to removing the trailing- |
I'm concerned with this powerful mechanism, because the increased complexity might make it harder to infer/validate the import maps spec and behavior, as well as adding "import maps RHS parser" that recognizes |
Also related, jkrems/proposal-pkg-exports#8. |
Sorry, I just noticed that I should have added a trailing {
"imports": {
"@my/generator/": "https://my.generator.com/?path={*}"
}
} |
This serves several use cases. The one I aim for is to enable calling server-side, dynamically generated modules, for an endpoint which does not follow a REST-like structure. I believe that it's not expected that bare specifiers always map to an existing "file on disk", such as if it was evaluated Node.js. The use case is that of a web server, and web-servers use URLs of various forms to reference resources. These resource can be static or dynamic. Another use case, that I just now realized, is supporting the above mentioned use case, in jkrems/proposal-pkg-exports#8, where something like this is proposed: {
"imports": {
"@my/lib/": "./dist/{*}.js"
}
} which constitutes a way to bulk declare all modules in a folder to be accessible without their extension. |
@dcleao extensionless import mappings like that are going to much less general in the presence of JSON, HTML, and CSS modules. Generating each entry for each file with a tool will work in the general case though. |
@justinfagnani, as I noted, that's not a use case that I aim for. I just mentioned it because I read elsewhere someone asking for that feature. |
Certainly "generating an entry for each file with a tool" will work, but it would be a very user-friendly feature - either in the initial proposal or as a followon - to support some kind of wildcard/regex/pattern matching to allow semantic minimizing of the size of import maps, without forcing arbitrary coding or transpilation patterns. |
For example, given the import map:
Above, the module specifier key in the import map would not be allowed to have a query string part (but the module URL it is mapped to could).
Then, in JavaScript code, it would be possible to resolve an import URL containing a query string:
Would this resolve to calling the URL:
https://my.generator.com/?path=a/b/c
?A similar exercise could be made for an ES6 module which the above URL would dynamically generate and that could then be loaded by the dynamic
import
"function".I believe this is a compelling use case.
The text was updated successfully, but these errors were encountered: