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

@happyvertical/smrt-vitest

v0.43.3

Published

Vitest plugin for automatic cross-package manifest loading in SMRT tests

Readme

@happyvertical/smrt-vitest

Vitest plugin for s-m-r-t projects -- required for all s-m-r-t tests. Auto-generates manifests, loads cross-package class metadata, and provides transaction-isolated test database utilities.

Installation

pnpm add -D @happyvertical/smrt-vitest

Usage

Required Plugin Setup

Every s-m-r-t project must include smrtVitestPlugin() in vitest.config.ts:

import { defineConfig } from 'vitest/config';
import { smrtVitestPlugin } from '@happyvertical/smrt-vitest';

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

Without this plugin, tests fail with "No field metadata found" or "unregistered class" errors.

Plugin Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | generateManifest | boolean | true | Auto-generate manifest at startup | | include | string[] | ['src/**/*.ts'] | Source patterns to scan | | exclude | string[] | ['**/*.d.ts', ...] | Patterns to exclude | | packages | string[] | [] | Additional packages beyond auto-discovered | | verbose | boolean | false | Enable detailed logging | | root | string | process.cwd() | Root directory | | setupFile | string | package setup entry | Override the setup file injected into Vitest projects | | aliasFilter | (entry) => boolean | keep all | Drop auto-generated workspace alias entries (receives the raw string find and replacement) |

Vite 8 (rolldown/oxc) Normalization

Vite 8 replaced esbuild with rolldown/oxc, which changed three behaviors that break s-m-r-t projects. The plugin normalizes all three so consuming apps don't need per-repo workarounds (evidence: anytown.ai#707, willgriffin.dev#220):

  1. esbuild.tsconfigRaw is ignored — legacy @smrt() decorators reach the bundle untransformed. The plugin injects oxc.decorator = { legacy: true, emitDecoratorMetadata: true } (plus the matching oxc.tsconfig.compilerOptions mirror).

  2. oxc elides type-position side-effect imports by default — test files usually sit outside the tsconfig include, so a repo-wide verbatimModuleSyntax never reaches them and side-effect model imports (s-m-r-t object registration) are silently dropped. The plugin injects oxc.typescript = { onlyRemoveTypeImports: true }.

  3. Rolldown prefix-matches string alias finds — a bare workspace alias like @org/pkgsrc/index.ts mangles unaliased subpath imports (@org/pkg/subsrc/index.ts/sub). Workspace aliases are emitted as anchored exact-match RegExps, so unaliased subpaths fall through to the package exports map; use aliasFilter to drop entries entirely.

    Breaking change for direct getWorkspaceViteAliases() consumers: each entry's find is now an anchored RegExp, not a string (the returned array is still ordered most-specific first, and the new second options parameter is optional). Code that used find as a string — e.g. a Map key or an equality filter — should match with entry.find.test('<specifier>') instead. Filters passed via aliasFilter (or the helper's options.filter) are unaffected: they receive the raw string find before anchoring. Plugin-only consumers need no changes.

All defaults are override-able: any oxc field you set in your own config is never injected (explicit consumer values always win, and sibling fields still deep-merge), and oxc: false suppresses injection entirely. The oxc keys are inert on esbuild-based vite ≤ 7.

Note: the plugin only reaches configs that include it (vitest configs and any vite config listing it in plugins). An app's separate build-only vite.config.ts without the plugin still needs its own oxc.decorator settings on vite 8.

Watch Mode Note

The manifest is generated once at vitest startup. Restart vitest after adding new @smrt() classes or fields.

API

Plugin

| Export | Description | |--------|-------------| | smrtVitestPlugin(options?) | Vite plugin -- generates manifest and loads cross-package classes | | setupSmrtManifests(options?) | Imperative alternative for non-Vite setups (e.g., globalSetup files) |

Test Database Utilities

| Export | Description | |--------|-------------| | createIsolatedTestDbFromManifest(options?) | Create DB from manifest with FK ordering and STI dedup (recommended) | | createIsolatedTestDb(options?) | Create DB with raw DDL schema and transaction isolation | | createTestDb(prefix?) | Create DB with cleanup function (no transaction isolation) | | getTestDbConfig(prefix?) | Get DB config for current environment | | getInMemoryDbConfig() | Get in-memory SQLite config | | getTestAdapter() | Detect adapter: 'postgres' or 'sqlite' | | getAdapterDisplayName() | Human-readable adapter name for test labels | | isPostgresAvailable() | Check if DATABASE_URL is set |

DB adapter auto-detection: DATABASE_URL set -> PostgreSQL; otherwise -> SQLite temp files.

Transaction Isolation Example

import { createIsolatedTestDb } from '@happyvertical/smrt-vitest';

let db, cleanup;

beforeEach(async () => {
  ({ db, cleanup } = await createIsolatedTestDb({
    schema: `CREATE TABLE users (id TEXT PRIMARY KEY, name TEXT NOT NULL)`
  }));
});

afterEach(async () => {
  await cleanup(); // Rolls back transaction
});

it('should insert and query', async () => {
  await db.insert('users', { id: '1', name: 'Alice' });
  const user = await db.get('users', { id: '1' });
  expect(user?.name).toBe('Alice');
});

Types

IsolatedTestDbOptions, IsolatedTestDbResult, ManifestTestDbOptions, TestDbAdapter, TestDbConfig, TransactionHandle

Dependencies

  • @happyvertical/smrt-core -- manifest builder, object registry
  • @happyvertical/sql -- database connections and transactions
  • vitest (peer) -- Vite test framework

License

MIT