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

Scope finding algorithm: Top-level scope's prefix? #41

Closed
nyaxt opened this issue Jun 1, 2018 · 5 comments
Closed

Scope finding algorithm: Top-level scope's prefix? #41

nyaxt opened this issue Jun 1, 2018 · 5 comments

Comments

@nyaxt
Copy link

nyaxt commented Jun 1, 2018

When finding the applicable scope, what string should we use to do longest prefix matching for the top-level scope?

For example, consider a case given a HTML hosted at http://example.com/baz/app.html:

<script type="packagemap">
{
  "path_prefix": "/foo",
  "packages": {
     "moment": { "main": "src/moment.js" },
  }
}
</script>
<script type=module src="http://example.com/main.js"></script> // should import 'moment' resolve? to which URL?
<script type=module src="http://example.com/foo/main.js"></script> // or would it require this?
<script type=module src="http://example.com/baz/foo/main.js"></script> // or this?
<script type=module src="https://example.com/baz/foo/main.js"></script> // what if html is http page and it references https?
```.
@nyaxt
Copy link
Author

nyaxt commented Jun 1, 2018

I'll proceed with the implementation by requiring the path_prefix to be a valid absolute URL, but given the story is to improve the development time experience, I assume that we want to have some kind of relative URL support.
e.g.) prod URL at https://prod.example.com/app/foo.html, while developing on https://localhost:8000/foo.html

@domenic
Copy link
Collaborator

domenic commented Jun 8, 2018

We are working on an answer for how the page URL, package map URL, and module URL all related in #37. Let's be sure to include all these test cases :).

@domenic
Copy link
Collaborator

domenic commented Jun 14, 2018

@guybedford, @justinfagnani, is this kind of case covered by the tests yet? What kind of answers do we give?

@guybedford
Copy link
Collaborator

For a package map hosted at http://foo.com/lib/map.json and a site at http://example.com/baz/app.html, the base-level path_prefix is resolved to the URL of the package map giving http://foo.com/foo/.

All the cases described then resolve moment to http://foo.com/foo/moment/src/moment.js. That is, the root scope always applies regardless of referrer, while the child scopes themselves resolve relative to the package name map baseURL, to then compare against the referrer. (I did actually test this as well)

Note also that if the path_prefix were foo without the leading /, then the same would apply here but into http://foo.com/lib/foo.

@domenic
Copy link
Collaborator

domenic commented Nov 2, 2018

This issue probably still has some relation to the current proposal, but it's hard to extract. Maybe it is covered by #63. Let me close it and we can file a new one that relates to the import maps proposal.

@domenic domenic closed this as completed Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants