Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback once modules installed #17

Closed
pavlosgi opened this issue Apr 22, 2015 · 7 comments
Closed

Callback once modules installed #17

pavlosgi opened this issue Apr 22, 2015 · 7 comments

Comments

@pavlosgi
Copy link

Would be nice if we could provide a callback to run once modules have been installed. I understand it might be difficult because you are spawning a new process for this. But it would be a great addition if possible

@dodtsair
Copy link

dodtsair commented Jun 3, 2015

I ran into this as well.

Currently I have one project which is used to run some sub projects. Like the follow

  1. rootProject/
  2. rootProject/gulpfile.js
  3. rootProject/subProject1/
  4. rootProject/subProject1/gulfile.js
  5. rootProject/subProject2/
  6. rootProject/subProject2/gulfile.js

Running gulp on rootProject runs it on each subproject. I have about three right now, but plan to add more. Before I can run gulp I need to install the npm modules

cd rootProject/
npm install
pushd subProject1
npm install
popd
pushd subProject2
npm install
popd
gulp

I was hoping I could change this to

cd rootProject/
npm install
gulp

This is what most people expect with a gulp project. However when I code gulp-install to call install on all the subprojects I don't see a way to run that serially with the actual gulp of that project.

In the end npm install is running on subProject1 while gulp is called on it. This obviously blows up. Modules are still missing.

@dodtsair
Copy link

dodtsair commented Jun 3, 2015

Looking at the code I see the use of through2. That object is returned from the call to install(). It looks like the code calls callbacks whenever npm install is done executing. So it looks like I am putting my callback in the wrong place.

Here is what my code looks like:

modules.forEach(function(module) {
  gulp.task(module + "-npm-install", function(cb) {
    var installPipe = install()
    gulp.src(['./' + module + '/package.json']).pipe(installPipe)
    installPipe.on("finish", cb);
  });
});

I create a task for each module. I didn't include the code but the gulp call for each module depends on the module-npm-install task. So if the cb gets called at the right time, then the gulp call should not happen until after npm install finished. I put my callback on the "finish" event for the installPipe. It seems to get called because nothing hangs, but it gets called in milliseconds

[12:20:24] Starting 'subProject1-npm-install'...
....
[12:20:24] Finished 'subProject1-npm-install' after 19 ms

Gulp has obviously decided that gulp-install finished well before its calls to npm install finished.

@roh85
Copy link

roh85 commented Jun 16, 2015

I have the same issue. Used a timeout as a workaround to bypass this behaviour. A proper fix would be appreciated.

gulp.task('install', function(cb){
    var installPipe = install();
    gulp.src(['./node_modules/subprojects/package.json'])
    .pipe(installPipe);
    installPipe.on("finish", function(){
        if(dirs_exists(['./node_modules/subproject/node_modules'])){
            CONST_TIMEOUT = 1000;
        }
        setTimeout(function() {
            /*
            Put tasks to execute here
             */
            gulp.start('build')
            gulp.start('images')
            gulp.start('scripts')
            gulp.start('styles')
        },CONST_TIMEOUT); //use timeout to give npm install the chance to finish properly
    });
});

@maxfrigge
Copy link

Another major use case for this is to restart your application after the modules have been installed.

@vtange
Copy link

vtange commented Apr 27, 2016

Would really like this to be possible. Wanted to make a slush generator that does some extra steps after the .pipe(install()) part, but pretty much can't. Tried linking Gulp tasks in serial and using plugins like run-sequence. .pipe(install()) seems to force a hard stop on the process

@tliebscher
Copy link

Creating task dependencies in gulp with the intention of blocking the following tasks until gulp-install has finished does not work, as gulp-install returns before e.g. bower even has started.
The following tasks then just don't find the directories and files.

Is there a way to make the execution of gulp-install blocking?

@swinston1000
Copy link

Callback support would be very useful - is there any reason that this has not been merged - #31 ???
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants