kotas / gulp-tsc

gulp.js plugin for compiling TypeScript files
69 stars 37 forks source link

Declaration files get the wrong reference #26

Closed daanwissing closed 10 years ago

daanwissing commented 10 years ago

I have the following in my gulpfile.js:

gulp.task("typescript", function() {
     return gulp.src([
            "/**/*.ts",
        ], {base: "."})
        .pipe(gulpFilter("!**/*.d.ts"))
        .pipe(typescript({
            module: "commonjs",
            declaration: true,
            target: "es5",
        }))
        .pipe(gulp.dest("."))
});

This generates all .js and .js.map files correctly and the .d.ts files look fine too, except that any reference to a .d.ts file (e.g. /// <reference path="../typings/lib.d.ts"/>) will get mangled to one level too far back and becomes /// <reference path="../../typings/lib.d.ts"/>, which is of course wrong, because the .d.ts files are written in the same directory as the .ts source files.

I did a bit of debugging here, and I think that the reason for this behavior is because the files are first generated to a temporary directory (gulp-tsc-tmp-*) and then copied back to their eventual destination. Because I used gulp.dest(".") I assumed that these references would stay intact, but apparently they do not.

kotas commented 10 years ago

Thank you for reporting this!

I have published v0.9.2 to fix this issue. Could you check if it fixes your problem?

Remember you have to specify outDir option to get correct paths. Read Path modification section for details.

Your gulp task would be:

gulp.task("typescript", function() {
     return gulp.src([
            "/**/*.ts",
        ], {base: "."})
        .pipe(gulpFilter("!**/*.d.ts"))
        .pipe(typescript({
            module: "commonjs",
            declaration: true,
            target: "es5",
            outDir: "."          // ADDED
        }))
        .pipe(gulp.dest("."))
});
daanwissing commented 10 years ago

Hi Kotas, Tried it just a moment ago, works like a charm! Thanks for quickly fixing this bug, good work!