Skip to content

Gulp 4: gulp.task('default', 'build') should be same as gulp.task('default', gulp.series('build')) #1091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
geirsagberg opened this issue Jun 4, 2015 · 13 comments

Comments

@geirsagberg
Copy link

Loving the new gulp.series() and gulp.parallel() flow, but I feel it shouldn't be necessary to type:

gulp.task('default', gulp.series('build'))

When the following would communicate the intent even more clearly, and is less code:

gulp.task('default', 'build')

The latter currently fails with AssertionError: Task function must be specified.

See also #771.

@dmackerman
Copy link

Yeah, ran into this myself. Would be nice, but it's not deal breaking IMO.

@SyntaxRules
Copy link
Contributor

I agree that your suggested functionality would be nice.

You could get around this by making build a function:

gulp.task('defualt', build);

function build() {
   return gulp.src(...)
   ...
}

This has other benefits too, like you can add a description to your build task

function build() { ... }
build.description = 'this does this and that to build';

@phated
Copy link
Member

phated commented Jun 4, 2015

Sorry, we aren'y supporting this because the recommended usage pattern for gulp 4 is to use functions and be explicit in what your code is doing. You should not be using strings whenever possible, instead using named functions or setting displayName on an anonymous function.

@fregante
Copy link

But 'build' is explicit. build is clearly the name of the task. gulp.parallel('build') is no more clear than 'build' is in that context.

@flying-sheep
Copy link

i agree. there’s nothing saying more clearly “'default' is an alias of 'build'” than this.

both 'parallel' and 'series' are less explicit: “a series consisting of one task” and “parallel execution of one task” are simply more complicated ways of saying “one task”

@yocontra
Copy link
Member

I agree, it is unclear. This annoys me about my own gulpfiles. I think this should work gulp.task('default', gulp.task('build')) since gulp.task with only one argument is supposed to fetch a task function, but IIRC it didn't work like this.

@sylvainpolletvillard
Copy link

+1 ; I also tried to pass a string as it seems the most natural way to upgrade from v3

@phated
Copy link
Member

phated commented Dec 8, 2015

The first goal of gulp 4 is to promote good patterns through its APIs. We've done things like keep string task naming around for an easier upgrade path but you should be switching your gulpfiles to use named functions instead of string references everywhere.

@flying-sheep
Copy link

then why do you advertize to do gulp.task('default', gulp.series('build')) here? this uses 2 named tasks.

i thought gulp 4 was about:

  1. named functions (registered as tasks) for actually doing work
  2. named tasks for delegating to an aliased task or serial and parallel execution of multiple tasks.

in your examples, this seems cleanest

gulp.task('build', gulp.series(
  clean,
  gulp.parallel(scripts, images),
))
gulp.task(clean)
gulp.task(watch)

gulp.task('default', 'build')

and also most consistent: strings (representing named tasks) and functions can then have the same roles:

  1. they can be registered as CLI tasks
  2. they can be used as “task body”
  3. they can be used as part of a serial or parallel execution

@flying-sheep
Copy link

another alternative would be to disallow all this and just do:

let build = gulp.series(clean, gulp.parallel(scripts, images))
let default = build

gulp.task(build)
gulp.task(clean)
gulp.task(watch)
gulp.task(default)

@adamreisnz
Copy link

I have to +1 on this one, I've been using Gulp4 for a long time now, and I love it, but I was stunned when I ran into this error.

If both of these work:

//1
gulp.task('default', release);
//2
gulp.task('stuff', gulp.series('release', 'blah'));

You'd logically expect both of these to work as well:

//3
gulp.task('default', 'release');
//4
gulp.task('stuff', gulp.series(release, blah));

Instead, only the latter works and the one syntax standing out and throwing an error is number three.

If you don't want people to use named tasks like this, then in my opinion they shouldn't be supported in gulp.series or gulp.parallel either, otherwise it's just confusing. Best to pick to either support them in both cases or in neither case, and stick to that.

@MaxYari
Copy link

MaxYari commented Oct 19, 2016

I don't see a reason for not making it backwards compatible with old syntax of ['string','string','string'] which will default to parallel, and maybe put a warning here that you shouldnt really use that. Otherwise it just breaks your gulpfile.

@flying-sheep
Copy link

as it is now, i just ignore gulp.task as well as the possibility of referring to tasks by name:

instead i use export function release() { ... } to define tasks and always pass the functions directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants