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

@typeflowjs/plugin

v0.0.1

Published

Import .typeflow mapping files directly — Node ESM loader, CommonJS require hook, and Bun plugin

Downloads

18

Readme

@typeflowjs/plugin

Import .typeflow mapping files directly, in every JS/TS environment:

import mapUser from './user.typeflow'; // TS or JS, Node ESM, Bun, Vite
const mapUser = require('./user.typeflow'); // Node CommonJS

const view = mapUser(apiResponse);

The module's default export is the compiled mapping function. Types come from the .d.typeflow.ts sidecars (typeflow types + allowArbitraryExtensions in tsconfig), so the import is fully typed — this package supplies the runtime half.

Setup

| Environment | Setup | | --------------------------------- | ---------------------------------------------------------------------- | | TypeScript via tsc (tsconfig) | sidecars for types; run the emitted JS with the Node flag below | | Node — JS/emitted ESM and CJS | node --import @typeflowjs/plugin/register app.js | | tsx | tsx --import @typeflowjs/plugin/register app.ts | | ts-node (CommonJS mode) | node -r ts-node/register --import @typeflowjs/plugin/register app.ts | | Bun — TS or JS | preload = ["@typeflowjs/plugin/bun"] in bunfig.toml | | Vite (dev, build, SSR) / Rollup | plugins: [typeflow()] from @typeflowjs/plugin/vite |

The Node hooks chain: tsx/ts-node handle .ts, this plugin handles .typeflow, in the same process and in either flag order.

Node (one flag covers both ESM import and CJS require):

$ node --import @typeflowjs/plugin/register app.js

or programmatically, before the first .typeflow import:

import { register } from '@typeflowjs/plugin';
register();

Bun (bun run, bun test, bun build) — in bunfig.toml:

preload = ["@typeflowjs/plugin/bun"]

Vite / Rollup — in vite.config.ts:

import typeflow from '@typeflowjs/plugin/vite';

export default defineConfig({ plugins: [typeflow()] });

Compilation happens at build/dev time and the emitted module only pulls the browser-safe typeflowjs/runtime, so this works for browser apps too — the compiler never ships to the client.

Runnable examples for every environment live in examples/.

How it works

All three hooks share one core (src/compile.ts): the file is compiled once in the hook (TypeScript adapter included, so input x: T from "./types" works), and the emitted module embeds the compiled JSON artifact — at runtime the consumer's module graph only loads typeflowjs/runtime (the tiny dependency-free interpreter) plus the mapping's own use modules, never the compiler.

  • ./register → Node module.register() ESM hooks + a require.extensions hook for CJS.
  • ./bunBun.plugin (runtime and bundler).
  • ./vite → Vite/Rollup plugin (same object shape works for both).
  • use fn(...) from "./mod" declarations become real imports of the emitted module — resolved to extension-explicit relative paths, so they work under Node ESM (no extension guessing), Vite, and Bun alike. Under require(), ESM use modules need Node >= 22.12.
  • Functions registered programmatically via defineFunction can't be wired through a bare file import — use loadTypeflowMapping from typeflowjs for those.

Build & test

bun install
bun run typecheck
bun run test   # builds, then verifies the full matrix against real
               # toolchains: node esm/cjs, bun js/ts, tsc esm/cjs (typed,
               # real tsconfig), vite build — needs the repo root's
               # `bun scripts/build.ts` first

typeflowjs is a peerDependency (also a devDependency, for local build/test) rather than a regular dependency: this package's hooks compile .typeflow files in the consumer's own process at import time, so it should use whichever typeflowjs version the consumer's project already has installed rather than pulling in a second copy of the compiler.