OverZealous / run-sequence

Run a series of dependent gulp tasks in order
MIT License
962 stars 61 forks source link

One of my tasks doesn't run till the end #77

Closed jestanoff closed 7 years ago

jestanoff commented 8 years ago
/* replace.js */
var gulp = require('gulp');
var revReplace = require('gulp-rev-replace');

var dests = require('../../data/dests');

module.exports = function() {
    var manifest = gulp.src(dests.base + 'cachebusting_map.json');

    return gulp.src(dests.base + '{js,css,less}/*.{js,css}')
        .pipe(revReplace({
            manifest: manifest,
            replaceInExtensions: ['.js', '.css'],
        }))
        .pipe(gulp.dest(dests.base));
};
/* gulpfile.js */
var gulp = require('gulp');
var gutil = require('gulp-util');
var webpack = require('webpack');
var runSequence = require('run-sequence');

gulp.task('cachebust:replace', require('./gulp/tasks/cachebust/replace'));

gulp.task('webpack', (callback) => {
    webpack(webpackConfig, (err, stats) => {
        if (err) {
            throw new gutil.PluginError('webpack', err);
        }
        gutil.log('[webpack]', stats.toString({ colors: true, chunkModules: false }));
        callback();
    });
});

gulp.task('default', [ 'clean' ], () => {
    runSequence(
        'sprites',
        'collectstatic',
        'webpack',
        [
            'styles:site',
            'styles:lib',
            'styles:styles',
            'styles:pages',
            'styles:grid',
            'styles:mobile',
            'styles:print',
            'styles:ie',
            'styles:widget',
            'styles:blog',
            'styles:moderation',
            'styles:qunit',
            'scripts:lib',
            'scripts:app',
            'scripts:moderation:lib',
            'scripts:moderation:app',
            'scripts:modernizr',
            'scripts:wysihtml5',
            'scripts:richmarker',
            'scripts:chosen',
            'scripts:hopscotch',
            'scripts:multiselect',
            'scripts:archantwidget',
            'scripts:tests'
        ],
        'cachebust:rename:all',
        'cachebust:replace',
        'test'
    );
});
[15:10:44] Starting 'clean'...
[15:10:45] Finished 'clean' after 1.12 s
[15:10:45] Starting 'default'...
[15:10:45] Starting 'sprites'...
[15:10:45] Finished 'default' after 171 ms
[15:10:45] Execute: glue "/home/vagrant/code/site/streetlife/core/static/images/sprites" --less=./streetlife/core/static/less/sprites --img=./streetlife/core/static/images/c --crop --project --margin=4 --quiet --url=../images/c/
[15:11:03] Finished 'sprites' after 18 s
[15:11:03] Starting 'collectstatic'...
[15:11:11] Finished 'collectstatic' after 8.64 s
[15:11:11] Starting 'webpack'...
[15:11:28] Finished 'webpack' after 17 s
[15:11:28] Starting 'styles:site'...
[15:11:29] Starting 'styles:lib'...
[15:11:29] Starting 'styles:styles'...
[15:11:29] Starting 'styles:pages'...
[15:11:29] Starting 'styles:grid'...
[15:11:29] Starting 'styles:mobile'...
[15:11:29] Starting 'styles:print'...
[15:11:29] Starting 'styles:ie'...
[15:11:29] Starting 'styles:widget'...
[15:11:29] Starting 'styles:blog'...
[15:11:29] Starting 'styles:moderation'...
[15:11:29] Starting 'styles:qunit'...
[15:11:29] Starting 'scripts:lib'...
[15:11:29] Starting 'scripts:app'...
[15:11:29] Starting 'scripts:moderation:lib'...
[15:11:29] Starting 'scripts:moderation:app'...
[15:11:30] Starting moderation app Browserify bundle
[15:11:30] Starting 'scripts:modernizr'...
[15:11:30] Starting 'scripts:wysihtml5'...
[15:11:30] Starting 'scripts:richmarker'...
[15:11:30] Starting 'scripts:chosen'...
[15:11:30] Starting 'scripts:hopscotch'...
[15:11:30] Starting 'scripts:multiselect'...
[15:11:30] Starting 'scripts:archantwidget'...
[15:11:30] Starting 'scripts:tests'...
[15:11:30] Finished 'styles:blog' after 986 ms
[15:11:40] Finished 'scripts:modernizr' after 10 s
[15:11:40] Finished 'scripts:hopscotch' after 10 s
[15:11:40] Finished 'scripts:multiselect' after 10 s
[15:11:40] Finished 'scripts:richmarker' after 10 s
[15:11:43] Finished 'styles:grid' after 14 s
[15:11:43] Finished 'styles:ie' after 14 s
[15:11:43] Finished 'styles:print' after 14 s
[15:11:43] Finished 'scripts:archantwidget' after 14 s
[15:11:43] Finished 'scripts:wysihtml5' after 14 s
[15:11:43] Finished 'styles:qunit' after 15 s
[15:11:43] Finished 'scripts:chosen' after 14 s
[15:11:43] Finished 'styles:lib' after 15 s
[15:11:43] Finished 'styles:styles' after 15 s
[15:11:43] Finished 'scripts:tests' after 14 s
[15:11:43] Finished 'styles:widget' after 15 s
[15:11:43] Finished 'styles:pages' after 15 s
[15:11:46] Finished 'styles:mobile' after 17 s
[15:11:46] Finished 'scripts:moderation:lib' after 17 s
[15:11:46] Finished 'styles:moderation' after 17 s
[15:11:49] Finished 'styles:site' after 21 s
[15:11:56] Finished 'scripts:lib' after 27 s
[15:12:00] Finished 'scripts:app' after 32 s
[15:12:04] Finished moderation app Browserify bundle
[15:12:04] Finished 'scripts:moderation:app' after 35 s
[15:12:04] Starting 'cachebust:rename:all'...
[15:12:04] Finished 'cachebust:rename:all' after 9.25 ms
[15:12:04] Starting 'cachebust:replace'...
[15:12:05] Finished 'cachebust:replace' after 939 ms
[15:12:05] Starting 'test'...
[15:12:05] Finished 'test' after 49 ms

------------------------------------------

[15:12:45] Starting 'cachebust:replace'...
[15:12:49] Finished 'cachebust:replace' after 4 s

I haven't included all tasks as the file is way too long.

I'm having problems with cachebust:replace above, which when run in sequence takes 939ms and doesn't complete the full length of the task. However when I run it on its own it takes 4s and completes just fine.

OverZealous commented 8 years ago

Hey @jestanoff, did you ever get this resolved?

I can't see anything wrong in the code above.

jestanoff commented 8 years ago

@OverZealous, it is still not fixed. Let me explain it this way, the cachebust:replace task should rename all asset hashes only after all of these are available. However what happens is that task exits prematurely.

Is there any way to debug runSequence so I know what is the exit status of each task?

OverZealous commented 8 years ago

The only other thing I can guess is one of your other tasks isn't returning properly (so it's not running asynchronously).

(Generally speaking, Gulp is designed so that you'd do your "cache-busting" inside a file stream, rather than as a separate step. That's where we do ours—the dist version of our scripts handle adding the rev tag and replacing the dev filenames inline with the normal processing.)

OverZealous commented 7 years ago

Closing because I'm confident this is due to an improper task setup, where a gulp task is correctly configured for asynchronous processes, which causes the following task to run prematurely.