Skip to content

Instantly share code, notes, and snippets.

@backnotprop
Created January 3, 2026 02:23
Show Gist options
  • Select an option

  • Save backnotprop/37a8e3e7aac00e9f9015e5dafbc3bf15 to your computer and use it in GitHub Desktop.

Select an option

Save backnotprop/37a8e3e7aac00e9f9015e5dafbc3bf15 to your computer and use it in GitHub Desktop.
// knip.ts (in the monorepo root)
import type { KnipConfig } from 'knip';
const config: KnipConfig = {
// Add schema for VSCode validation and autocompletion
$schema: 'https://unpkg.com/knip@5/schema.json',
// --- Monorepo Setup ---
// Knip automatically detects pnpm workspaces via pnpm-workspace.yaml.
// The `workspaces` key is only needed to *override* defaults for specific
// workspaces or include non-standard ones. We'll start without it.
// --- Entry Files ---
// Define the main starting points of your applications/packages.
// Patterns ending with '!' are considered 'production' code.
// Use --production flag to only analyze these.
entry: [
// API Service (likely entry point)
'packages/api/src/index.ts!',
// Worker Service (likely entry point)
'packages/worker/src/index.ts!',
// Example UI (main entry for Vite)
'packages/client-example-ui/src/main.tsx!',
// Parser CLI (entry defined in its package.json bin field - Knip might find this automatically, but explicit is good)
'packages/parser/src/index.ts!',
// Root-level scripts (if they import project code, adjust pattern if needed)
// 'scripts/**/*.ts', // Assuming TS scripts might exist later
// Config files that import dependencies
'eslint.config.mjs',
'packages/client-example-ui/vite.config.ts',
'packages/client/jest.config.js',
'packages/db-postgres/src/vitest.integration.config.mts', // Example test config
// Add other known entry points if Knip misses them
],
// --- Project Files ---
// Define glob patterns for files Knip should analyze.
// Defaults are usually good. '!' marks production code patterns.
project: [
'**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}!', // Mark all typical source files as potentially production
'!**/*.d.ts', // Exclude declaration files
// Exclude test files specifically from *production* analysis via the '!' on the main pattern
// and Knip's default exclusion of test patterns in production mode.
// For fine-grained control if needed:
// '!**/*.{spec,test}.{js,jsx,ts,tsx}!', // Ensure tests aren't marked production
// '!packages/db-postgres/src/test/**/*', // Example: Explicitly ignore test helpers if needed
],
// --- Ignores ---
// Ignore specific files or directories from reporting issues.
// NOTE: Files listed here are STILL ANALYZED for dependency tracing,
// but their *own* unused exports/etc., won't be reported.
ignore: [
'**/node_modules/**',
'**/dist/**', // Standard build output
'**/build/**', // Common build output
'**/*.config.js', // General JS config files (can be refined)
'**/*.config.ts', // General TS config files (can be refined)
'**/coverage/**', // Test coverage reports
'_project_context/**', // Your documentation folder
'**/prisma/migrations/**', // Prisma migration files
// Add specific generated files if they cause issues
// 'packages/db-postgres/src/generated/**/*',
],
// Ignore specific dependencies from being reported as unused.
// Useful for dev tools invoked via CLI, or types packages.
ignoreDependencies: [
'only-allow', // pnpm specific tool in root
'husky', // Git hooks tool
'lint-staged', // Used by husky
'npm-run-all', // Script runner
'rimraf', // Used in scripts
'dotenv-cli', // Used in scripts
'ts-node', // Used to run TS files directly (dev scripts)
'ts-node-dev', // Used in dev scripts
'tsc-files', // Used in lint-staged
'typescript', // Core TS compiler
'@types/node', // Node types
'eslint', // Linter (and related plugins listed in root devDeps)
'@eslint/js',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
'eslint-config-prettier',
'eslint-import-resolver-typescript',
'eslint-plugin-import-x',
'typescript-eslint',
'globals',
'prettier', // Formatter
'prisma', // ORM CLI tool
'vitest', // Test runner
'@vitest/coverage-v8', // Test coverage
'supertest', // API testing helper
'vite', // UI builder
'@vitejs/plugin-react', // Vite plugin
'@tailwindcss/vite', // Tailwind plugin
'tailwindcss', // Tailwind CSS
// Add any other dev dependencies used only via CLI/config files
],
// --- Production Mode Exclusions (Alternative/Refinement) ---
// If `project` patterns with '!' aren't enough, you can use negated patterns here for prod mode.
// Example: Exclude all test files explicitly IF running with --production
// production: {
// project: [ '!**/*.{test,spec}.{ts,tsx,js,jsx}!' ]
// },
// --- Plugin Config (if needed) ---
// Knip auto-detects many plugins (Vite, ESLint, etc.).
// Explicitly configure if auto-detection fails or needs overrides.
// vite: { config: ['packages/client-example-ui/vite.config.ts'] },
// typescript: { config: ['tsconfig.json'], project: ['packages/*/tsconfig.json'] },
};
export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment