grunt-ng-annotate icon indicating copy to clipboard operation
grunt-ng-annotate copied to clipboard

Is there a way to pass a sourcemap to ngAnnotate?

Open subtubes-io opened this issue 9 years ago • 12 comments

I am trying to concat, then annotate, then minify and I need to create source-map along the way but not sure I can pass a source-map to ng-annotate. Is this possible?

subtubes-io avatar Jun 25 '15 23:06 subtubes-io

Currently grunt-ng-annotate combines source maps but AFAIK only if the input source map is inline in the generated file. This is mostly handled by ng-annotate, though, I'm mostly just constructing proper options so that it works. Maybe open an issue there? I can add support but only if ng-annotate handles it correctly.

Note, though, that grunt-ng-annotate doesn't support creating a source map for multiple source files (see #26). This shouldn't be an issue if you're concatenating using another task, I guess.

mgol avatar Jul 20 '15 14:07 mgol

@mzgol do I understand you correctly that the following scenario should work?

  1. concat several files and generate an inline source map like //# sourceMappingURL=data:application/json;base64, ...
  2. annotate the concatenated file and create a source map file
  3. the resulting source map should be a combination of both source maps

For me, this does not work. Step 2 does not take into account the inline source map generated in step 1 so that I loose the references to my original files. Instead, the resulting source map (step 3) points to a temporary by-product.

How is this meant to work?

stefan-- avatar Dec 14 '15 11:12 stefan--

@stefan-- Interesting; I have a test for combining source maps that ensures combining with Babel inline source maps works: https://github.com/mzgol/grunt-ng-annotate/blob/259f56efd9f51a32ac1e54ea50f640bcca0efc29/test/spec/api.js#L116-L138. Both the fact that sources point to the original file and the mappings are checked.

Could you post a simple test case showing the bug?

mgol avatar Dec 14 '15 11:12 mgol

@mzgol thanks for your quick response. I just had a look at your test case in order to understand whether it maps to my case and it does with the only difference that the sourcemap from the transpilation has only one source and the sourcemap from my concatenation task has several sources. In addition, babel is capable of adding the sourcesRoot property whereas grunt-contrib-concat does not support it yet.

Any further suggestions?

Is it possible that the sources array within the sourcemap is overridden during the combination?

stefan-- avatar Dec 14 '15 16:12 stefan--

Hmm, OK, it seems a basic example with grunt-contrib-concat should reproduce the problem then. I'll see what I can do (once I find time, it's been busy for me recently).

One thing you could do is to try to run ng-annotate directly on the output of grunt-contrib-concat with proper parameters and see what needs to be passed there to make it work. This is to determine whether the bug lies in the Grunt plugin or ng-annotate itself.

mgol avatar Dec 14 '15 16:12 mgol

@mzgol it works with ng-annotate

stefan-- avatar Dec 14 '15 17:12 stefan--

Could you write how you call it (with what parameters)? I'll check later what I do incorrectly here.

For reference, this is where ng-annotate is called: https://github.com/mzgol/grunt-ng-annotate/blob/259f56efd9f51a32ac1e54ea50f640bcca0efc29/tasks/ng-annotate.js#L168

mgol avatar Dec 14 '15 17:12 mgol

@mzgol just 'solved' the problem. I attempted to save the source map not inline but as a separate file with sourceMap: '/path/to/file'. This is where it fails. Maybe the documentation should take this into account or the lib should support this case. Thanks for your help!

stefan-- avatar Dec 14 '15 17:12 stefan--

Ah, so it breaks not with inline source maps but with external ones?

That's possible, I have a test for combining inline source maps but no test for combining external ones... Does that work with pure ng-annotate? If so, could you post how a snippet showing how you call ng-annotate?

mgol avatar Dec 14 '15 17:12 mgol

@mzgol exactly. It works with pure ng-annotate with the following command ng-annotate -a -o app.annotated.js --sourcemap app.js, however, it does only support an inline source map, as far as I know.

stefan-- avatar Dec 15 '15 09:12 stefan--

Any news on this issue?

SuneRadich avatar Jul 15 '16 12:07 SuneRadich

No news. I'll happily merge a PR if someone submits one.

mgol avatar Jul 30 '16 15:07 mgol