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

@hypertheory-labs/msw-lens

v0.2.3

Published

Scenario switcher and context generator for MSW Mock Service Worker

Readme

msw-lens

A developer tool for projects that use MSW. Two jobs:

  1. Scenario switcher — flip between mock scenarios without editing handler files. Pick an endpoint, pick a scenario, the app updates via Vite HMR instantly.
  2. Context generator — crawl a component's imports, inline the source files an LLM needs, and write a ready-to-paste prompt.

The switcher is real and useful. The context generator is why the tool exists.

The real point

Every time you start a new AI conversation about your app, it begins cold. No memory of what you built or what state the app is running under. You become the translator.

msw-lens produces committed artifacts that any AI instance can read and reason about immediately:

  • src/mocks/active-scenarios.ts — which scenario is active per endpoint
  • src/mocks/bypassed-endpoints.ts — endpoints currently bypassing MSW (real-network passthrough)
  • .msw-lens/context.md — a snapshot of every mocked endpoint, active scenario, and bypass status
  • .msw-lens/prompts/<component>.md — a ready-to-paste prompt with the real source inlined

Drop context.md into any conversation. That instance knows what's mocked, what's active, and where the source lives. No narration required.

The manifest is the prompt. The same YAML is useful to the switcher, useful to you, and useful to an AI. One artifact, three consumers.

Install

npm install --save-dev @hypertheory-labs/msw-lens
{
  "scripts": {
    "lens:init": "msw-lens --init",
    "lens": "msw-lens",
    "lens:watch": "msw-lens --watch",
    "lens:context": "msw-lens --context"
  }
}

Zero-config if your MSW handlers live in src/mocks/ (MSW's default). Otherwise add a msw-lens block pointing at your mocks directory — see Configuration.

Run npm run lens:init once after install to bootstrap the tool-owned files.

MSW prerequisite for bypass

For the bypass option to pass through to real APIs, start MSW with onUnhandledRequest: 'bypass':

worker.start({ onUnhandledRequest: 'bypass' });

This is conventional MSW dev configuration — mock what you intend to mock, real-network everything else.

Commands

npm run lens:init                                     # bootstrap tool-owned files (run once)
npm run lens                                          # interactive scenario switcher
npm run lens:watch                                    # stay in switcher, Ctrl+C to exit
npm run lens:context -- <path/to/component.ts>        # generate an LLM prompt

The switcher's scenario picker offers bypass — pass through to real API per endpoint. Picking it filters the handler out of MSW registration so requests reach the real network. Pick any other scenario to restore mocking.

Minimum viable manifest

# yaml-language-server: $schema=https://unpkg.com/@hypertheory-labs/msw-lens/schema/manifest.schema.json

endpoint: /api/cart
method: GET
description: User's shopping cart

scenarios:
  typical:
    description: Cart has items — renders the list, enables checkout
    active: true

  empty:
    description: Zero items — tests the empty-cart message and disabled Checkout

Co-located with your MSW handler. Handler reads the active scenario and switches. Full reference: manifest format docs.

The two-universe model

msw-lens creates a handoff point between separate AI sessions:

Universe 1 (your session)          Universe 2 (any model, any session)
─────────────────────────          ───────────────────────────────────
npm run lens:context            →  receives .msw-lens/prompts/cart.md
  crawls your actual source         reads the real TypeScript + templates
  finds the endpoints               identifies what scenarios make sense
  inlines the files                 writes manifest + handler + gap analysis

The prompt is the artifact. The model is interchangeable. The conversation isn't durable; the YAML is.

Demos

This repo contains demo apps showing msw-lens working across frameworks — same manifest format, different UI.

| App | Framework | Status | |-----|-----------|--------| | apps/angular-demo/ | Angular 21 + Tailwind + DaisyUI | working | | apps/react-demo/ | Vite + React 19 + Tailwind + DaisyUI | working | | apps/vue-demo/ | Vue 3 + Vite | planned |

nx serve angular-demo       # dev server
nx build angular-demo       # production build
npm run build:lens          # build the package itself

Docs

Related

  • Stellar Devtools — observes app state, records causal chains (click → HTTP → state change), exports as AI-readable markdown. Stellar = observe. msw-lens = control.