ivogabe / gulp-typescript

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

Allow to read declarations from the stream #603

Closed pepone closed 4 years ago

pepone commented 5 years ago

Is there an option to read the declarations from the stream?

I have a setup like this

const tsc = require("gulp-typescript");
...
pump([
    gulp.src([path.join(root, "*.ice"), "Client.ts"]),
    // slice2js generated .d.ts declarations and add them to the stream
    slice2js({include: [root], args: ["--typescript"], dest: root}), 
    filter("*.ts"),
      // Can I get TS compiler to use the declarations that are on the stream?
      tsc({....}),
    filter("*"),
    gulp.dest(root)
], cb);
ivogabe commented 5 years ago

The plugin exposes a stream with JavaScript files (.js) and a stream with declaration files (.d.ts). You can use this to write the javascript and declaration files to different directories:

var gulp = require('gulp');
var ts = require('gulp-typescript');
var merge = require('merge2');  // Requires separate installation

gulp.task('scripts', function() {
    var tsResult = gulp.src('lib/**/*.ts')
        .pipe(ts({
            declaration: true
        }));

    return merge([
        tsResult.dts.pipe(gulp.dest('release/definitions')),
        tsResult.js.pipe(gulp.dest('release/js'))
    ]);
});

I have no experience with pump, so that might not work well together.

pepone commented 5 years ago

I see what you say but I think my use case is different, slice2js is generating both JavaScript and TypeScript declarations and putting them in the gulp stream, I was trying to get the TS compiler to use the declarations directly from the gulp stream without need writing them to disk

So that imports in Client.ts can be resolve to files in the gulp stream rather than to files from disk

ivogabe commented 4 years ago

I see, I think gulp-filter provides the functionality you need. gulp-typescript reads the files from the input stream, which is usually gulp.src or tsProject.src(), but may also be something more complicated as for instance gulp-filter and slice2js.