Tuesday, 10 December 2019

Gulp sequential execution of same task on array of source files

A simplified version of my gulp file looks like this:

stylusFiles=[...];

gulp.task("stylus", function(done){
  global.stopOnError = true;
  stylusFiles.forEach((file) => {
    executeStylus(file.name, file.src, Date.now());
  });
  done();
});

javascFiles = [firstjs, secondjs];

gulp.task("firstcompile", function (done) {
  createBundle(firstjs);
  done();
});

gulp.task("secondcompile", function (done) {
  createBundle(secondjs);
  done();
});

gulp.task("compile", function(done) {
  setVersion();
  global.stopOnError = true;
  stylusFiles.forEach((file) => {
    executeStylus(file.name, file.src, Date.now());
  });

  createBundles(javascFiles);
  done();
});

gulp.task("seqcompile",
  gulp.parallel("stylus",
  gulp.series("firstcompile","secondcompile"), 
  function(done) {
    setVersion();
    global.stopOnError = true;
    done();
  }
));

Stylus compilation works in concurrent manner (output order != order of stylus files in code). If I run gulp on any single JS file, it works. The reason I try to force sequential execution is that gulp compile on the full set of JS files either crashes with an "out of heap memory" error (even using --max_old_stack_size=12000 on a 16 GB workstation) or runs indefinitely (>10 h) on the larger JS files (original size <=24 MB). However, the way it is written here in the example, gulp seqcompile is still not sequential, since output order != order of JS files in code, and on my remote instance, gulp still runs indefinitely (at least I have now had success on the 16 GB workstation).

  1. How do I force sequential execution?
  2. It would be nice to be able to write something like gulp.series(javascFiles).
  3. I am not sure if setVersion is run only once before both stylus and js compilation, as it should.


from Gulp sequential execution of same task on array of source files

No comments:

Post a Comment