OverZealous / run-sequence

Run a series of dependent gulp tasks in order
MIT License
961 stars 56 forks source link

Can't seem to pass a callback…? #74

Closed hedefalk closed 8 years ago

hedefalk commented 8 years ago

I can't seem to pass a callback to run-sequence as the last param as described in the docs. This blows with:

/Users/viktor/dev/projects/ensime-node/node_modules/run-sequence/index.js:17 throw new Error("Task "+t+" is not a valid task string."); ^

Error: Task [object Object] is not a valid task string.

OverZealous commented 8 years ago

Can you provide the code you are trying to run? Only the last item in the list can be a callback, and it has to be a function. It looks like you are not passing in a function, or you are not passing in any valid tasks.

hedefalk commented 8 years ago

You're so right, I accidentally passed a vinyl object from gulp-watch instead of the callback I intended.

gulp.task('watch', ['build'], function(cb) {
    gulp.watch('src/**/*.ts', function(vinyl) {
        runSequence('compile-ts', 'test');
    });
    gulp.watch('src/**/*.coffee', function(cb) {
        runSequence('compile-coffee', 'test', cb);
    });
});
hedefalk commented 8 years ago

Another thing:

This combination of watch and runSequence gives me a stacktrace that I don't want. I have a watch that runs the tests and I have to scroll up a lot to see my failing tests because of the stack. It's not jasmine that does it…

starting tests… **.........F...... Failures: 1) formatType should format typeargs with tuples correctly 1.1) Expected '((ActivityRow, Option[AdminRow], Option[ParticipantCardRow]))' to be 'Seq[(ActivityRow, Option[AdminRow], Option[ParticipantCardRow])]'.

18 specs, 1 failure, 2 pending specs Finished in 0 seconds [16:17:10] 'test' errored after 197 ms [16:17:10] Error in plugin 'gulp-jasmine' Message: Tests failed [16:17:10] 'watch' errored after 31 s [16:17:10] Error in plugin 'run-sequence(test)' Message: Tests failed Stack: at finish (/Users/viktor/dev/projects/ensime-node/node_modules/run-sequence/index.js:56:13) at Gulp.onError (/Users/viktor/dev/projects/ensime-node/node_modules/run-sequence/index.js:67:4) at emitOne (events.js:82:20) at Gulp.emit (events.js:169:7) at Gulp.Orchestrator._emitTaskDone (/Users/viktor/dev/projects/ensime-node/node_modules/orchestrator/index.js:264:8) at /Users/viktor/dev/projects/ensime-node/node_modules/orchestrator/index.js:275:23 at finish (/Users/viktor/dev/projects/ensime-node/node_modules/orchestrator/lib/runTask.js:21:8) at DestroyableTransform. (/Users/viktor/dev/projects/ensime-node/node_modules/orchestrator/lib/runTask.js:52:4) at DestroyableTransform.f (/Users/viktor/dev/projects/ensime-node/node_modules/once/once.js:17:25) ………

I wanted to rid it, so now I did:

gulp.task('watch', ['build'], function(cb) {
    gulp.watch('src/**/*.ts', function(vinyl) {
        runSequence('compile-ts', 'test', function() {cb();});
    });
    gulp.watch('src/**/*.coffee', function(vinyl) {
        runSequence('compile-coffee', 'test', function() {cb();});
    });
});

Feels a bit ugly, any tips? :)

hedefalk commented 8 years ago

Forget ☝️

gulp.task('watch', ['build'], function(cb) {
    gulp.watch('src/**/*.ts', function(vinyl) {
        runSequence('compile-ts', 'test', function() {});
    });
    gulp.watch('src/**/*.coffee', function(vinyl) {
        runSequence('compile-coffee', 'test', function() {});
    });
});

was better :)

OverZealous commented 8 years ago

I don't understand what the question is, exactly.

You probably don't want to use the callback in watch tasks anyway, since they never complete. In those cases, just don't add cb to your task function, and don't add a callback to run-sequence. I, personally, don't use gulp.watch, so I can't help much with that (I use gulp-watch, which lets you perform incremental updates).

Honestly, I don't think you are using the tools right here. You should have dedicated tasks, and be firing those via gulp.watch, rather than using runSequence within a function.

Not sure I can help much more than that. This is really more of a gulp-level question.

hedefalk commented 8 years ago

Yeah, sorry, totally not related. I'll give gulp-watch a shot, thanks!

For the record, the issue I had was that I was using gulp.watch and not giving runSequence a callback, like:

gulp.task('watch', ['build'], function(cb) {
    gulp.watch('src/**/*.ts', function(vinyl) {
        runSequence('compile-ts', 'test');
    });
    gulp.watch('src/**/*.coffee', function(vinyl) {
        runSequence('compile-coffee', 'test');
    });
});

Then failures from 'test' would pop all the way up and be reported with stacktraces from the task. So just giving a function() {} callback to runSequence made that silenced.

Anyway, thanks for a great tool!

OverZealous commented 8 years ago

Ah, yeah, makes sense. runSequence was probably just throwing the error because it didn't have anywhere to report it.

Honestly, it used to have more subtle, silent reporting, but I've had complaints and several PRs to switch to full error reporting, so now it reports full errors, which is probably the issue.