You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@gratimax - The expected behavior of this would be that when a file gets modified it gets emitted down the stream again. The problem arises when you have something that works against sets of files in your task (like gulp-concat). This would also totally screw up task dependencies since a task with .watch() in it really never ends so if something depends on it then it will never be executed.
@contra One possible solution is to just use new the newly defined trigger(from issue #32, I was thinking of that all along) whenever a watch is used, so like your example in that issue:
This does require having to change how tasks work, so that they'd function more like event stream maps than anything.
Another possible solution is adding some stuff to gulp-util that allows you to make 'file blobs', or collections of files that check which files are recomputed, and always send the full file list down the pipe. You could create a file blob from gulp-util that would read the incoming stream and automatically add new files. Any change in the files list, and the whole file list is sent down again. This would also make passing things along easier.
Example for gulp-concat:
vares=require('event-stream'),path=require('path'),util=require('gulp-util');module.exports=function(fileName){if(!fileName)thrownewError("Missing fileName option for gulp-concat");varblob=newutil.FileBlob();// Create a file blobfunctionconcatFiles(files,cb){// files is an array that blob storesvarjoinedContents=files.map(function(file){returnfile.contents;}).join('');varjoinedPath=path.join(path.dirname(files[0].path),fileName);varjoinedFile={shortened: fileName,path: joinedPath,contents: joinedContents};cb(null,joinedFile);}returnes.pipeline(blob.add,// blob.add adds a file to the blobes.map(concatFiles)// our concat function);};
The resulting code is shorter and arguably more concise. Anyway, this is a pretty big change. I think I may have to pull this into its own issue.
The use-case that created this is I want to gulp.src('/path/to/some.thing') then pipe that through a filter before watching. E.g. perhaps I want to watch **/*.js except **/external/**. Right now minimatch doesn't support globs like {**/*.js,!**/external/**} because it presumes ! will be the first character in the whole thing, not the first character in each match expression. It also doesn't support the ,{ignore:['**/external/**']} syntax anymore. Thus, there's no good way to say "watch part of this path without watching all of it".
Given that you'd usually apply the same transforms to the same input files whether you compile them once (.src) or you watch them while in dev (.watch), have you considered making that an option of the execution rather than a part of the pipeline, for instance as a CLI option (gulp --watch <taskname>)?
Why not create glob streams ? A stream of gulp.src objects. Plugins are functions we run to return a stream to pipe. So, we could do that:
gulp.watch("./client/js/*.coffee",{ignore: ["vendor"]})// set a stream of gulp.src results.pipe(coffee)// just provide the function.pipe(gulp.wrap(header,"This is a header"))// helper to run a function with the given parameters.pipe(minify).pipe(gulp.wrap(gulp.dest,"./public/js"));
That way, we could end streams, concat files etc... without annoying side effects.
Okay so I think we can do this but it will only be for plugins that work with incremental builds. Things that need every file at once (concat, bundling, etc.) will need to use the traditional .src() stuff.
Based on @gratimax 's first proposal, ideally something like the following would be awesome:
gulp.task('default',function(){vartarget='./**/*.coffee';// hypothetical "stream maker"// to avoid repetitionvargulpCoffee=gulp.factory().pipe(coffee()).pipe(minify()).pipe(gulp.dest("./public/js"));// Process all coffee files.gulp.src(target).gulpCoffee();gulp.watch("./client/js/*.coffee",{ignore: ["vendor"]})// just like gulp.src, except watches files.gulpCoffee();});
I guess this solution isn't the best though for such a common use case.
What about gulp.watchAndGather to solve this problem of watching one file then wanting all of the glob?
It would trigger an src when any of the files in the glob change? There's probably a prettier way...
gulp.watchAndGather("./client/js/*.coffee",{ignore: ["vendor"]})// just like gulp.src, except watches files.pipe(coffee()).pipe(minify()).pipe(gulp.dest("./public/js"));
//... // hypothetical "stream maker"// to avoid repetitionvargulpCoffee=gulp.factory().pipe(coffee()).pipe(minify()).pipe(gulp.dest("./public/js"));// Process all coffee files.gulp.src(target).pipe(gulpCoffee());gulp.watch("./client/js/*.coffee",{ignore: ["vendor"]})// just like gulp.src, except watches files.pipe(gulpCoffee());// ...
The difference is that gulpCoffee can be pipe'd. I think this may be possible.
We can continue this on another issue if we're off topic. I'm not an expert on streaming; since I adopted gulp only a few days ago. I'm still wrapping my head around streaming.
If the idiom is that simple, I don't see a reason for it not to be part of gulp once gulp.watch(...) is more fleshed out.
Activity
maxov commentedon Nov 30, 2013
Or maybe just make gulp.watch() inline, and emit new files whenever it discovers them or has them changed? Then it could replace gulp.src().
yocontra commentedon Nov 30, 2013
@gratimax - Love it.
yocontra commentedon Dec 1, 2013
@gratimax I do have concerns though that incremental builds will complicate plugin development. I need to think about this for a bit.
maxov commentedon Dec 1, 2013
@contra Not sure what you mean by incremental builds.
EDIT: nevermind
yocontra commentedon Dec 1, 2013
@gratimax - The expected behavior of this would be that when a file gets modified it gets emitted down the stream again. The problem arises when you have something that works against sets of files in your task (like gulp-concat). This would also totally screw up task dependencies since a task with .watch() in it really never ends so if something depends on it then it will never be executed.
maxov commentedon Dec 2, 2013
@contra One possible solution is to just use new the newly defined trigger(from issue #32, I was thinking of that all along) whenever a watch is used, so like your example in that issue:
This does require having to change how tasks work, so that they'd function more like event stream maps than anything.
Another possible solution is adding some stuff to gulp-util that allows you to make 'file blobs', or collections of files that check which files are recomputed, and always send the full file list down the pipe. You could create a file blob from gulp-util that would read the incoming stream and automatically add new files. Any change in the files list, and the whole file list is sent down again. This would also make passing things along easier.
Example for gulp-concat:
The resulting code is shorter and arguably more concise. Anyway, this is a pretty big change. I think I may have to pull this into its own issue.
robrich commentedon Dec 2, 2013
The use-case that created this is I want to
gulp.src('/path/to/some.thing')then pipe that through a filter before watching. E.g. perhaps I want to watch**/*.jsexcept**/external/**. Right now minimatch doesn't support globs like{**/*.js,!**/external/**}because it presumes!will be the first character in the whole thing, not the first character in each match expression. It also doesn't support the,{ignore:['**/external/**']}syntax anymore. Thus, there's no good way to say "watch part of this path without watching all of it".yocontra commentedon Dec 2, 2013
@robrich I'm working on standardizing the arguments passed to .watch and .src to support arrays of globs and arrays of ignores
theefer commentedon Dec 18, 2013
Given that you'd usually apply the same transforms to the same input files whether you compile them once (
.src) or you watch them while in dev (.watch), have you considered making that an option of the execution rather than a part of the pipeline, for instance as a CLI option (gulp --watch <taskname>)?yocontra commentedon Dec 19, 2013
@theefer I'm still thinking about the best way to do that. It is annoying to have to keep pasting the same paths around
nfroidure commentedon Dec 26, 2013
Why not create glob streams ? A stream of gulp.src objects. Plugins are functions we run to return a stream to pipe. So, we could do that:
That way, we could end streams, concat files etc... without annoying side effects.
yocontra commentedon Dec 29, 2013
Okay so I think we can do this but it will only be for plugins that work with incremental builds. Things that need every file at once (concat, bundling, etc.) will need to use the traditional .src() stuff.
yocontra commentedon Dec 29, 2013
This will be added into vinyl-fs and brought into gulp when that is.
dashed commentedon Dec 29, 2013
Based on @gratimax 's first proposal, ideally something like the following would be awesome:
ajoslin commentedon Dec 30, 2013
@dashed, couldn't you just do that right now (prettiest in coffeescript):
I guess this solution isn't the best though for such a common use case.
What about
gulp.watchAndGatherto solve this problem of watching one file then wanting all of the glob?It would trigger an
srcwhen any of the files in the glob change? There's probably a prettier way...dashed commentedon Dec 30, 2013
@ajoslin I already have something; a little similar. It's a little hacky solution (but not too hacky for it to be a problem): https://github.com/gobanjs/gojs/blob/rewrite/gulpfile.js
Your coffeescript proposal is interesting.
Another alternative use case is:
The difference is that
gulpCoffeecan be pipe'd. I think this may be possible.ajoslin commentedon Dec 30, 2013
Just realized
eventStream.pipeline()is your gulp.factory() idea :-)This here works great:
I think we've gotten a little off-topic though .. I think if we can just get
watchto be pipable we could do this really well.dashed commentedon Dec 30, 2013
We can continue this on another issue if we're off topic. I'm not an expert on streaming; since I adopted gulp only a few days ago. I'm still wrapping my head around streaming.
If the idiom is that simple, I don't see a reason for it not to be part of gulp once
gulp.watch(...)is more fleshed out.yocontra commentedon Dec 30, 2013
@dashed @ajoslin
If enough people want it I could probably throw this in gulp-util and/or as its own module
Usage:
dashed commentedon Dec 30, 2013
That would be useful to keep things DRY.
yocontra commentedon Dec 31, 2013
@dashed Moving this to gulpjs/gulp-util#16
yocontra commentedon Jan 3, 2014
Moving this to #84
yocontra commentedon Jan 3, 2014
Also somebody should put that combine stuff in the recipes section of the wiki