concat-with-sourcemaps icon indicating copy to clipboard operation
concat-with-sourcemaps copied to clipboard

Generates incorrect source map when one of the input files has an empty source map.

Open insidewhy opened this issue 9 years ago • 5 comments

See https://github.com/wearefractal/gulp-concat/issues/94 and https://github.com/gulpjs/gulp/issues/843#issuecomment-101400811

Currently gulp passes this library empty source maps which cannot be concatenated. You wanted to fix the problem here rather than in gulp-concat, I guess this would entail detecting empty source maps and replacing them with identity source maps.

insidewhy avatar May 13 '15 08:05 insidewhy

@ohjames just for the record - gulp doesn't pass anybody sourcemaps. gulp-sourcemaps is responsible for all of that.

yocontra avatar May 13 '15 18:05 yocontra

I know, but many plugins also touch the source map object attached to the vinyl by gulp-sourcemaps that's why I generically use the term gulp.

insidewhy avatar May 13 '15 18:05 insidewhy

Hi @ohjames, sorry for the late answer. I just tested your example in the gulp-concat thread and it worked fine. Could you set up a repository that shows the error you describe? Thanks!

floridoo avatar Sep 27 '15 18:09 floridoo

If I may breath some life into this issue, the problem reported comes from line 93 (pretty sure)(https://github.com/floridoo/concat-with-sourcemaps/blob/master/index.js#L93)

this._sourceMap.addMapping({
            generated: {
              line: this.lineOffset + i,
              column: (i === 1 ? this.columnOffset : 0)
            },
            original: {
              line: i,
              column: 0
            },
            source: filePath //This sucker right here
          });

When a source map is not included, the mapping that is used uses the file path as the source location (as opposed to sourceMap.sources[0]; if there is a source map). This results in a source location that looks like this
/Users/astoker/Sites/aurelia-cli/test-dep1/src/app.html
as opposed to this
app.html (based off the base url of src).
The result is that when you look in the source mapped version of sources in a browser, you get strange paths that separate html files from js files. Strange meaning that the html files have fully qualified path names, while the js files are defined from the root of the application.

AStoker avatar Oct 25 '16 20:10 AStoker

Example:
screen shot 2016-10-25 at 4 19 42 pm

AStoker avatar Oct 25 '16 20:10 AStoker