Munter / express-systemjs-translate

Express middleware to speed up systemjs development loads by running translations serverside
28 stars 4 forks source link

map file support #172

Closed lookfirst closed 8 years ago

lookfirst commented 8 years ago

Ok, things are working now, but if I throw a 'debugger' line into my javascript, it doesn't stop in the map file generated source, but instead just shows the actual source code.

Munter commented 8 years ago

Ah, forgot about source maps. Try passing in sourceMaps: true in the buildFlags and see if that gives you what you expect. If not I'll have do do some extra work to make source maps work.

This is all really good feedback :D

Munter commented 8 years ago

This branch should add sorucemaps. I haven't had time to create a setup to verify that all paths are correct. It's bedtime on my end, so I'll pick this up and verify some time tomorrow. If you would like to try this branch immediately to help me verify npm install Munter/express-systemjs-tranlate#sourcemaps

lookfirst commented 8 years ago

that command fails... can't find the branch.

lookfirst commented 8 years ago

i see the typo

lookfirst commented 8 years ago

The 'tree' for the sourcemaps are made, but the 'file' shows up blank in chrome.

Munter commented 8 years ago

Sounds like the paths might not be entirely correct. First step though

lookfirst commented 8 years ago

How can I help? =)

lookfirst commented 8 years ago

Just noticed this in my web server log, which appears to be the result of trying to load the source file... /js/sell/js/sell/sell/ordersModule.js

It should be: /js/sell/ordersModule.js

Munter commented 8 years ago

So I have source maps working locally now and just need to make it a bit pretty. But one problem still remains. The source of the requested file will never show the original content. It always shows the served bundle. Doesn't matter if I send sourcesContent in the source map or not. This seems to be because of the conflicting file name. Sending a Vary: Accept header does not make the browser reconsider what to show in the sources tab.

The only way I can think of fixing this right now is to redirect to a different file name when responding to a request with Accept: application/x-es-module, just to get the name of the original resource unblocked. That feels a bit ugly to me though.

Any other ideas? @gustavnikolaj @papandreou @guybedford

Munter commented 8 years ago

I have created this page to show an example of the problem I'm encountering: http://source-map-sources.surge.sh/

Munter commented 8 years ago

Redirecting to a different url that serves the bundle doesn't work. the sources tab will show the source as if it came from the originally requested url.

@papandreou suggested modifying the url of the bundle target in the source mapsources array, appending a ?original query or similar. I tried implementing it and that seems to at least get the source visible under this new fake name in the dev tools sources tab. But I couldn't get breakpoints to work as the file apparently then becomes unrelated

lookfirst commented 8 years ago

@Munter thanks for your hard work on this. i'm excited to use it when it is working. =)

guybedford commented 8 years ago

Just had a look at this and the inlined sourceMappingURL seems to be missing the leading # character after the comment?

lookfirst commented 8 years ago

screenshot: http://take.ms/bBBPc

Munter commented 8 years ago

I merged my source map branch. All sources which are not in the original file requested should now be shown correctly. I'm still having trouble with getting browsers to display the original source for the requested file, as all browers I have tested in will show resuested.js (translate bundle) instead of requested.js (source map sources). You can test the current state by installing from the master branch. I haven't cut a release yet as I'm not confident with the missing tests right now

Munter commented 8 years ago

And finally I found the thing I missed. https://www.npmjs.com/package/inline-source-map-comment strips source map sourcesContent by default. DOH!

Munter commented 8 years ago

Released in 3.1.0

lookfirst commented 8 years ago

I wish you could close this, but it still isn't working for me. =( Now it just isn't running my code at all. I can also see multiple 'app.js' files in the inspector tree even though there should only be one in /sell/app.js. The one in /sell/app.js is blank and the other one has the System.register wrapped output..

screenshot: http://take.ms/iVqel

Munter commented 8 years ago

I think you need to set the serverRoot config option. Looks like the paths for app.js are different. They shouldn't be

lookfirst commented 8 years ago

I have serverRoot set.

Munter commented 8 years ago

Please enable the debug option and copy sourcesRoot and sources from the debug sourcemap that is injected at the bottom of the bundles response. That might help me figure out if there is a bug in the path resolving between serverRoot and systemjs baseURL

Munter commented 8 years ago

v4.0.0 is out. serverRoot is now required and normalization is false by default: https://github.com/Munter/express-systemjs-translate/releases/tag/v4.0.0