Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init({ loadMaps: true }) does not remove sourcemaps added earlier in the same pipeline #218

Open
kjots opened this issue Aug 11, 2016 · 12 comments

Comments

@kjots
Copy link

kjots commented Aug 11, 2016

If a sourcemap is written, and then subsequently loaded and written again in the same pipeline, then the final output contains both sourcemaps.

For example, given the following input file (test.es6.js):

let value = 'Test Value';

console.log(`value: ${ value }`);

When running the following Gulp script:

import gulp from 'gulp';
import gulpBabel from 'gulp-babel';
import gulpRename from 'gulp-rename';
import gulpSourcemaps from 'gulp-sourcemaps';

gulp.task('test.es5.js', [], () => {
    return gulp.src('test.es6.js')
        .pipe(gulpSourcemaps.init())
        .pipe(gulpBabel())
        .pipe(gulpRename('test.es5.js'))
        .pipe(gulpSourcemaps.write())
        .pipe(gulpSourcemaps.init({ loadMaps: true }))
        .pipe(gulpSourcemaps.write())
        .pipe(gulp.dest('.'))
});

Then the following output is produced (test.es5.js):

'use strict';

var value = 'Test Value';

console.log('value: ' + value);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxRQUFRLFlBQVo7O0FBRUEsUUFBUSxHQUFSLGFBQXVCLEtBQXZCIiwiZmlsZSI6InRlc3QuZXM1LmpzIiwic291cmNlc0NvbnRlbnQiOlsibGV0IHZhbHVlID0gJ1Rlc3QgVmFsdWUnO1xuXG5jb25zb2xlLmxvZyhgdmFsdWU6ICR7IHZhbHVlIH1gKTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxRQUFRLFlBQVo7O0FBRUEsUUFBUSxHQUFSLGFBQXVCLEtBQXZCIiwiZmlsZSI6InRlc3QuZXM1LmpzIiwic291cmNlc0NvbnRlbnQiOlsibGV0IHZhbHVlID0gJ1Rlc3QgVmFsdWUnO1xuXG5jb25zb2xlLmxvZyhgdmFsdWU6ICR7IHZhbHVlIH1gKTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

If the pipeline is separated into two stages, with the file being output via gulp.dest() after the first sourcemap is written and then a new pipeline is created via gulp.src(), then the first sourcemap is removed as expected:

'use strict';

var value = 'Test Value';

console.log('value: ' + value);


//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxRQUFRLFlBQVo7O0FBRUEsUUFBUSxHQUFSLGFBQXVCLEtBQXZCIiwiZmlsZSI6InRlc3QuZXM1LnN0ZXAtMi5qcyIsInNvdXJjZXNDb250ZW50IjpbImxldCB2YWx1ZSA9ICdUZXN0IFZhbHVlJztcblxuY29uc29sZS5sb2coYHZhbHVlOiAkeyB2YWx1ZSB9YCk7Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
@nmccready
Copy link
Collaborator

@kjots is this a problem against master as well?

@nmccready nmccready modified the milestones: 2.0.0, 1.7.0 Oct 10, 2016
@kjots
Copy link
Author

kjots commented Oct 16, 2016

Hi @nmccready, can confirm this issue is still present in gulp-sourcemaps version 2.1.1.

@nmccready
Copy link
Collaborator

I actually think this issue is a dupe, if not another issue is the dupe

@nmccready
Copy link
Collaborator

#222

@felixfbecker
Copy link

felixfbecker commented Dec 16, 2016

Hitting this problem:

    browserify('src/bootstrap.js', {debug: true})
      .bundle()
      .pipe(source('src/bundle.js'))
      .pipe(buffer())
      .pipe(sourcemaps.init({loadMaps: true}))
      .pipe(sourcemaps.write('.', {sourceRoot: fileUri(__dirname)})
      .pipe(gulp.dest('dist'))

the .map file is correctly written, but the inline sourcemap generated by Browserify is not removed and no sourceMapURL added. This means the browser will use the inline sourcemap instead of the file

@otakustay
Copy link

I have the same problem:

rollup(merge(ROLLUP_CONFIG, {entry: './src/index.js'}))
            .pipe(source('index.js', './src/*'))
            .pipe(buffer())
            .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(sourcemaps.write('./map'))
            .pipe(gulp.dest('.'));

This ended with a map/index.js.map file along with an inline sourcemap so the external .map file would never be used.

Another task includes an uglify step and it output the .map file and a correct sourceMappingURL

rollup(merge(ROLLUP_CONFIG, {entry: './src/index.js'}))
            .pipe(source('index.js', './src/*'))
            .pipe(buffer())
            .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(uglify(UGLIFY_OPTIONS))
            .pipe(rename({suffix: '.min'}))
            .pipe(sourcemaps.write('./map'))
            .pipe(gulp.dest('.'));

The essential difference is the uglify step

@dfreedm
Copy link

dfreedm commented Dec 20, 2016

A quick git-bisect leads to 6972337

@nmccready
Copy link
Collaborator

A quick git-bisect leads to 6972337

Yeah, I will need add another spec to cover this case and figure out how to work around or remove preExisting.

@felixfbecker
Copy link

Please consider this a high priority, it made debugging our clients impossible. Maybe even revert whatever introduced this for the time being?

@nmccready
Copy link
Collaborator

Use the previous release 2.2.0 or 1.9.0

@wvankuipers
Copy link

Use the previous release 2.2.0 or 1.9.0

In my case downgrading to 2.2.0 resolved this issue!

@felixfbecker
Copy link

Downgrading to 2.2 did not fix it for me (with the Gulptask I posted above)

@phated phated modified the milestone: 2.0.1 Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

7 participants