gulp.series() could be friendlier to run inside a function
See original GitHub issueThere are a few scenarios where I’ve been wanting to write a task similar to:
gulp.task('prod', () => {
process.env.NODE_ENV = 'production';
return gulp.series([
'build'
'serviceWorker',
]);
});
This doesn’t work because gulp.series()
returns a function, and the execution of a task is expected to return a promise or a stream.
So executing gulp.series, like so:
gulp.task('prod', () => {
process.env.NODE_ENV = 'production';
return gulp.series([
'build'
'serviceWorker',
])();
});
Running the prod
task, it’ll correctly run the series tasks, but at the end it’ll print:
[11:10:12] The following tasks did not complete: prod [11:10:12] Did you forget to signal async completion?
In the end I need to write:
gulp.task('prod', (done) => {
process.env.NODE_ENV = 'production';
return gulp.series([
'build'
'serviceWorker',
])(done);
});
This works, but it would have been amazing if:
- Returning a function as a result of a gulp task would cause the function to be run. This means developers could do:
gulp.task('example', () => { // TODO: Do stuff here return gulp.series([....]); });
- The return type of gulp.series()() was suitable for gulp.task to be happy once it’s completed (i.e. return a promise or stream or gulp.task expect the result).
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (11 by maintainers)
Top Results From Across the Web
GulpJS 4.0.2 series inside a function called by a series does ...
I am using gulp 4.0.2. In reality I have the second function registered as a task in a different file and that is...
Read more >series() - gulp.js
series() #. Combines task functions and/or composed operations into larger operations that will be executed one after another, in sequential order.
Read more >An Introduction to Gulp.js - Section 1 - SitePoint
The exported html task uses gulp.series() to combine tasks that are executed one after the other. In this case, the images() function is...
Read more >Building a Gulp API Compatible Task Automation Tool - Toptal
In version 4.0, Gulp introduced two new functions: gulp.series and gulp.parallel. These APIs allow tasks to be run in series or in parallel....
Read more >Gulp 4 tutorial for beginners (Sass and JS workflow)
Gulp is a tool that will run various tasks for you in your web ... notice that we are putting all those tasks...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nevercast the “gulp way” is to go plain js wherever possible, I would write your stuff as simply:
You only need gulp.series/gulp.parallel when you start needing nesting, stream completion, callbacks, etc. - if you are using simple promises you can just use async/await normal JS stuff.
@gauntface hmmm. The general idea of these APIs is to compose functions at the top level. The pattern you showed is something that can be done due to the implementation but it’s not a recommended pattern (thus looks bad). If we added your suggestion, I feel like many more people would be adding extra function wrappers into their programs (like
gulp.task('example', () => gulp.series(...));
) which we really don’t want.I think most of these scenarios go away when people utilize flags and task metadata). (And named functions in the cases where they are dodging the forward reference changes)
I understand you provided a pretty basic example and I’d like to see other samples to see how they could be converted to not add another function wrapper around
gulp.series
/gulp.parallel