These are chat archives for systemjs/systemjs

23rd
Jul 2015
Matt Ginzton
@metamatt
Jul 23 2015 00:51
Hi. I'm curious about baseURI vs baseURL. I've been using systemjs 0.16, and had things set up so I could load code in the browser the normal systemjs way, then also use systemjs in nodejs to load some of the same code to run a headless test suite. I accomplished this by setting different baseURL values in System.config(). I now am trying to upgrade to systemjs 0.18 and finding that it seems to ignore my baseURL setting. I traced through the code and in the normalize hook I see that it's always using baseURI (which is not configurable) for "page-relative" paths (starting with ., .. or /) while it uses baseURL (which is configurable) only for other paths.
I'm curious if this behavior is documented or if you can explain the intent and how we're supposed to use it, and was it intentional that ../foo falls into the "page-relative" case (not obvious from the comment)?
A separate but somewhat related question is: is it possible, using systemjs in nodejs, to retrieve files from http:// URLs instead of file:// URLs? (baseURI always refers to file://process.cwd, and as above it's usually baseURI that gets used to resolve relative paths)
(I'm trying to read systemjs/systemjs#290 but there's a lot there to digest)
Matt Ginzton
@metamatt
Jul 23 2015 01:16
(also, I've tried finding docs, but https://github.com/ModuleLoader/es6-module-loader/wiki/Configuring-the-Loader is for 0.16 and says see https://github.com/ModuleLoader/es6-module-loader/tree/master/docs for 0.18, but the latter doesn't seem to cover baseURL or baseURI at all)
Micah Zoltu
@MicahZoltu
Jul 23 2015 01:18
@metamatt You can map a module ID to a CDN if that is what you mean.
System.config({
    "map": {
        "jquery": "https://code.jquery.com/jquery-2.1.4.js"
    }
});
Adrian Mitev
@amitev
Jul 23 2015 12:08
hi all! I have an old es5 library that i need to import but it doesn't work for some reason
the variable is undefined
Adrian Mitev
@amitev
Jul 23 2015 12:16
idea what kind of format i should follow in my es5 library
Sharon (Sean) Rolel
@Mosho1
Jul 23 2015 12:16
Would it make sense to use System.import to get JSON data from an api?
It seems to work well, the only thing I can think of would be a problem is refreshing the "module" with a new call
Adrian Mitev
@amitev
Jul 23 2015 12:21
is there an unregister() function? :)
Sharon (Sean) Rolel
@Mosho1
Jul 23 2015 12:26
what if I register over an existing module
Peter Müller
@Munter
Jul 23 2015 13:15
@Mosho1 Unless you explicitly want the caching behavior from system, you should probably use fetch() instead
Matt Ginzton
@metamatt
Jul 23 2015 15:26
@Zoltu: I don't want to do this for a single module ID, I'd want to make all module IDs mean (come from over here, or go get them from over there). Seems I could do this with baseURL in 0.16 but not really in 0.18.
Guy Bedford
@guybedford
Jul 23 2015 16:19
@metamatt baseURL is a SystemJS construct only, documented at https://github.com/systemjs/systemjs/blob/master/docs/overview.md#baseurl
you're exactly right about the behaviour
parent-relative paths ./ ../ are baseURI-relative which is environment-fixed
only "plain paths" are taken to be baseURL-relative
this is to make module specifiers entirely a superset of standard URL behaviours
and leveraging the fact that ./x and x is tautology in URLs
Loading from HTTP paths is not supported in Node currently. Still not sure what use case that would ever serve.
@Mosho1 yes it is best used for data that can be considered cacheable code. A language definition file may well make sense as part of the codebase. A database query that changes regularly should be fetched as data. I guess anything that you'd check into git would probably be the guideline there.
Matt Ginzton
@metamatt
Jul 23 2015 16:41
@guybedford: thanks. Is there any plan or possibility to make baseURI configurable in Node, or does that work at cross purposes to a goal I haven't understood yet? It was really useful to me in Node to be able to tell SystemJS where to look for stuff (I can accomplish this via process.cwd calls if I need to, I suppose, but that seems to have all the downsides of a configurable baseURI plus it's implicit/less obvious)
Guy Bedford
@guybedford
Jul 23 2015 16:42
paths and baseURL are the ways to tell SystemJS where to find things
top-level relative module names are taken to be environment relative URLs
Let me know if that makes sense
Matt Ginzton
@metamatt
Jul 23 2015 16:43
one use case for loading from HTTP paths in Node: (a) our http server synthesizes some resources that aren't actually in the filesystem / static / available otherwise. (b) we find it useful to test our frontend code by loading it in Node (this doesn't work for all frontend code but it works for a surprisingly large subset of it, and I find the tradeoffs to be better than, say, karma or protractor for again a large subset of our frontend code). If you put (a) and (b) together, you end up with a use case for loading from HTTP paths in node (we work around this with some SystemJS loader plugins that accomplish what the http server would have)
Guy Bedford
@guybedford
Jul 23 2015 16:44
right
the generally advised way to deal with that is to use paths configuration that differs between client and server for loading
we could certainly support HTTP in NodeJS quite easily, it's just about doing it in a way that doesn't encourage a footgun really
Matt Ginzton
@metamatt
Jul 23 2015 16:46
OK. I'll give a try using paths configuration instead of baseURL configuration.
Guy Bedford
@guybedford
Jul 23 2015 16:46
There's an example of this in the builder tests - https://github.com/systemjs/builder/blob/master/test/test-build.js#L19
where that resource isn't built, but is loaded on the client
(jquery-cdn)
the build: false exclusion won't work for an sfx bundle though