Skip to content

gulp-run doesn't work when child process changes working directory #44

Description

@mirik123

The problem occurs because the child gulp script requires working directory change:
gulp --gulpfile "<...>\gulpfile.js" build
[13:40:01] Working directory changed to <...>
[13:40:03] Using gulpfile <...>\gulpfile.js
[13:40:03] Starting 'build'...
[13:40:03] Finished 'build' after 6.42 μs

This works:

const cp = require('cp');
gulp.task('gg2', function (done) {
    var gulpfile = path.join(gulpcwd, 'gulpfile.js'); 
    var subShell = cp.spawn('cmd.exe', ['/C', 'gulp', '--gulpfile', gulpfile, '--cwd', gulpcwd, 'build'], {
        env: process.env,
        cwd: process.cwd()
    });

    subShell.stdout.pipe(process.stdout);
    subShell.stderr.pipe(process.stderr);
    subShell.once('exit', function (code) {
            done(code);       
    });
});

This doesn’t work:

const run = require('gulp-run');
gulp.task('gg2', function (done) {
    var gulpfile = path.join(gulpcwd, 'gulpfile.js');
    return run('gulp --gulpfile "' + gulpfile + '" --cwd "' + gulpcwd + '" build', { verbosity: 3 })
        .exec(function (err) {
            done(err);
        }); 
});

In latter case the child process sends a standard gulp error that the gulp file is not found.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions