ivogabe / gulp-typescript

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

TS does not compile in certain conditions #592

Closed amoldavsky closed 5 years ago

amoldavsky commented 5 years ago

Expected behavior: expecting to get a *.js file in output

Actual behavior: getting a *.ts file in output

Your gulpfile:

    const task = gulp.src('src/**/*.ts');
    const project = ts.createProject({
        declaration: true,
        noImplicitAny: true,
        // outFile: 'output.js',
        target: 'ES6',
    });

    task.pipe(project());
    task.pipe(gulp.dest('build'));
    task.pipe( debug({ title: 'build-scripts' }) );
    return task;

any other gulp script / lib i run in this fashion seems to work fine. And the reason why i do not chain is because in the actual use case i have conditionals in which i would add more steps to a task based on some CLI parms.

Regardless of anything, wether chaining or separating this should have absolutely no difference, gulp task was intended to work either way and the support imo has to be there whether this does or does not makes sense to do it this way.

samjudge commented 5 years ago

If you want to use gulp in this way (not daisy-chaining), shouldn't you be assigning the results of your pipe operations to task? I don't think it's (supposed to be) mutable.

i.e.

task = task.pipe(project());
task = task.pipe(gulp.dest('build'));
task = task.pipe( debug({ title: 'build-scripts' }) );
ivogabe commented 5 years ago

Gulp wasn't designed to handle streams like this. It might work on some plugins, as some plugins mutate objects. The first plugin would mutate the file object (synchronously), and the handler of the second plugin would then get the mutated object as input. This requires that the plugins work synchronously, as the next plugin will be invoked directly afterwards.

Ignoring the question whether it is a good idea to modify those objects instead of creating new ones, we simply cannot do that, for several reasons:

The solution by Sam is a good alternative. I would suggest to use the normal way of chaining if possible. If you for instance have some logic to determine which plugins you need to apply, you could store the result in a variable.