Skip to content

Gulp outputs that series has finished, but processes still running #2643

@paul-uz

Description

@paul-uz

I am running a few tasks via series, with one task scanning some directories, and another zipping the contents of each directory.

Despite the console displaying the message Finished 'cleanAndBuild' after 28 s this isn't actually the case, with the console not exiting until much later, at about 120s.

gulpfile.js

const { exec } = require('child_process');
const { series, dest, src } = require('gulp');
const del = require('del');
const fs = require('fs');
const zip = require('gulp-zip');

function clean() {
  return del('.dist/');
}

function installPackages() {
  const directories = fs.readdirSync('lambda/');
  directories.forEach((dir) => {
    if (fs.existsSync('lambda/' + dir + '/package.json')) {
      console.log('package.json exists in ' + dir);
      const path = `lambda/${dir}/`
      exec(`npm --prefix ${path} ci ${path} --production`)
    }
  });
  return Promise.resolve();
}

function buildZip() {
  console.log('zipping...');
  const directories = fs.readdirSync('lambda/');
  directories.forEach((dir) => {
    return src('lambda/'+dir+'/**').pipe(zip(`${dir}.zip`)).pipe(dest('.dist/lambda/'+dir));
  });

  return Promise.resolve();
}

exports.cleanAndBuild = series(clean, installPackages, buildZip);

Using the CLI tool gnomon I was able to get the true timing of running my task.

Why is gulp saying cleanAndBuild has finished when it hasn't? And is there anything I can do to improve this script to make it faster/more efficient?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions