gulp-bower icon indicating copy to clipboard operation
gulp-bower copied to clipboard

Can't action at end of bower task unless adding unnecessary .pipe command

Open spoco2 opened this issue 9 years ago • 4 comments

gulp_bower is performing the task I want, which is for any of my 'self contained' modules to be able to locally install their bower components during the build process if they are not present.

My problem is, that this is one step in the chain, and it must complete before the RequireJS optimization step starts.

So, what I want to have is:

gulp.task("installBower",function(cb){
    var progPath = path.join(opts.appRoot,opts.currentProgram);
    fs.exists(path.join(progPath,"bower.json"),function(exists){
        if(exists){
            bower({directory:"./bower_components",cwd:progPath})             
                .on("end",function(res){                 
                    cb();
                })
        }
        else{
            console.log("installBower: no bower.json found");
            cb();
        }
    });
});

Problem is, I have to add in a line:

gulp.task("installBower",function(cb){
    var progPath = path.join(opts.appRoot,opts.currentProgram);
    fs.exists(path.join(progPath,"bower.json"),function(exists){
        if(exists){
            bower({directory:"./bower_components",cwd:progPath})          
               .pipe(gulp.dest(path.join(progPath,"bower_components")))//<----UNNECESSARY STEP 
                .on("end",function(res){                 
                    cb();
                })
        }
        else{
            console.log("installBower: no bower.json found");
            cb();
        }
    });
});

To make the *.on("end" * event trigger.

Without that pipe, and with no following tasks, this runs fine and installs the bower components as I want them, but the rest of the gulp chain doesn't fire because the "end" event is never called.

Am I not understanding something about gulp and pipes... I just want to be able to run the bower task and have the next task only run once the bower step is finished.

spoco2 avatar Aug 10 '15 01:08 spoco2

I faced the same issue as described above. It feels counter intuitive compared to other gulp-x packages and the documentation doesn't really specify this as its behaviour.

asser-dk avatar Oct 19 '15 13:10 asser-dk

I'm also having a problem with gulp-bower not emitting an end event (but only sometimes!). Adding the superfluous gulp.dest doesn't work for me, though.

babelfish avatar Jan 06 '16 20:01 babelfish

same problem here

mister-good-deal avatar May 19 '16 23:05 mister-good-deal

IMHO I believe all you need is a return. Simple test, try removing the return on some of the gulp tasks and you'll notice it never says finish (even thought it had been running for 5 minutes :) )

theCuriousOne avatar Dec 28 '16 12:12 theCuriousOne