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

@eserstack/collector

v5.1.0

Published

Readme

⚙️ @eserstack/collector

Note: JSR is frozen at 4.5.x. From 5.0.0, @eserstack/collector is published on npm under the same name (pnpm add @eserstack/collector); the JSR versions stay available but get no updates.

eserstack Library — eser/stack on GitHub Install: pnpm add @eserstack/collector

Module export collector and manifest generator. Walks a directory tree, dynamically imports modules, collects their exports, and generates a typed manifest file — useful for auto-discovery of routes, handlers, plugins, or any convention-based module system.

🚀 Quick Start

import * as collector from "@eserstack/collector";

// Collect all exports from a directory
const exports = await collector.collectExports({
  baseDir: "./src/routes",
});

for (const [file, moduleExports] of exports) {
  console.log(`${file}: ${moduleExports.map(([name]) => name).join(", ")}`);
}

🛠 Features

  • File Walking — Recursively walk directories for JS/TS modules
  • Export Collection — Dynamically import and collect module exports
  • Manifest Generation — Generate typed manifest files with import statements
  • Glob Filtering — Filter files with glob patterns
  • Export Filtering — Custom filter functions for selective export collection
  • Test File Exclusion — Automatically skips test files by default

🔌 API Reference

collectExports(options)

Walk a directory tree, import each module, and return its exports.

import * as collector from "@eserstack/collector";

const exports = await collector.collectExports({
  baseDir: "./src/handlers",
  globFilter: "**/mod.ts",
  exportFilter: async (entries) =>
    entries.filter(([name]) => name.startsWith("handle")),
});
// Returns: Array<[filename, Array<[exportName, exportValue]>]>

| Option | Type | Description | | ------------------- | ---------------------------------------------------------------- | ----------------------------------------------- | | baseDir | string | Root directory to walk | | globFilter | string | Glob pattern to filter files | | exportFilter | (entries: [string, unknown][]) => Promise<[string, unknown][]> | Filter collected exports | | ignoreFilePattern | RegExp | Pattern for files to skip (default: test files) |

walkFiles(baseDir, globFilter, ignoreFilePattern)

Async generator that yields relative file paths matching the criteria. It walks .ts, .tsx, .js, .jsx, .mts, .cts, .mjs and .cjs files, skips node_modules, .git, dist, coverage, .output and .cache directories and unreadable directories below baseDir, and yields files in depth-first, name-sorted order. A baseDir that cannot be read is an error.

The walk runs in Go when the native ajan library is loaded. Without it (no library, ESER_AJAN=disabled, or only the WASM build, which has no filesystem) the same walk runs in TypeScript on the runtime's file system, so no native library is required.

import * as collector from "@eserstack/collector";

for await (const file of collector.walkFiles("./src", "**/*.ts", /test/)) {
  console.log(file);
}

buildManifestFile(filepath, options)

Collect exports and write a manifest file to disk.

import * as collector from "@eserstack/collector";

await collector.buildManifestFile("./src/manifest.gen.ts", {
  baseDir: "./src/routes",
});
// Generates a file with import statements and a typed manifest object

buildManifest(target, options)

Collect exports and write a manifest to a WritableStream.

import * as fs from "node:fs";
import * as stream from "node:stream";
import * as collector from "@eserstack/collector";

const file = stream.Writable.toWeb(fs.createWriteStream("manifest.gen.ts"));
await collector.buildManifest(file, {
  baseDir: "./src/routes",
});

writeManifestToString(collection)

Convert a collected export array into a manifest string: one import * as $$identifier from "./path" line per file and a manifest object whose exports array refers to each export by the name of its value (a function's name). Imports and references are sorted in natural order, with numbers compared by value and lower case before upper case. The source is not formatted; run it through a formatter such as oxfmt for canonical style.

import * as collector from "@eserstack/collector";

const source = await collector.writeManifestToString(
  await collector.collectExports({ baseDir: "./src/routes" }),
);

specifierToIdentifier(specifier, used)

Convert a file path into a valid JavaScript identifier for use in generated imports, and add it to used. A name already in used gets a _1, _2, ... suffix.

import * as collector from "@eserstack/collector";

const used = new Set<string>();
collector.specifierToIdentifier("routes/[id].ts", used); // "routes_id_"
collector.specifierToIdentifier("routes/[id].js", used); // "routes_id__1"

Where the work runs

Go writes the manifest and the identifiers (pkg/ajan/collectorfx), reached through @eserstack/ajan: the native library, or its WASM build where the native library cannot load. writeManifestToString, buildManifest, buildManifestFile and specifierToIdentifier throw the bridge's load error when neither loads, for example with ESER_AJAN=disabled. specifierToIdentifier is synchronous and loads the bridge synchronously on first use. walkFiles and collectExports work without the bridge, as described above.

📋 Types

ExportItem

type ExportItem = [string, Array<[string, unknown]>];
// [filename, Array<[exportName, exportValue]>]

CollectExportsOptions

type CollectExportsOptions = {
  baseDir: string;
  globFilter?: string;
  exportFilter?: (entries: [string, unknown][]) => Promise<[string, unknown][]>;
  ignoreFilePattern?: RegExp;
};

🔗 For further details, visit the eserstack repository.