question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecating gulp.run no longer allows defining logic before running tasks.

See original GitHub issue

Given a gulp file similar to the one below, before version 3.5 I was able to run some logic before running other tasks.

var shouldMinify = false;

gulp.task('js', function () {
    return gulp.src('./js/*.js')
        .pipe(concat('app.js'))
        .pipe(gulpif(shouldMinify, uglify()))
        .pipe(gulp.dest('js'));
});

gulp.task('develop', function () {
    shouldMinify = false;
    gulp.run('js');
});

gulp.task('build', function () {
    shouldMinify = true;
    gulp.run('js');
});

As gulp.run is now deprecated, the only way to have a task run other tasks is by specifying them as dependencies. This feels extremely limiting, as the only way to set some logic before running a task is by using command line flags like in this example.

I may have missed it in the issues, but are there plans for programmatically starting tasks other than adding them as dependencies of other tasks?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:28 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
timrwoodcommented, Jan 25, 2014

Gulp may not solely be a task runner, but the fact that it runs tasks kind of makes it a task runner. I suppose this is just a matter semantics though, so I’ll just consider gulp a thing that has a task runner.

I think the task system in gulp/orchestrator one of gulp’s strengths. Being able to name units of work and reference other named units of work that must happen prior is an excellent pattern.

I understand that you can do essentially what gulp.run did by passing around and calling functions.

The problem I see is that now we end up with is two task systems.

One is formally defined by gulp. It is what is used for running tasks from the command line and from watchers. It has explicit task dependency definitions. It is well tested, and bugfixes are shared with everyone.

The second is informally defined by the user. It may be written with callbacks or events or promises or some other vanilla js. It may or may not have explicit task dependency definitions. It is probably not well tested, and bugs are unique to each re-implementation.

I understand that both of these spaces are going to exist, but removing the ability to start a gulp task from user-land code feels like you are pushing a greater burden onto the user.

Here is a closer representation of what I am currently doing. There are a few more tasks for html, images, and fonts, but this is the gist of it.

var minify = false;

// js-clean and css-clean remove compiled assets
gulp.task('js-clean', function () {...});
gulp.task('css-clean', function () {...});

// js and css tasks use gulp-if to only minify when minify is true
gulp.task('js', ['js-clean'], function () {...});
gulp.task('css', ['css-clean'], function () {...});

// task to build before deployment
gulp.task('build', function () {
    minify = true;
    gulp.run('js', 'css');
});

// task to run while actively developing
gulp.task('develop', function () {
    minify = false;
    gulp.run('js', 'css');
    gulp.watch(jsPaths, 'js');
    gulp.watch(cssPaths, 'css');
});

Without gulp.run, now I need have the develop and build tasks simply call functions that do what the js and css tasks do. But before those functions run, I need to have functions that do what js-clean and css-clean do. Sure, this is possible, but now I have written a one-off task dependency system that cannot hook into gulp’s dependency system.

If I want the two to work together, I need to create hooks for the gulp task dependency system to call my task dependency system rather than the other way around.

Again, all this is possible to do, but it just seems silly to have a task runner bundled with gulp that you cannot use for running tasks and managing their dependencies.

If the reason for deprecating gulp.run was because of user error, do you really think making users implement their own solution is going to result in fewer user errors?

0reactions
yocontracommented, Jun 15, 2016

Just to be clear: the new task system in 4.0 is leagues ahead and much more flexible than the 3.x one discussed in this thread. Check out the docs on the 4.0 branch, you’ll all love it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

gulp.run is deprecated. How do I compose tasks?
The accepted answer does not address the issue of running tasks before setting the watches. The next answer uses gulp.start which is going...
Read more >
allows to define vs allows defining - Online Editor
Deprecating gulp.run no longer allows defining logic before running tasks. · SuperModule allows defining class methods and method invocations the same way a ......
Read more >
Gulp | JetBrains Rider Documentation
JetBrains Rider parses Gulpfile.js files, recognizing definitions of tasks, shows tasks in a tree view, lets you navigate between a task in ...
Read more >
CoffeeScript
The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ... ,...
Read more >
allows to define or allows defining? - TextRanch
30 commits · 1 branch · 1 release · Fetching contributors. Deprecating gulp.run no longer allows defining logic before running tasks. #193. Closed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found