On Friday, 2012-03-23 at 18:14 , David Herman wrote:
> On Mar 23, 2012, at 5:05 PM, Irakli Gozalishvili wrote: > > > I'v being trying to figure out how ES.next module path resolution would > > work. Unfortunately proposal is not very clear about it: > > http://wiki.ecmascript.org/doku.php?id=harmony:modules > > There's more info about the resolution semantics on the loaders page: > > http://wiki.ecmascript.org/doku.php?id=harmony:module_loaders > > Basically loaders make it possible for programmers to create custom > resolution policies. > > But your question is probably more about what the default policy of the > System loader will be on the web. Yeap! > First of all, the System loader's baseURL (should it be baseURI? I never > understood the difference) would come from the document's URL. So relative > would definitely be relative the HTML file. Yeah so by default `document.baseURI` is just a `document.documentURI` or simply URL to the html document. All the relative URLs on that document resolve to the `document.baseURI`. Also, there is an html `base` tag that allows one to set value of `document.baseURI` and there for change relative url resolution. More details can be found in HTML spec: http://www.w3.org/TR/html401/struct/links.html#h-12.4 > > > Here are some of the questions I have: > > > > 1. Will html [base element] have a same effect on modules as it has on > > script tags today ? > > 2. Are relative paths resolved to a requirer's url, owner html document's > > urlor baseURI ? > > > > If my assumptions are correct this little example is correct: > > https://github.com/Gozala/packageless/tree/master/examples/es.next/ > > > > [base element]:https://developer.mozilla.org/en/HTML/Element/base > > These are really good points I hadn't thought about. Thanks for bringing it > up! I like the idea that > > ./foo.js > > forces the loading to be relative to the document, whereas > > bar/baz.js > > is interpreted as relative to the <base> path. I don't have strong feelings > myself about what the System loader's policy should be on the web, but I want > to make sure our infrastructure is flexible enough to support a) whatever > everyone decides is the best policy for the browser, and b) policies like the > Node.js / NPM policy. I will have to read up a little more on > document.baseURI and <base> and all that. Let me elaborate a bit on what my intent is: Usually any app / lib code is organized such that third party dependencies are located in an separate directory from an actual program code. This helps to reduce noise for a human eye and also make it easier to work with version control systems, since third party code is commonly not tracked in the same repository. I think it's pretty important to have good support for this. One cleanest way IMO would be to have different resolution login for dependencies: A. ./foo.js ../foo/bar.js B. foo.js, foo/bar.js I'd suggest to resolve A type paths relative to a requirer (ether require module url, or document url). And resolve B type paths relative to a `document.baseURI`. That would allow users to organize codebase as described above and show in the example repo: https://github.com/Gozala/packageless/tree/master/examples/es.next/ Also not that this is somewhat similar to nodejs behavior where `./foo, ../foo/bar` form is used for resolving modules relative to the requirer. While `foo, foo/bar` form is used for installed package dependencies. Unfortunately nodejs policies are bit more complicated than that since `foo` form there won't look in just one `baseURL` instead it does recursive upward search in `node_modules` folders which I don't think is compliant with web. That being said though I think it would map simple cases pretty well. > > Thanks for the information and ideas! > > Dave Regards
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

