These are chat archives for systemjs/systemjs

6th
May 2015
Sam Seay
@samueljseay
May 06 2015 02:29
Hi, does anyone know, when creating a custom module format extension is there a way in System.js to get a hook in before the file is fetched? ie to determine some custom fetching logic?
Sam Seay
@samueljseay
May 06 2015 04:20
Another question, I'm wondering if anyone else has run into is it appears that an inline script is created for performing an eval over required modules? I get hundreds of CSP unsafe eval errors.
Sam Seay
@samueljseay
May 06 2015 10:52
ur sorry i mean 'unsafe-inline'. I have relaxed my CSP, assume there is a good reason inline script is created
Guy Bedford
@guybedford
May 06 2015 10:54
@samueljseay yes script injection is used for evaluation to ensure global execution bindings work identically to script tags
there is a csp build of systemjs for CSP policies
Sam Seay
@samueljseay
May 06 2015 10:54
oh right. thanks. I'll check that out
Guy Bedford
@guybedford
May 06 2015 10:54
but it requires you to compile all your scripts into either System.register or AMD first
it has limited support, and is usually best used after running a bundle of your whole app
Sam Seay
@samueljseay
May 06 2015 10:55
ok thanks. thats really helpful info :)
System.js is awesome by the way. I'm a big fan of the work you do. :)
Guy Bedford
@guybedford
May 06 2015 10:58
thanks!
Mike Haas
@mikehaas763
May 06 2015 15:33
When using the systemjs loader, is the idea that you just deploy node_modules along with your app into your site root? Seems weird to deploy node_modules but I don't think there would really be another solution except for using the builder to bundle
Nelo Mitranim
@Mitranim
May 06 2015 15:38
For most applications, you want to make a single bundle-sfx and deploy just that
If you really want to decompose your app and load some modules dynamically, you'll have to deploy those separately
It can be bundles or your whole jspm_packages folder
Mike Haas
@mikehaas763
May 06 2015 15:40
And for development just deploy node_modules, jspm_packages etc? I don't want to bundle for development. I'm honestly not even too sure if I will bundle for production either because it's a cordova app so I don't really have any http overhead
Micah Zoltu
@MicahZoltu
May 06 2015 15:46
@mikehaas763 Yeah, for development I "deploy" those two folders is all.
(I run my development server pointed at my repo root, so they are accessible)
If you want to move them away from root of the web server you have to update config.js.
Mike Haas
@mikehaas763
May 06 2015 15:50
@Zoltu thanks for the info. Right now my build process runs and dumps everything into a dir. I then run the server root from that dir. Not sure exactly how I would set the project up like yours
Micah Zoltu
@MicahZoltu
May 06 2015 16:02
You could just copy those two folders into that folder as well @mikehaas763.
The trick is your config.js file and/or any additional System.config calls you have during your application startup.
Mike Haas
@mikehaas763
May 06 2015 16:03
@Zoltu Yep I'm doing that right now. It adds 20 seconds to my build lol
Micah Zoltu
@MicahZoltu
May 06 2015 16:03
Ah.
Mike Haas
@mikehaas763
May 06 2015 16:03
I was hoping to find a way other than just a plain "copy" to the build output. Oh well it will have to make due for now
Micah Zoltu
@MicahZoltu
May 06 2015 16:04
You could setup your config.js to point elsewhere, assuming your server can serve those files.
Or you could do a symlink... that may be best.
Mike Haas
@mikehaas763
May 06 2015 16:04
Ahh a symlink may not be a bad idea
Micah Zoltu
@MicahZoltu
May 06 2015 16:04
Your webserver just needs to find host/jspm_packages/...
So do whatever you need to to make ^ happen and you won't have to copy.
Mike Haas
@mikehaas763
May 06 2015 16:06
Hopefully I can find a gulp-plugin or some other way to handle "symlinks" on windows
Because some people on my team are on win
Mike Haas
@mikehaas763
May 06 2015 17:51
I'm just curious. What magic trick does systemjs perform to detect what's been added to the global object when importing a global script?
That maybe sounded weird... I'm just wondering high-level what the implementation is for detecting
Mike Haas
@mikehaas763
May 06 2015 18:19

I'm using ES6 modules + systemjs for the loader. I use my own angular modules like this:

import SomeAngularModule from './SomeAngularModule';
angular.module('anotherModule', [SomeAngularModule.name]);

Now, if I've downloaded a 3rd party angular module with npm that is not an ES6 module that exports the module, is it possible to configure systemjs to export the module relevant angular module? something like exports: ['angular.module("3rd-party-module")']?

Guy Bedford
@guybedford
May 06 2015 18:30
@mikehaas763 good question - I've created systemjs/systemjs#442
basically it iterates the globals and takes a snapshot before and after execution, before comparing
no easy way to write angular.module - unfortunately that's always repetitive
you can export a global though
interesting idea though having exports as an expression
Mike Haas
@mikehaas763
May 06 2015 18:32
@guybedford meaning I could have exports: ['someGlobal'] right?
Guy Bedford
@guybedford
May 06 2015 18:32
System.meta['some/module'] = { exports: 'global.name' }
Mike Haas
@mikehaas763
May 06 2015 18:32
Yep that's what I meant. Is the exports key allows to be an array?
Guy Bedford
@guybedford
May 06 2015 18:33
no just a string
why would you want it to be an array?
Mike Haas
@mikehaas763
May 06 2015 18:34
Isn't it just the explicit form of when system automatically detects globals?
Guy Bedford
@guybedford
May 06 2015 18:35
yes, but would you want that?
Mike Haas
@mikehaas763
May 06 2015 18:35
No I currently don't need it I just figured being that a module can export multiple things a global script should be allowed to "export" multiple things
Guy Bedford
@guybedford
May 06 2015 18:36
it's an interesting and attractive idea, not sure how useful it is
definitely worth considering if a use case comes up
Mike Haas
@mikehaas763
May 06 2015 18:37
Actually I just remembered there is one case I needed it. I'm using ionic which by default bundles an angular version to avoid compatibility problems. I was trying to export both the ionic module and angular from that global script
Guy Bedford
@guybedford
May 06 2015 18:38
was the automatic detection catching that ok?
Created systemjs/systemjs#443
Mike Haas
@mikehaas763
May 06 2015 18:41
Not exactly. It was detecting angular because angular defines a global. However I couldn't import ionic modules essentially because of the same reason as I mentioned above.
Mike Haas
@mikehaas763
May 06 2015 18:47
Actually, I take that back. By default it was detecting an exported string "ui.router" because ui-router is also bundled but is nice enough to export itself for CJS. I then tried explcitly settings exports: 'angular' for it and was able to export angular also.
@guybedford If having expressions for a configured export was a reasonable feature, off the top of your head what would you use to actually execute the expression?
Guy Bedford
@guybedford
May 06 2015 18:51
that's the problem it's not csp-compatible
currently globals can be made csp-compatible if you declare exports
Mike Haas
@mikehaas763
May 06 2015 18:59
Ya that was my thinking because isn't eval() blocked by CSP?
So would have to write a parser to translate it into runtime accessors or something lol. Not pretty.
Mike Haas
@mikehaas763
May 06 2015 19:28
Is the difference between maps and paths configuration whether it's resolved before or after the path normalization stage?
Guy Bedford
@guybedford
May 06 2015 22:02
@mikehaas763 map is in normalize, paths is just before fetching, in locate.