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

Increasing the "through2" highWaterMark #19

Closed
mdurchholz opened this issue Feb 9, 2021 · 5 comments
Closed

Increasing the "through2" highWaterMark #19

mdurchholz opened this issue Feb 9, 2021 · 5 comments

Comments

@mdurchholz
Copy link

I am using your plugin to loop through a set of SCSS files and compile them into beautified CSS for documentation purposes. Anyways, I am running into an issue where the amount of loop iterations is maxing out at 16 files. After doing some research, I see that there is a property in "through2" called "highWaterMark" which is set to 16 by default.

gulpjs/gulp#716

Is there a way to update this number through your plugin?

@mariusGundersen
Copy link
Owner

Do you have some code? I suspect you are not returning the stream inside the flatMap callback. As the comment in your link says, if nothing is consuming the stream then it won't continue processing.

@mdurchholz
Copy link
Author

mdurchholz commented Feb 9, 2021

I return stream once to avoid my "style.scss" file on the level of my sourceLib.

var sourceLib = "path/to/sources/";

//  librarySources should return a length 25
var librarySources = [
    sourceLib+'**/*.scss', // Search for all SCSS files
    '!'+sourceLib          // but exclude the first level
];

gulp.task('createExampleCSS', function(done){

    gulp.src(librarySources)
        .pipe(plugins.flatmap(function(stream, file)
        {
            var basePath = file.path.replace(__dirname+'/'+sourceLib, '');

            // Ignore any files on the first level (Ex. the main style.scss that is unrelated to this gulp function) 
            if( basePath.split('/').length == 1 ) return stream;

            // Only returns 16 paths
            console.log(basePath);

            // Run custom gulp on individual file that creates a beautified CSS file of the SCSS file
            return gulp
            .src([ ... ])
            .pipe( ... )
            .pipe( gulp.dest("path/to/production/") );
        }));

    done();

});

@mdurchholz
Copy link
Author

mdurchholz commented Feb 9, 2021

I can actually update my snippet to the following and get the same result without return stream:

var sourceLib = "path/to/sources/";

// librarySources should return 25 files
var librarySources = [
    sourceLib+'**/*.scss',     // Search for all SCSS files
    '!'+sourceLib+'style.scss' // but exclude the style.scss
];

gulp.task('example', function(done){

    gulp.src(librarySources)
        .pipe(plugins.flatmap(function(stream, file)
        {
            var basePath = file.path.replace(__dirname+'/'+sourceLib, '');

            // Only returns 16 paths
            console.log(basePath);

            // Run gulp on individual file
            return gulp
            .src([ ... ])
            .pipe( ... );
        }));

    done();

});

@mdurchholz
Copy link
Author

mdurchholz commented Feb 9, 2021

Ahhh, I see what needs to be done now from that post I shared regarding the "consumption". I am all set. Thanks for the quick responses!

var browserSync = require('browser-sync').create();

var sourceLib = "path/to/sources/";

// librarySources should return 25 files
var librarySources = [
    sourceLib+'**/*.scss',     // Search for all SCSS files
    '!'+sourceLib+'style.scss' // but exclude the style.scss
];

gulp.task('example', function(done){

    gulp.src(librarySources)
        .pipe(plugins.flatmap(function(stream, file)
        {
            var basePath = file.path.replace(__dirname+'/'+sourceLib, '');

            // Now returns everything!
            console.log(basePath);

            // Run gulp on individual file
            return gulp
            .src([ ... ])
            .pipe( ... )
            .pipe( gulp.dest("path/to/production/") );
        }))

       // "Consume" the stream
       .pipe( browserSync.stream() );

    done();

});

@mariusGundersen
Copy link
Owner

Here is how I would do it:

gulp.task('example', function(){
    return gulp.src(librarySources)
        .pipe(plugins.flatmap(function(stream, file)
        {
            var basePath = file.path.replace(__dirname+'/'+sourceLib, '');

            console.log(basePath);

            // Run gulp on individual file
            return gulp
            .src([ ... ])
            .pipe( ... );
        }))
        .pipe( gulp.dest("path/to/production/") );
});

This way the task isn't marked as done until it is actually done processing (by returning the stream) and you consume the entire stream (by having gulp.dest() outside of flatMap().

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

2 participants