Skip to content

Gulp 4: How do I prevent from duplicated dependent task execution? #1392

Closed
@gary5

Description

@gary5

I have a configuration file of gulp 3.

var gulp = require('gulp');

gulp.task('0', function(done) {
    console.log('0');
    done();
});

gulp.task('1', ['0'], function(done) {
    setTimeout(function() {
        console.log('1');
        done();
    }, 1000);
});

gulp.task('2', ['0'], function(done) {
    setTimeout(function() {
        console.log('2');
        done();
    }, 200);
});

gulp.task('default', ['1', '2'], function(done) {
    console.log('default');
    done();
});

The execution result is:

[13:59:36] Starting '0'...
0
[13:59:36] Finished '0' after 138 μs
[13:59:36] Starting '1'...
[13:59:36] Starting '2'...
2
[13:59:36] Finished '2' after 201 ms
1
[13:59:37] Finished '1' after 1 s
[13:59:37] Starting 'default'...
default
[13:59:37] Finished 'default' after 82 μs

After migrating it to gulp 4 version.

var gulp = require('gulp');

gulp.task('0', function(done) {
    console.log('0');
    done();
});

gulp.task('1', gulp.series('0', function(done) {
    setTimeout(function() {
        console.log('1');
        done();
    }, 1000);
}));

gulp.task('2', gulp.series('0', function(done) {
    setTimeout(function() {
        console.log('2');
        done();
    }, 200);
}));

gulp.task('default', gulp.series('1', '2', function(done) {
    console.log('default');
    done();
}));

The task 0 has been executed twice.

[13:59:10] Starting 'default'...
[13:59:10] Starting '1'...
[13:59:10] Starting '0'...
0
[13:59:10] Finished '0' after 687 μs
[13:59:10] Starting '<anonymous>'...
1
[13:59:11] Finished '<anonymous>' after 1 s
[13:59:11] Finished '1' after 1.01 s
[13:59:11] Starting '2'...
[13:59:11] Starting '0'...
0
[13:59:11] Finished '0' after 604 μs
[13:59:11] Starting '<anonymous>'...
2
[13:59:11] Finished '<anonymous>' after 202 ms
[13:59:11] Finished '2' after 205 ms
[13:59:11] Starting '<anonymous>'...
default
[13:59:11] Finished '<anonymous>' after 720 μs
[13:59:11] Finished 'default' after 1.22 s

I need gulp.series to keep dependencies in sequence, but I can't find any information to prevent duplicated execution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions