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

tanstart-analyzer

v0.2.0

Published

Static analyzer for TanStack Start apps - detect server code leaking into client bundles

Readme

tanstart-analyzer

Static analyzer for TanStack Start apps. Detects patterns that cause server code to leak into client bundles.

Why?

TanStack Start route loaders are isomorphic - they run on both server AND client during SPA navigation. If you import server-only modules (database, secrets) in loaders or components, they get bundled into the client.

This analyzer detects these patterns before they become production bugs.

Installation

npm install -D tanstart-analyzer
# or
pnpm add -D tanstart-analyzer

Quick Start

# Create config file
npx tanstart-analyzer init

# Run analysis
npx tanstart-analyzer check

Rules

| Rule | Severity | Description | |------|----------|-------------| | direct-db-import | error | Server module imports in isomorphic files | | loader-server-import | error | Server imports used in route loaders | | server-fn-misuse | error | Server functions called at module level | | barrel-export | warn | export * patterns that prevent tree-shaking | | env-leak | error | process.env access in client code | | import-chain | error | Transitive imports reaching server modules |

Configuration

Create tanstart-analyzer.config.ts:

export default {
  rootDir: "./src",

  boundaries: {
    // Files that ONLY run on server
    serverOnlyPatterns: [
      "**/server/**/*.ts",
      "**/inngest/**/*.ts",
    ],
    // Files bundled for BOTH server and client
    isomorphicPatterns: [
      "**/routes/**/*.tsx",
      "**/components/**/*.tsx",
      "**/hooks/**/*.ts",
      "**/lib/**/*.ts",
    ],
    // API routes (server-only)
    serverApiPatterns: ["**/routes/api/**/*.ts"],
  },

  // Modules that should NEVER be imported in isomorphic files
  serverOnlyModules: [
    "postgres",
    "drizzle-orm/postgres-js",
    "~/server/functions/db",
  ],

  rules: {
    "direct-db-import": "error",
    "loader-server-import": "error",
    "server-fn-misuse": "error",
    "barrel-export": "warn",
    "env-leak": "error",
    "import-chain": "error",
  },
}

CLI Usage

# Run with default config
npx tanstart-analyzer check

# Use specific config file
npx tanstart-analyzer check --config ./my-config.ts

# Output as JSON
npx tanstart-analyzer check --format json

# Write output to file
npx tanstart-analyzer check --format json --output report.json

# Show verbose output (import chains)
npx tanstart-analyzer check --verbose

# Fail on warnings
npx tanstart-analyzer check --fail-on-warn

Programmatic API

import { analyze, loadConfig } from "tanstart-analyzer"

// Simple usage
const result = await analyze()

if (result.errorCount > 0) {
  console.error(`Found ${result.errorCount} errors`)
  for (const violation of result.violations) {
    console.log(`${violation.relativePath}:${violation.line} - ${violation.message}`)
  }
  process.exit(1)
}

// With custom config
const config = await loadConfig({ configPath: "./custom-config.ts" })
const result = await analyze({ config })

How It Works

File Classification

The analyzer classifies files based on patterns:

  • server-only: Files in server/ or inngest/ directories - safe to import database
  • server-api: API routes with server.handlers - server-only execution
  • isomorphic: Routes, components, hooks - bundled for BOTH server and client

What Gets Detected

  1. Direct Server Imports

    // ❌ BAD - db imported in component
    import { db } from "~/server/functions/db"
  2. Loader Server Imports

    // ❌ BAD - db used in loader (runs on client!)
    import { db } from "~/server/functions/db"
    
    export const Route = createFileRoute('/trips')({
      loader: async () => await db.select().from(trips)
    })
  3. Environment Variable Leaks

    // ❌ BAD - secret exposed to client
    const secret = process.env.SECRET_KEY
  4. Import Chains

    // ❌ BAD - transitive import reaches server module
    // component.tsx → utils.ts → helpers.ts → db.ts

Safe Patterns

  • Type-only imports are always safe:

    import type { TripOffer } from "@tourvy/database"
  • Server functions are safe (TanStack Start handles code-splitting):

    import { getTrips } from "~/server/functions/trips"
    
    export const Route = createFileRoute('/trips')({
      loader: async () => await getTrips({ data: {} }) // RPC call
    })
  • Guarded env access is safe:

    if (typeof window !== "undefined") {
      return { apiUrl: "/api" }
    }
    return { apiUrl: process.env.API_URL }

CI Integration

Add to your CI pipeline:

# .github/workflows/ci.yml
- name: Check bundle
  run: npx tanstart-analyzer check

License

MIT