frankwallis / gulp-hub

Gulp plugin to run tasks in multiple gulpfiles
MIT License
89 stars 24 forks source link

add-subtask changes current directory then the following parent task gets confused. #23

Closed JakeJP closed 9 years ago

JakeJP commented 9 years ago

I understand process.chdir for the subfile is neccesary to run properly. But problem goes like this:

gulp.task( 'any-name', ['taskname-in-submodule'], function(){
    return gulp.src( ...this reference is affected by submodule's chdir ... )
}

Is there any chance to get cwd back for the parent task to continue after finishing tasks in submodules?

My current workaround is just put chdir on the top of every task function.

gulp.task( 'any-name', ['taskname-in-submodule'], function(){
    process.chdir(__dirname);
    return gulp.src( ...this reference is affected by submodule's chdir ... )
}
frankwallis commented 9 years ago

Thanks for raising this. I have just released 0.7.1 which I believe will fix this issue - can you please confirm as I'm not completely clear what your setup is?

JakeJP commented 9 years ago

Thanks for your quick response. I confirmed that problem is fixed in a single task. But fix is sill halfway. My project is a little more complicated.

project/
  |-- gulpfile.js (contains task A, B, C)
  |-- subproject
       |-- gulpfile.js (contains task S )

hub([ './subproject/gulpfile.js' ]);
gulp.task( 'A', ['S'], function(){ return ...; } ); // depending on S
gulp.task( 'B', funcion(){ return ...; } ); // simple task not using callback
gulp.task( 'C', function(){ return ...; } ); // simple task not using callback
gulp.task( 'all', ['A','B','C'] );
...

Task A completes without problem by the fix this time. (thanks)

Task 'all' misses some files because of the same cwd issue. I guess it's because tasks are running parallel and multiple processes are recycled between and before after task A,B,C...

frankwallis commented 9 years ago

Yes I don't think there is a way to solve that if the tasks are run in parallel. Gulp4 will make it easier to run them in series, but until then you could use 'run-sequence' to run them I suppose.

JakeJP commented 9 years ago

Ok. I understood. run-sequence is a good alternative for my case.

gulp.task( 'all', function(cb){
    runSequence('A', [ B', 'C' ], cb);
});

works perfect for me. Thanks.