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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hook-channel

v1.0.0

Published

A minimal, deterministic hook execution system for composing modular systems.

Readme

hook-channel

A minimal, deterministic hook execution system for composing modular systems.


Overview

hook-channel loads modules (typically from node_modules) and executes exported functions based on hook names.

It is designed to be:

  • Simple – no boilerplate required in plugins
  • Deterministic – ordered execution via priorities
  • Flexible – works both at runtime (Node.js) and build-time (bundled for browsers)

Core Concept

A hook is just a named function exported from a module:

export function build(ev) {
  // do something
}

When a hook is dispatched:

await channel.dispatch(new HookEvent("build", {...}));

All exported functions named build across all loaded modules are executed in order.


Installation

npm install hook-channel

Usage

Load a channel

import { loadHookChannel, HookEvent } from "hook-channel";

const channel = await loadHookChannel({
  keyword: "mysys-plugin",
  export: "mysys-build-events",
  cwd: "somedir"
});

This will:

  1. Locate the nearest package.json (based on cwd)
  2. Read its dependencies
  3. Filter packages containing the keyword, e.g. "mysys-plugin"
  4. Resolve the export "./mysys-build-events" using Node resolution
  5. Import all matching modules

Dispatch a hook (async)

await channel.dispatch(new HookEvent("build", {
  /* data */
}));

Dispatch a hook (sync)

channel.dispatchSync(new HookEvent("build", {
  /* data */
}));

⚠️ All handlers must be synchronous. If a handler returns a Promise, an error should be thrown.


Shorthand

await channel.dispatch("build", {...});

Plugin Authoring

A plugin is just a module exporting functions.

Example

export function build(ev) {
  console.log("running build step");
}

Priority

Execution order is controlled via a priority property:

build.priority = 15; // default is 10

Lower values run earlier.


Stop propagation

A handler can stop further execution:

export function build(ev) {
  if (something) {
    ev.stopPropagation();
  }
}

HookEvent

class HookEvent {
  constructor(name, data = {}) {
    this.name = name;
    this.data = data;
    this._stopped = false;
  }

  stopPropagation() {
    this._stopped = true;
  }
}

Bundle Mode (Browser)

Instead of loading modules at runtime, you can bundle them.

Create a channel in bundle mode

const channel = await loadHookChannel({
  keyword: "peac-plugin",
  export: "peac-build-events",
  load: false
});

Bundle

await channel.bundle({
  target: "file.js"
});

This generates a standalone module containing all hooks.


Use in browser

import { dispatch, HookEvent } from "./file.js";

await dispatch(new HookEvent("build", {...}));

Design Goals

  • No registration API (zero boilerplate)
  • Function name = hook name
  • Deterministic execution order
  • Works in both Node.js and browser environments
  • Keeps plugin system internal and minimal

Non-Goals

  • Dependency injection framework
  • Complex lifecycle management
  • Runtime plugin installation in browsers

Summary

hook-channel is a small primitive:

Load modules → collect functions → dispatch by name

Everything else is built on top of that.


License

MIT