mgol / grunt-ng-annotate

Add, remove and rebuild angularjs dependency injection annotations
MIT License
222 stars 29 forks source link

Is there a way to pass a sourcemap to ngAnnotate? #33

Open subtubes-io opened 9 years ago

subtubes-io commented 9 years ago

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?

mgol commented 9 years ago

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.

stefan-- commented 8 years ago

@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?

mgol commented 8 years ago

@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?

stefan-- commented 8 years ago

@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?

mgol commented 8 years ago

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.

stefan-- commented 8 years ago

@mzgol it works with ng-annotate

mgol commented 8 years ago

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

stefan-- commented 8 years ago

@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!

mgol commented 8 years ago

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?

stefan-- commented 8 years ago

@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.

SuneRadich commented 8 years ago

Any news on this issue?

mgol commented 8 years ago

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