GithubHelp home page GithubHelp logo

Comments (24)

yocontra avatar yocontra commented on July 20, 2024

@OverZealous full code? Also can you make sure you npm update and are on the latest versions

from gulp-util.

OverZealous avatar OverZealous commented on July 20, 2024

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.

OverZealous avatar OverZealous commented on July 20, 2024

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.

OverZealous avatar OverZealous commented on July 20, 2024

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.

yocontra avatar yocontra commented on July 20, 2024

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.

yocontra avatar yocontra commented on July 20, 2024

I'm always open to better ways though. gulp-util is being deprecated completely after the acceptance tests come out

from gulp-util.

OverZealous avatar OverZealous commented on July 20, 2024

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.

yocontra avatar yocontra commented on July 20, 2024

@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.

OverZealous avatar OverZealous commented on July 20, 2024

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.

OverZealous avatar OverZealous commented on July 20, 2024

Note: I modified the code to be immutable — it's extremely safe for messing around with now.

from gulp-util.

yocontra avatar yocontra commented on July 20, 2024

@OverZealous Got an example of using arguments with the streams? I assume you probably just have to .bind them in right

from gulp-util.

OverZealous avatar OverZealous commented on July 20, 2024

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.

yocontra avatar yocontra commented on July 20, 2024

@OverZealous very cool. I'll deprecate gutil.combine in favor of lazypipe

from gulp-util.

yocontra avatar yocontra commented on July 20, 2024

@OverZealous Want to publish that as a module with some tests?

from gulp-util.

OverZealous avatar OverZealous commented on July 20, 2024

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.

OverZealous avatar OverZealous commented on July 20, 2024

OK, I wrote it, got some tests working, and published it as lazypipe.

from gulp-util.

marklagendijk avatar marklagendijk commented on July 20, 2024

+1 for lazypipe! It is indeed what I expected gutil.combine to be.
It fixed the problem which I had with gutil.combine:

  1. I define several 'steps' using gutil.combine, eg: 'processLess'
  2. I used those steps in different 'build' tasks.
  3. As soon as I executed more than 1 build task, they would fail.
  4. Changing gutil.combine to lazypipe fixes the problem.

@contra will you include lazypipe in gutil, or will you just mention it in the documentation?

from gulp-util.

yocontra avatar yocontra commented on July 20, 2024

@marklagendijk I'll include it in the next breaking release

from gulp-util.

alexgorbatchev avatar alexgorbatchev commented on July 20, 2024

would be great to surface this in README because combine doesn't seem to work as expected

from gulp-util.

yocontra avatar yocontra commented on July 20, 2024

@alexgorbatchev Doesn't work at all really. This will be replaced with lazypipe in the next breaking change

from gulp-util.

alexgorbatchev avatar alexgorbatchev commented on July 20, 2024

@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.

yocontra avatar yocontra commented on July 20, 2024

@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.

yocontra avatar yocontra commented on July 20, 2024

gulp-util.combine will be removed in 3.0

Use the lazypipe module directly for this functionality

from gulp-util.

yocontra avatar yocontra commented on July 20, 2024

Related: https://github.com/gulpjs/gulp-util/tree/descope

from gulp-util.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.