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

glob-workers

v0.1.0

Published

A Node.js library and CLI for processing large numbers of files in parallel using worker threads. Simply specify a glob pattern and worker module to be run on each file that matches the glob.

Downloads

22

Readme

glob-workers

A Node.js library and CLI for processing large numbers of files in parallel using worker threads. Simply specify a glob pattern and worker module to be run on each file that matches the glob.

This is especially useful for CPU-intensive operations on large file collections, such as linting, parsing, transforming code, etc. The library is customizable, letting you configure the number of worker threads, the maximum number of files each worker can process concurrently, and so on.

Usage

npx glob-workers --glob '**/*.txt' --worker './my-worker.mjs'

Where my-worker.mjs contains a default export function that accepts a single WorkerOptions parameter:

// my-worker.mjs
export default function worker(options) {
  // options === { args, filePath, fileContent }
}

WorkerOptions

interface WorkerOptions {
  /** Arguments passed to the worker script. */
  args: string[]
  /** Path of the current file being processed. */
  filePath: string
  /** Content of the current file being processed. */
  fileContent: string
}

CLI Options

--glob, -g (string): The glob pattern of files to process.
--glob-cwd (string): Overrides the default glob `cwd` e.g. process.cwd()
--glob-ignore (string): Ignore pattern for glob matching.

--worker, -w (string): Path to the worker module.
--worker-cwd (string): Overrides the default `cwd` when resolving the worker module e.g. process.cwd()
--worker-max-files (number): Overrides the max number of files concurrently processed by each worker thread.

--max-workers (number): Override the max number of worker threads.
--verbose, -v (boolean): Output debug information.

JavaScript API

npm i glob-workers
import { globWorkers } from 'glob-workers'

await globWorkers({
  glob: '**/*.txt',
  worker: './my-worker.mjs',
})

globWorkers(options: GlobWorkersOptions): Promise<void>

Executes the provided worker module on each file that matches the provided glob pattern.

GlobWorkersOptions

An object with the following properties:

type GlobbyParameters = Parameters<typeof globby>

interface GlobWorkersOptionsCWD {
  /** @default process.cwd() */
  cwd?: URL | string
}

export type GlobWorkersOptions = {
  /** Glob pattern of files to process. */
  glob: GlobbyParameters[0]
  /** Glob options such as cwd, ignore patterns, etc. */
  globOptions?: GlobWorkersOptionsCWD &
    Omit<NonNullable<GlobbyParameters[1]>, 'cwd' | 'absolute'>
  /** Path to the worker module. */
  worker: string
  workerOptions?: GlobWorkersOptionsCWD & {
    /** Arguments passed to the worker module. */
    args?: string[]
    /**
     * Max number of files concurrently processed by each worker thread.
     * @default 50
     */
    maxFiles?: number
  }
  /** Max number of workers threads. */
  maxWorkers?: number
  /** Output debug information. */
  verbose?: boolean
}