npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-cluster-src

v0.4.0

Published

Process files in parallel using node's cluster module

Downloads

3,123

Readme

Gulp Clustered File Source

Process files in parallel using node's cluster module.

Why

You might have a single task in your gulpfile that processes a lot of files, and some of those files might take a long time to process.

You also might be processing these files on a 8-core hyper-threaded monster of a box, which means you have 15 cores sitting there not doing anything.

When they could be...

This module attempts to seamlessly add multi-core support to a single task, as opposed to [gulp-multi-process][2], which runs multiple tasks in their own process.

Usage

const gulp       = require('gulp');
const envify     = require('gulp-envify');
const uglify     = require('gulp-uglify');

const clusterSrc = require('gulp-cluster-src')(gulp);

gulp.task('compress:js', () =>
    clusterSrc('src/**/*.js', src =>
        src.pipe(uglify())
           .pipe(gulp.dest('dist'))
    )
);

Caveats

  • You must return the value that clusterSrc returns back to gulp, so that gulp can detect when all the child processes are finished.

  • You must pass gulp into the function exported by gulp-cluster-src. This performs some necessary initialization steps.

How it works

TL;DR

Set up a file stream in the master process, spawn multiple child processes, hook the two up via process.send, and use the pipeline parameter factory function in each child process to do the actual work.

Wat?

Read the source, Luke.

Parameters

glob

opts

These parameters are passed as-is to glob-stream. See that package for what options it supports.

In addition, the following options are used by this package:

concurrency

The max number of child processes to spawn. The default is require('os').cpus().length.

This is a maximum limit. While you can specify a number greater than the number of processors in your machine, you won't really see any benefit. Also,

taskName

We automatically try to get the currently running task name, but this can be hard to do with certain gulp setups. In that case, use this parameter to set the task name.

Additional methods

clusterSrc.logfiles()

Creates a stream that will log the processed files. Not that gulp-debug can be used, but you might not like the results due to multiple processes writing to process.stdout at the same time.

clusterSrc.log(msg)

This is the function used by logfiles() to log output. It should be used instead of console.log or util.log for writing output.