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

@aseity/mirage

v0.4.0

Published

Browser-side virtual backend for generated web app previews.

Readme

@aseity/mirage

Mirage publishes a collection of files as an independent browser preview. A service worker serves its URLs to an iframe, including relative scripts, styles, images, and fetches.

Setup

pnpm add @aseity/mirage

Serve MIRAGE_WORKER_SOURCE as JavaScript at /mirage-backend/worker.js. For example, a Next.js route at app/mirage-backend/worker.js/route.ts:

import { MIRAGE_WORKER_SOURCE } from '@aseity/mirage';

export function GET() {
  return new Response(MIRAGE_WORKER_SOURCE, {
    headers: {
      'Content-Type': 'application/javascript; charset=utf-8',
      'Cache-Control': 'no-cache',
    },
  });
}

Mirage requires HTTPS or localhost and a browser with service worker support. The worker's directory is its scope; use serviceWorkerPath to change it. The host page can live outside that scope.

Publish a preview

import { createMirage } from '@aseity/mirage';

const mirage = await createMirage();
const preview = await mirage.mount({
  '/index.html': '<h1>Hello</h1><script src="./app.js"></script>',
  '/app.js': 'console.log("Ready")',
  '/api/data.json': {
    type: 'file',
    content: JSON.stringify({ ready: true }),
    contentType: 'application/json',
  },
  '/images/logo.png': {
    type: 'proxy',
    target: 'https://example.com/logo.png',
  },
});

iframe.src = preview.url('/index.html');

// When the preview closes, remove its persisted files and proxy configuration.
await preview.dispose();

Interface

  • createMirage({ serviceWorkerPath? }) registers the worker and returns a host. It has no global configuration or active namespace. Multiple hosts can share the same worker without clearing one another's previews.
  • mirage.mount(files) publishes a complete snapshot and returns a preview only after every file and proxy configuration has been persisted. Each call creates a new preview URL. File contents are copied when called; later input mutations do not change the snapshot. A failed publication removes its partial data.
  • preview.url(path) returns an absolute URL, encoding each filename segment. preview.url('/') gives its base URL. Treat the URL structure as opaque.
  • preview.dispose() removes that snapshot. Repeated calls are safe, including concurrent calls; a failed disposal can be retried. New requests to removed files return 404. Requests already in progress may finish.

File values are strings, { type: 'file', content, contentType? }, or { type: 'proxy', target, headers? }. Contents can be strings, ArrayBuffers, or Uint8Arrays. Content types default from the filename. Directories are implicit; empty directories and directory listings are not supported. Paths escaping the preview root and duplicate normalized paths are rejected.

Each preview supports GET and HEAD. Queries do not change which file is served. Proxy entries fetch their configured HTTP(S) target on every request, preserving the upstream status and content type. They support fixed request headers and follow ordinary browser CORS restrictions; they are resource mappings, not a request-forwarding backend.

Use relative asset URLs inside a preview (./app.js, images/logo.png). URLs starting with / refer to the site's root. Fetching a preview URL from a host page outside the worker scope does not route through Mirage; fetch from the preview iframe instead.

Snapshots, including proxy configurations, survive worker termination and host reloads through Cache Storage. Proxy response bodies are not persisted. Browser storage eviction can remove snapshots. The host owns disposal; navigating away without disposing leaves the snapshot stored. Releasing one preview does not release any other preview.

For refreshes, mount a new snapshot, switch the iframe to its URL, and dispose the old preview when no longer needed. If an asynchronous mount finishes after its owner has closed, dispose the returned preview immediately.

Migrating from 0.3

This is a breaking interface change:

  • Replace getMirage, configureMirage, and await mirage with createMirage.
  • Remove setNamespace and clearPrevious; each mount is independently owned.
  • Replace mount(files, { overwrite: true }) with const preview = await mount(files).
  • Replace manually constructed URLs with preview.url(entry) and release the preview on close or replacement with preview.dispose().
  • Remove writeFile, mkdir, rm, watch, directory mount entries, and proxy memory-cache options. Publish a new snapshot to change files.
  • Replace MirageMountTree with MirageFiles. Worker protocol and internal entry types are no longer exported. scope, namespace, and debug initialization options and mirageContext have been removed.

Deploy the updated worker source together with the client. Legacy namespace URLs and the old mirage-cache-v1 storage format are not read by this version. Remount previews from their source files after upgrading; Mirage does not automatically delete the old cache.

Development

pnpm exec playwright install chromium
pnpm test
pnpm typecheck
pnpm lint

Tests cover atomic publication and rollback, real iframe loading, concurrent mounts, multiple tabs, disposal, encoded paths, and worker termination/recovery.

License

MIT