You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wire up source maps from transpiled languages #470
perhaps just look for existing fileName.js.map file, then use that as the input source map to the next stage of the transform.
Prefer using fileName.js.map, with .js extension since it is conceivable down the road that there is a fileName.html.map, fileName.js.map. I suppose as a stopgap, also look for fileName.map assuming that it is the map to go into JS.
While that would work for "whole directory" optimizations, single file optimizations, where for example, maybe just out= is used (or in the browser out = function (){}), then it would be nice to pass the maps through the code flow without having to touch disk.
We have this issue. We are coding in TypeScript and would like to use r.js to bundle/minify. However we lose the sourcemaps for debugging purposes. I've always been in the "old school" of generating "PDBs" even for production. There are bugs that only can be reproduced in production environments. If you lose the sourcemap support with release code, debugging becomes much harder.
Ran out of time for this release window, but more thoughts on this:
load.fromText(text, opts), with opts.sourceMap being the source map. During dev, just tack it inline to the evaled code along with the sourceURL?
During a build, optimizer writes the sourceMap to the file system when multifile optimization. For single file optimization, hold on to it until the end, saved out separately(?). For out: function(){}, pass it in opts object as second arg, under sourceMap property.
perhaps just look for existing fileName.js.map file, then use that as the input source map to the next stage of the transform.
Apologies if I'm misunderstanding something, but shouldn't it be possible to completely automatically figure out the source map for a given file? If it's a source-mapped file, then it has a comment saying where the source map is, no?
I'm working with .coffee amd-modules, using a grunt task to compile those to .js amd-modules, each with their own .js to .coffee source-map.
Afterwards, i combine those amd-modules to components using r.js, each component being based on the dependency tree of a certain file. When using uglify2 and enabling sourcemap support, this results in a .js file and a sourcemap for each component - the sourcemap mapping the built .js file to the batch of .js files concatenated into it.
I was thinking about somehow using the uglify2 option in-source-map.
To clarify this - the required files are first concatenated using r.js and the resulting file is optimized afterwards using uglify/uglify2/closure?
That finds the sourcemap if the transpiler provides an existing sourcemap. that's just the beginning of the uglify2 function on line 23363. that function uses the inSourceMap as part of the uglify config object.
Thinking a little higher level, what if every js tool followed the following rule:
Either:
All the artifacts that the tool produces have a different name to the original source file. So for example, in coffeescript, the source file is foo.coffee, and the generated file is foo.js, or with uglify, source file is foo.js, and the generated file is foo.min.js. If the tool does this, then the tool should name the source map by appending .map to the output filename, eg foo.js.map for coffeescript, or foo.min.js.map for uglify.
The tool produces output artifacts that have the same name as the original file, and copies the original source file to have a new filename. This is requirejs. In that case, the tool should name the sourcemap by appending .map to the name of the new name of the input source file. So, requirejs names its source map foo.js.src.js.map. In this case, foo.js will point to foo.js.src.js.map, which will point to foo.js.src.js, which will point to foo.js.map, which will point to foo.coffee.
Pretty much every other tool complies with the first case above, the exception is requirejs. If it were to comply with the second, then I believe no tools would step on each others source maps.
Of course, it's not conventional since the source map file is named according to the original source file, not the output source file. But then, requirejs is already not conventional compared to other tools, since it renames the original source file, and replaces it with the output file.
Thanks for putting thought into managing the tool flow, I'll see how I can integrate that. For the requirejs case, it keeps the names the same because that allows the rest of the project, the HTML, the requirejs.config() used in the project to continue to work without modifications.
Yes, I understand why requirejs is different, and I think that's fine.
We're working on a new web assets pipeline for play framework right now, so we're in a good position to be able to test and give feedback on anything you need testing/feedback for, and we've also done a lot of thinking about how all the different possible tools in the pipeline might fit together, including source maps etc, so we'd be happy to give feedback on any ideas you have.
As far as i can see, we're dealing with two basic scenarios (factoring out JavaScript transpiled in loader plugins).
Plain JavaScript
R.js concatenates multiple JavaScript sources and delivers a concatenated file with a sourcemap that maps the concatenated file to its source files. No multi-level sourcemaps required so far.
When minification using uglify2 is configured, uglify2 then uses this sourcemap as its input sourcemap and delivers a minified version of the concatenated file and a sourcemap that maps the minified, concatenated result to the source files that were used for the concatenation.
This is a two-way mapping and basically works (albeit having a few issues, see Source maps: the names attribute is always empty #672, thanks @thorn0).
Pre-transpiled JavaScript
Using CoffeeScript as example language, r.js concatenates multiple JavaScript sources, each of which has a sourcemap that maps from a single CoffeeScript- to a single JavaScript-file. R.js deliveres a concatenated file with a sourcemap, that maps the concatenated file to its JavaScript source files. At this step, r.js should base the resulting sourcemap on the CoffeeScript to JavaScript sourcemaps by concatenating them instead of building a sourcemap from scratch.
Minification using uglify2 works the same way it does in the previous example.
In reality, this should be a three-way mapping from CoffeeScript sources to JavaScript sources to concatenated JavaScript to minified, concatenated JavaScript.
As r.js seems to utilize mozilla/source-map, mozilla/source-map#105 could probably help.
Activity
clavecoder commentedon Jul 3, 2013
We have this issue. We are coding in TypeScript and would like to use r.js to bundle/minify. However we lose the sourcemaps for debugging purposes. I've always been in the "old school" of generating "PDBs" even for production. There are bugs that only can be reproduced in production environments. If you lose the sourcemap support with release code, debugging becomes much harder.
+1 for sourcemap chaining.
Fixes #470, allow anon wrapped umd pattern with interior modules to w…
jrburke commentedon Jul 8, 2013
Ugh, bad commit comment. That commit is for #460.
jrburke commentedon Jul 8, 2013
Ran out of time for this release window, but more thoughts on this:
pelotom commentedon Nov 27, 2013
Apologies if I'm misunderstanding something, but shouldn't it be possible to completely automatically figure out the source map for a given file? If it's a source-mapped file, then it has a comment saying where the source map is, no?
codepunkt commentedon Dec 5, 2013
+1 for this issue!
I'm working with .coffee amd-modules, using a grunt task to compile those to .js amd-modules, each with their own .js to .coffee source-map.
Afterwards, i combine those amd-modules to components using r.js, each component being based on the dependency tree of a certain file. When using uglify2 and enabling sourcemap support, this results in a .js file and a sourcemap for each component - the sourcemap mapping the built .js file to the batch of .js files concatenated into it.
I was thinking about somehow using the uglify2 option in-source-map.
To clarify this - the required files are first concatenated using r.js and the resulting file is optimized afterwards using uglify/uglify2/closure?
matthewwithanm commentedon Dec 26, 2013
Why is this necessary? Like @pelotom mentioned, the map filename should be in the compiled output, no?
DrSammyD commentedon Dec 26, 2013
@matthewwithanm Nevermind, it is in the compiled output.
matthewwithanm commentedon Dec 26, 2013
Neat! Seems to me that using that is much less fragile than making assumptions about filenames.
DrSammyD commentedon Dec 27, 2013
There, now we check each js file for it's existing map instead of making assumptions about file names
codepunkt commentedon Dec 27, 2013
How does this help getting sourcemaps for transpiled languages?
DrSammyD commentedon Dec 27, 2013
That finds the sourcemap if the transpiler provides an existing sourcemap. that's just the beginning of the uglify2 function on line 23363. that function uses the inSourceMap as part of the uglify config object.
I'm just making it so that it uses the reference from the javascript file instead of making assumptions about file naming.
DrSammyD commentedon Dec 27, 2013
Should I do a pull request for this?
7 remaining items
jroper commentedon Mar 20, 2014
Thinking a little higher level, what if every js tool followed the following rule:
Either:
foo.js, or with uglify, source file isfoo.js, and the generated file isfoo.min.js. If the tool does this, then the tool should name the source map by appending.mapto the output filename, egfoo.js.mapfor coffeescript, orfoo.min.js.mapfor uglify..mapto the name of the new name of the input source file. So, requirejs names its source mapfoo.js.src.js.map. In this case,foo.jswill point tofoo.js.src.js.map, which will point tofoo.js.src.js, which will point tofoo.js.map, which will point tofoo.coffee.Pretty much every other tool complies with the first case above, the exception is requirejs. If it were to comply with the second, then I believe no tools would step on each others source maps.
Of course, it's not conventional since the source map file is named according to the original source file, not the output source file. But then, requirejs is already not conventional compared to other tools, since it renames the original source file, and replaces it with the output file.
jrburke commentedon Mar 20, 2014
Thanks for putting thought into managing the tool flow, I'll see how I can integrate that. For the requirejs case, it keeps the names the same because that allows the rest of the project, the HTML, the requirejs.config() used in the project to continue to work without modifications.
jroper commentedon Mar 20, 2014
Yes, I understand why requirejs is different, and I think that's fine.
We're working on a new web assets pipeline for play framework right now, so we're in a good position to be able to test and give feedback on anything you need testing/feedback for, and we've also done a lot of thinking about how all the different possible tools in the pipeline might fit together, including source maps etc, so we'd be happy to give feedback on any ideas you have.
codepunkt commentedon Apr 29, 2014
As far as i can see, we're dealing with two basic scenarios (factoring out JavaScript transpiled in loader plugins).
R.js concatenates multiple JavaScript sources and delivers a concatenated file with a sourcemap that maps the concatenated file to its source files. No multi-level sourcemaps required so far.
When minification using uglify2 is configured, uglify2 then uses this sourcemap as its input sourcemap and delivers a minified version of the concatenated file and a sourcemap that maps the minified, concatenated result to the source files that were used for the concatenation.
This is a two-way mapping and basically works (albeit having a few issues, see Source maps: the names attribute is always empty #672, thanks @thorn0).
Using CoffeeScript as example language, r.js concatenates multiple JavaScript sources, each of which has a sourcemap that maps from a single CoffeeScript- to a single JavaScript-file. R.js deliveres a concatenated file with a sourcemap, that maps the concatenated file to its JavaScript source files. At this step, r.js should base the resulting sourcemap on the CoffeeScript to JavaScript sourcemaps by concatenating them instead of building a sourcemap from scratch.
Minification using uglify2 works the same way it does in the previous example.
In reality, this should be a three-way mapping from CoffeeScript sources to JavaScript sources to concatenated JavaScript to minified, concatenated JavaScript.
As r.js seems to utilize mozilla/source-map, mozilla/source-map#105 could probably help.
thorn0 commentedon Apr 29, 2014
The first scenario doesn't work that fine. See #672 (the names attribute is always empty).
Wiring up existing source maps of transpiled codes
Wiring up existing source maps of transpiled codes
dotnetwise commentedon Jul 30, 2014
+1
grapswiz commentedon Oct 25, 2014
+1
david0178418 commentedon Oct 20, 2015
Though, it seems that this is a dead issue, +1 for me too.
Has anyone come up with a work-around? Specifically, I'm in scenario 2 (Developer used a command line tool to generate the transpiled JS.)
DrSammyD commentedon Oct 20, 2015
@david0178418 This tool can create source maps directly back to original source.
https://github.com/Rich-Harris/sorcery