ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
831 stars 129 forks source link

Sourcemaps are not generated correctly when using gulp-header plugin. #597

Open frenchu opened 5 years ago

frenchu commented 5 years ago

Expected behavior:

Sourcemaps are generated properly even if intermediate plugins are used.

Actual behavior:

When I use gulp-header plugin in the gulp pipe, sourcemaps are generated but it is not possible to put breakpoints in the right place in the source code while debugging in Chrome Dev Tools. When I disable gulp-header plugin sourcemaps are generated correctly. As stated in gulp-header plugin documentation it supports sourcemaps, I've also made tests and it looks like it works fine. Moreover, I've tried to use other similar plugins to gulp-header, which support sourcemaps and the issue persists.

gulpfile:

var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json');

gulp.task('default', function () {
    return tsProject.src()
        .pipe(sourcemaps.init())
        .pipe(header('//Hello <%= name %>\n\n', { name: 'frenchu' }))
        .pipe(tsProject())
        .pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '..' }))
        .pipe(gulp.dest('dist'));
});

tsconfig.json:

{
  "files": [
    "src/app.ts",
    "src/path/to/module/greet.ts"
  ],
  "compilerOptions": {
    "module": "amd",
    "outFile": "module.js",
    "noImplicitAny": true,
    "target": "es5"
  }
}

Code:

Sample project where you can replicate the issue is here: github.com/frenchu/sourcemaps-issue

Remarks:

The reason of this issue may be similar to #576.