These are chat archives for systemjs/systemjs

6th
Jan 2016
Theo Sherry
@theosherry
Jan 06 2016 00:26
What is the "normalized name" of a module that is registered in a System instance?
Adam Hoddinott
@NervosaX
Jan 06 2016 00:28
System.normalize you mean?
Theo Sherry
@theosherry
Jan 06 2016 00:31
In the documentation https://github.com/systemjs/systemjs/blob/master/docs/system-api.md#systemgetmodulename---module it says to give the "normalized name" of the module as an argument for various methods, but I can't find any definition of what that would be.
Adam Hoddinott
@NervosaX
Jan 06 2016 00:44
@theosherry So the normalized name is the full url path to where your package is. So not "yourfile.js" instead "http://localhost:8000/lib/yourfile.js"
You can get the normalized path by using System.normalizeSync("lodash") => http://localhost:8000/jspm_packages/npm/lodash/lodash.js or whatever your package is.
Theo Sherry
@theosherry
Jan 06 2016 00:53
Thanks. Do you know if System.defined() gives a list of registered modules? I'm trying to retrieve a module that should be registered, and it shows up in System.defined(), but when System.has(normalizedName) is giving false
Adam Hoddinott
@NervosaX
Jan 06 2016 00:54
Sorry, I've not needed to use defined
System._loader.modules has all the loaded stuff, but obviously that's a private method
One of the methods must be a wrapper
Theo Sherry
@theosherry
Jan 06 2016 00:57
Ok, thanks a lot. I'll keep digging around
Jayson Harshbarger
@Hypercubed
Jan 06 2016 03:17
If anyone is interested I managed to load the twitter JS interface using system JS. http://bl.ocks.org/Hypercubed/76a1bf7b7d276b1548a0
Previously had to add a script tag (manually or via js) or use https://github.com/Prinzhorn/twitter-widgets
Guy Bedford
@guybedford
Jan 06 2016 07:46
@Hypercubed thanks for the example. I've just been playing around with this, and it can work without the scriptLoad: true as SystemJS assumes script load when format: 'global' is set with exports
I've also just been working on the 0.15 builder to support the map config version and automatic exclusions feature, which should make this nicer too!
(no build: false or paths config necessary)
Chris Grant
@ChrisGrant
Jan 06 2016 08:31
This message was deleted
This message was deleted
Connor Wyatt
@connorwyatt
Jan 06 2016 09:46
Hi all, I am currently unit testing a typescript angular 2 project that uses systemjs and I want to mock the file that is requested in the import statement.

I have

import {CustomValidators} from '../../services/customValidators';

And in the unit tests I want to mock the CustomValidators class. Is there any way to temporarily override the path to the systemjs module?

Thanks in advance for any support
Connor Wyatt
@connorwyatt
Jan 06 2016 10:00
I'm kinda feeling like it isn't going to be possible as I think that systemjs will have already imported the file by the time my unit test file is run, and that would mean having an override in every unit test, meaning that I wouldn't be able to test the file that I mocked as that test would also be using the mocked version.
Nonetheless, any ideas/comments would be appreciated :smile:
Peter Uithoven
@peteruithoven
Jan 06 2016 10:04
@connorwyatt I found the following solution, would be awesome if the idea could be wrapped into a more general, readable tiny library:
https://github.com/peteruithoven/mocking/blob/master/test/index.js
Connor Wyatt
@connorwyatt
Jan 06 2016 10:31
@peteruithoven Yeah I agree, so in your example you use normalizeSync to override a module that is already loaded? Thanks for the response btw :+1:
Peter Uithoven
@peteruithoven
Jan 06 2016 10:34
I use normalizeSync to get the actual name/path, then use System.set to override that module and then reimport that module that depended on it
Connor Wyatt
@connorwyatt
Jan 06 2016 10:34
Oh okay, I'm just about to try it now, thanks for the tip and nice find
Peter Uithoven
@peteruithoven
Jan 06 2016 10:49

@connorwyatt It would be awesome if we could just do something simple like:

importWithMock('../src/randomColor.js’, '../src/random.js’, {
  default: () => randomValue // return our custom value
}).then(callback);

instead of something like

  // override random.js
  System.set(System.normalizeSync('../src/random.js'), System.newModule({
    default: () => randomValue // return our custom value
  }));
  // reimport randomColor, pass to callback
  return System.import('../src/randomColor.js').then(callback);

(I removed getting the module.default by default)

Connor Wyatt
@connorwyatt
Jan 06 2016 11:03
@peteruithoven That would be nice, once I get it working I might look into writing a little library for that
Having a bit of trouble at the minute getting it up and running though
I think I'm replacing it after it has been used at the moment
Peter Uithoven
@peteruithoven
Jan 06 2016 11:21
You're are working with a promise / callback right? because the System.import is async.
Connor Wyatt
@connorwyatt
Jan 06 2016 11:22
Yeah I am, I'm stepping through systemjs now to see where my issue is
Jayson Harshbarger
@Hypercubed
Jan 06 2016 11:27
@guybedford No problem. I added some notes to the gist.
Connor Wyatt
@connorwyatt
Jan 06 2016 12:05
@peteruithoven Still having issues getting the override to work as I am using angular2 and it appears that the describe function queues the tests rather than running them immediately
That means that the tests aren't registered as the promise hasn't resolved
I'm going to need to dig a little deeper
Connor Wyatt
@connorwyatt
Jan 06 2016 12:18
The good thing is, the import is working and bringing in the module correctly
Peter Uithoven
@peteruithoven
Jan 06 2016 12:18
@connorwyatt What framework are you using? I've used Tape in that experiment.
Connor Wyatt
@connorwyatt
Jan 06 2016 12:19
Angular2 wraps jasmine
so just that at the minute
but I've got round that issue
my issue now is that the override isn't working as planned
I think my path is wrong
Guy Bedford
@guybedford
Jan 06 2016 13:34
@Hypercubed nice note the script assuption for globals is only when exports is set as well as we cant do sync global detection for script loading
Jayson Harshbarger
@Hypercubed
Jan 06 2016 14:29
@guybedford so I should say: "scriptLoad defaults to true if format === 'global' and exports is defined"?
C凉凉D
@cdll
Jan 06 2016 14:47
halo~
could i use systemjs to do the ajax data load with headers and authorization set?
Connor Wyatt
@connorwyatt
Jan 06 2016 15:07
@peteruithoven How are you running your project? I'm trying to debug your unit tests to work out how it is working and can't get it running
Guy Bedford
@guybedford
Jan 06 2016 15:20
@Hypercubed and globals is not set :)
Keath Milligan
@keathmilligan
Jan 06 2016 15:31
Just getting started with System.js and I'm running into issues with silent failures. Is there some option to turn on additional error/debug output? I notice the issue is especially bad with Safari
Connor Wyatt
@connorwyatt
Jan 06 2016 16:40

@peteruithoven I have found the difference between our projects that is causing my issues. Our tests are written in typescript and we have imports that are transpiled into a System.registerat the top of the file.

For some reason, this System.register causes the dependency on the file we are importing (random in your case) to be the old one (before we replaced it). If we remove the imports, so there is no System.register, it seems to work. We need these imports really though so could do with working out why this is the case.

Peter Uithoven
@peteruithoven
Jan 06 2016 16:43
@connorwyatt great that you found the reason, I can't find the time at the moment to really help out
Jeremy Danyow
@jdanyow
Jan 06 2016 18:44
mentioning this here because it heavily impacts the performance of SystemJS on Microsoft Edge. Please upvote if you get a chance.
Vlado Tesanovic
@vladotesanovic
Jan 06 2016 19:19
Hey, is anyone succeed to bundle Angular 2 application?
Guy Bedford
@guybedford
Jan 06 2016 20:52
@jdanyow it could be worth looking to see if there are any public browser benchmarks that could be convinced to include promise benchmarks? It's another way to apply pressure on that issue.
Jeremy Danyow
@jdanyow
Jan 06 2016 20:57
sure- will look into that
Guy Bedford
@guybedford
Jan 06 2016 20:58
@jdanyow for example, pdfjs seems to be used in both Octane and Jetstream, and uses promises. Perhaps advocating getting pdfjs from using its internal Promise implementation to using native Promises would help get that pressure vector.