Comments (24)
@OverZealous full code? Also can you make sure you npm update and are on the latest versions
from gulp-util.
I reran npm up, it still happened. I created a minimal project to show it happening
Run that, and you'll see that only one file makes it into the build.
from gulp-util.
FYI: rolling back to 2.2.10 fixes it. However, I'm not sure I can use this anyway, because now I'm getting cryptic Error: write after end
messages that I don't get if I inline the tasks manually when using this with gulp-watch
.
It's a shame, too, since it is a much cleaner way to reuse groups of tasks.
from gulp-util.
I've been thinking about this more, and I realized something huge, this method may cause more harm than good, because it appears that it supports code reuse, but it actually creates hard-to-resolve mistakes by reusing task streams.
For example, say I have this:
var watch = require('gulp-watch');
var common = gutil.combine(A(), B(), C());
gulp.task('build', function() {
return gulp.src(...).pipe(common).pipe(D()).pipe(gulp.dest('1'));
});
gulp.task('default', ['build'], function() {
watch({glob:...}).pipe(common).pipe(E()).pipe(gulp.dest('2'));
});
You'd expect everything in common to run once, then D, then dest 1, then watched. On change it should run common, run E, then dest 2. What happens on watch though, is that everything is run through common, run through the dest 1 and simultaneously run through E, then dest 2.
Anyway, this has caused me a ton of trouble. I'm working on some better way of reusing sets of tasks, but I haven't really found one that is clean.
from gulp-util.
gutil.combine returns a function that combines the stream. You actually want code that looks like this
var watch = require('gulp-watch');
var common = gutil.combine(A(), B(), C());
gulp.task('build', function() {
return gulp.src(...).pipe(common()).pipe(D()).pipe(gulp.dest('1'));
});
gulp.task('default', ['build'], function() {
watch({glob:...}).pipe(common()).pipe(E()).pipe(gulp.dest('2'));
});
from gulp-util.
I'm always open to better ways though. gulp-util is being deprecated completely after the acceptance tests come out
from gulp-util.
Sorry, that was a typo — I know I have to call it as a function. The issue is that A
, B
, and C
are already created, so they are getting reused. I'm pretty sure that's what's happening, because it doesn't look like it recreates the pipe every time you call it. (And even if it did, as long as it pipes A to B directly, then we end up with a tree.)
I suppose it would work if I wrote it like this:
var jsBuildTasks = function() {
return gutil.combine(A(), B(), C())();
};
// later
.pipe(jsBuildTasks())
Then at least you would know you are getting new tasks every time you use it. Everything ends up very verbose, and that double parentheses is ugly.
from gulp-util.
@OverZealous Yeah you would have to wrap every single stream. I totally get what you mean... not sure on the best solution but the function is very misleading
from gulp-util.
I think I have come up with a solution for task group reuse that is safe, clean to use (and mirrors the built-in piping).
I created a gist with the concept here.
Usage example (notice how the items are added without being executed):
var cssTasks = lazypipe()
.pipe(recess, recessConfig)
.pipe(less)
.pipe(autoprefixer);
// calling cssTasks() will create a pipeline at that time.
Arguments can be added after the command name, so you can have as many arguments as necessary.
If you think this makes sense, I'll turn it into an npm module tomorrow. The only thing I might change is to make the lazypipe itself immutable, so you can add new items on the end of a lazypipe without affecting previous steps.
from gulp-util.
Note: I modified the code to be immutable — it's extremely safe for messing around with now.
from gulp-util.
@OverZealous Got an example of using arguments with the streams? I assume you probably just have to .bind them in right
from gulp-util.
Arguments to the individual streams can be passed in as additional parameters to pipe()
. The example above for recess
shows it in action.
Since the lazypipe is immutable, you can do all sorts of crazy stuff mixing and matching pre-built stuff, like this:
// streamA -> streamB
var foo = lazypipe().pipe(streamA).pipe(streamB);
// streamA -> streamB -> streamC
var bar = foo.pipe(streamC);
// streamD -> streamA -> streamB -> streamE
var baz = lazypipe().pipe(streamD).pipe(foo).pipe(streamE);
Everything there should work as expected.
from gulp-util.
@OverZealous very cool. I'll deprecate gutil.combine in favor of lazypipe
from gulp-util.
@OverZealous Want to publish that as a module with some tests?
from gulp-util.
Great! I'll work on that, but I need to learn how to write tests for npm modules. (It'll also be a lot easier now that npm is fixed!)
from gulp-util.
OK, I wrote it, got some tests working, and published it as lazypipe.
from gulp-util.
+1 for lazypipe! It is indeed what I expected gutil.combine
to be.
It fixed the problem which I had with gutil.combine
:
- I define several 'steps' using gutil.combine, eg: 'processLess'
- I used those steps in different 'build' tasks.
- As soon as I executed more than 1 build task, they would fail.
- Changing
gutil.combine
tolazypipe
fixes the problem.
@contra will you include lazypipe in gutil, or will you just mention it in the documentation?
from gulp-util.
@marklagendijk I'll include it in the next breaking release
from gulp-util.
would be great to surface this in README because combine
doesn't seem to work as expected
from gulp-util.
@alexgorbatchev Doesn't work at all really. This will be replaced with lazypipe in the next breaking change
from gulp-util.
@contra any idea when this is coming? gulp is gaining a good momentum, having stuff broken like this in official repo isn't very nice to newcomers :) this has been open for over a month now.
from gulp-util.
@alexgorbatchev Sorry about this being open so long. There are a ton of changes going into the next breaking release of gulp-util. I wanted to get them all finished before pulling the trigger on a version bump. I will try to have it done either today or tomorrow.
from gulp-util.
gulp-util.combine will be removed in 3.0
Use the lazypipe
module directly for this functionality
from gulp-util.
Related: https://github.com/gulpjs/gulp-util/tree/descope
from gulp-util.
Related Issues (20)
- The README on npm doesn't have the deprecation note HOT 1
- more helpful replacement pointers HOT 8
- [email protected]
- deprecated [email protected] used on [email protected] > [email protected] HOT 3
- deprecated [email protected] used on [email protected] HOT 1
- [email protected] deprecated HOT 2
- gulp
- Gulp throws assertion error after fixing gulp-util deprecation with gulp-cli HOT 2
- Error cannot find gulp-util after attempting to fix assertion issue HOT 2
- Cannot find module 'gulp-util' HOT 3
- remove gulp-util HOT 1
- ecosystem
- remove gulp-util HOT 1
- remove gulp-util
- remove gulp-util
- [email protected]: is deprecated
- Please run `npm deprecate` HOT 1
- remove gulp-util by replacing the API listed below
- Can not install gulp on my project via npm HOT 1
- Security vulnerability HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-util.