omsmith / browserify-ngannotate

57 stars 7 forks source link

Enable sourcemap support #8

Closed ruimarinho closed 9 years ago

ruimarinho commented 10 years ago

I've been trying to add sourcemap support by using convert-source-map to parse the original sourcemap from ngAnnotate. However, I have been unable to apply an existing source map if one exists in the original file. This is particularly frustrating when using another browserify transform, such as es6ify, because they are not merged.

Any idea on how to support this? Maybe @thlorenz can give us a hint here :)

This is my (failed) attempt:

var compiled = annotateResult.src;
var originalSourceMap = convert.fromSource(compiled);
var newSourceMap = convert.fromJSON(annotateResult.map);

if (originalSourceMap) {
  compiled = convert.removeComments(compiled);

  var generator = SMGenerator.fromSourceMap(new SMConsumer(originalSourceMap.toObject()))

  newSourceMap = newSourceMap.toObject();

  generator.applySourceMap(new SMConsumer(newSourceMap), file);

  newSourceMap = convert.fromObject(generator.toJSON());
}

this.push(compiled + '\n' + newSourceMap.toComment() + '\n');
thlorenz commented 10 years ago

combine-source-map may be useful here. It handles both cases:

omsmith commented 10 years ago

I'd rather see ng-annotate's sourcemap support accept input sourcemaps and deal with it it there, as has been mentioned in olov/ng-annotate#75

If that doesn't come to fruition, I would eventually add support here for sure.

ruimarinho commented 10 years ago

@omsmith I'm not sure if it should be each tool accepting an input sourcemap or the build util combining them whenever necessary - gulp-sourcemaps does this for gulp, so browserify could do the same for each transform that generates an output sourcemap.

@thlorenz would that work well for sourcemaps coming from es6ify (files sources appended with .es6)?

thlorenz commented 10 years ago

I'm not sure, dig through the browser-pack code to see if it does anything special for .js vs. other files.

kloy commented 10 years ago

Is there an example anywhere of this working?

omsmith commented 9 years ago

Experimenting with browserify debug and ng-annotates new sourcemap support. Making sure it all works as I would expect

omsmith commented 9 years ago

Published in 0.7.0