### Install Pruny Globally or Run with npx Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Install Pruny globally for direct command-line access or use npx to run it without a global installation. The 'pruny init' command generates a configuration file. ```bash npm install -g pruny ``` ```bash npx pruny ``` ```bash pruny init ``` -------------------------------- ### Install and Run Pruny CLI Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt Install Pruny globally using npm or run it directly with npx. This command installs the CLI tool for project-wide use. ```bash npm install -g pruny # or run directly npx pruny ``` -------------------------------- ### Pruny Configuration File Example Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt A sample pruny.config.json file demonstrating how to configure ignore patterns for routes, folders, files, and links, as well as specify file extensions and NestJS global prefix. ```json { "ignore": { "routes": ["/api/webhooks/**", "/api/cron/**"], "folders": ["node_modules", ".next", "dist", ".git"], "files": ["*.test.ts", "*.spec.ts"], "links": ["/custom-path", "/legacy/*"] }, "extensions": [".ts", ".tsx", ".js", ".jsx"], "nestGlobalPrefix": "", "extraRoutePatterns": [] } ``` -------------------------------- ### Install Pruny CLI Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Install Pruny globally using npm or run it directly with npx. This command makes the pruny CLI available in your terminal. ```bash npm install -g pruny ``` ```bash npx pruny ``` -------------------------------- ### Pruny Configuration Example Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Create a pruny.config.json file in your project root to specify ignore patterns for routes, folders, files, and links, as well as custom file extensions. Supports glob syntax for patterns. ```json { "ignore": { "routes": ["/api/webhooks/**", "/api/cron/**"], "folders": ["node_modules", ".next", "dist"], "files": ["*.test.ts", "*.spec.ts"], "links": ["/custom-path", "/legacy/*"] }, "extensions": [".ts", ".tsx", ".js", ".jsx"] } ``` -------------------------------- ### Pruny Configuration for Ignoring Links Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Example of a pruny.config.json file specifically showing how to use the `ignore.links` option to suppress broken link warnings for specified paths. ```json { "ignore": { "links": ["/view_seat", "/review", "/custom-path"] } } ``` -------------------------------- ### Pruny CI Integration Example Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Integrate Pruny into your CI pipeline to automatically detect unused code before merging. The `--all` flag ensures all monorepo apps are scanned and the process exits with code 1 if issues are found. ```bash npx pruny --all ``` -------------------------------- ### Pruny Configuration for Multi-Tenant Ignore Links Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt Example of configuring ignore.links within pruny.config.json to suppress broken link warnings for specific paths, useful in multi-tenant or externally handled routing scenarios. ```json { "ignore": { "links": ["/view_seat", "/review"] } } ``` -------------------------------- ### Run Pruny in CI Mode Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Scans all apps in a monorepo and exits with code 1 if unused items are found, suitable for CI pipelines. Example shows GitHub Actions integration. ```bash npx pruny --all ``` ```yaml # In GitHub Actions: # - name: Check for unused code # run: npx pruny --all ``` ```text # Expected output (issues found): # 👉 Scanning App: web... 3 issues found # 👉 Scanning App: api... ✅ # # ⚠ Issues in web: # ❌ Unused API Routes (Fully Unused): # /api/legacy-users (GET) # → apps/web/app/api/legacy-users/route.ts # # 📊 Monorepo Summary # ┌──────────────┬────────┬───────┬─────────┬────────┐ # │ (index) │ Routes │ Files │ Exports │ Issues │ # ├──────────────┼────────┼───────┼─────────┼────────┤ # │ web (Next.js)│ 12 │ 142 │ 310 │ 3 │ # │ api (NestJS) │ 8 │ 96 │ 201 │ 0 │ # │ Total │ 20 │ 238 │ 511 │ 3 │ # └──────────────┴────────┴───────┴─────────┴────────┘ # Process exits with code 1 ``` -------------------------------- ### Broken Link Detection Example Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md This example demonstrates how Pruny detects internal link references, including those defined in arrays and rendered via `.map()`. Paths are validated against known routes, and dynamic segments are matched correctly. ```tsx const navLinks = [ { href: "/about", label: "About" }, // checked { href: "/nonexistent", label: "Missing" }, // flagged as broken ]; // Later: navLinks.map(item => ...) ``` -------------------------------- ### Ignoring Specific Links Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Configure Pruny to ignore specific links by adding them to the `ignore.links` array in your configuration file. This is useful for handling custom routing setups or known false positives. ```json { "ignore": { "links": ["/view_seat", "/review", "/custom-page"] } } ``` -------------------------------- ### Build and Scan Local Projects Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/testing.md Build the project and then use the scanner to analyze a local directory. Supports CI mode for automated checks and auto-fix mode for corrections. ```bash bun run build node dist/index.js --dir /path/to/project node dist/index.js --dir /path/to/project --all # CI mode (exit 1 on issues) node dist/index.js --dir /path/to/project --fix # auto-fix mode ``` -------------------------------- ### Generate Config File Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Run `pruny init` to create a `pruny.config.json` file in the current directory with default values. Running it multiple times is safe as it skips if the file already exists. ```bash pruny init ``` ```json { "ignore": { "routes": [], "folders": ["node_modules", ".next", "dist", "build"], "files": [], "links": [] }, "extensions": [".ts", ".tsx", ".js", ".jsx"], "nestGlobalPrefix": "", "extraRoutePatterns": [] } ``` -------------------------------- ### Initialize Pruny Configuration File Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Generate a default pruny.config.json file in your project root. ```bash pruny init ``` -------------------------------- ### Monorepo CLI Usage Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Command-line interface options for running Pruny in a monorepo. Use `--all` to scan everything, `--app` to specify an app, or `--ignore-apps` to exclude specific apps. ```bash # Scan everything (CI mode) pruny --all ``` ```bash # Scan one app pruny --app web ``` ```bash # Skip certain apps pruny --ignore-apps admin,docs ``` -------------------------------- ### loadConfig(options) Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Loads and merges configuration from all `pruny.config.json`, `.prunyrc.json`, or `.prunyrc` files found in the project, including patterns from `.gitignore`. It allows specifying the directory to scan and an optional explicit configuration file path. ```APIDOC ## loadConfig(options) ### Description Loads and merges configuration from all `pruny.config.json` / `.prunyrc.json` / `.prunyrc` files found in the project, plus `.gitignore` patterns. ### Parameters #### Path Parameters - **options** (object) - Required - Options for loading the configuration. - **dir** (string) - Required - The directory to start searching for configuration files. - **config** (string) - Optional - The explicit path to a configuration file. - **excludePublic** (boolean) - Optional - Whether to exclude public assets from the configuration. ### Request Example ```typescript import { loadConfig } from 'pruny/dist/config.js'; // Basic usage const config = loadConfig({ dir: './apps/web' }); // With explicit config path const config2 = loadConfig({ dir: './', config: './configs/pruny.custom.json', excludePublic: true, }); console.log(config.ignore.folders); // merged ignore list including .gitignore entries console.log(config.nestGlobalPrefix); // e.g. 'api/v1' console.log(config.extensions); // ['.ts', '.tsx', '.js', '.jsx'] ``` ### Response #### Success Response (200) - **ignore** (object) - Contains `folders` property with a merged ignore list. - **nestGlobalPrefix** (string) - The NestJS global prefix, if configured. - **extensions** (array) - An array of file extensions to consider. ``` -------------------------------- ### Pruny CLI Commands Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/CLAUDE.md Common commands for building, developing, linting, validating, testing, and running Pruny in CI mode. Use `pruny --all` for CI checks. ```bash bun run build # build dist/ (main + worker) ``` ```bash bun run dev # run src/index.ts directly ``` ```bash bun run lint # eslint ``` ```bash bun run validate # lint + tsc --noEmit ``` ```bash bun test # bun:test ``` ```bash pruny --all # CI mode: scan all apps, exit 1 if issues ``` -------------------------------- ### Run Tests with Bun Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/testing.md Execute all tests using `bun:test`, a specific test file, or run a validation script that includes linting, type checking, and tests. ```bash bun test # all tests (uses bun:test) bun test tests/foo.test.ts # one file bun run validate # lint + tsc --noEmit + tests ``` -------------------------------- ### Run Interactive Scan with Pruny Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Launches an interactive scan. In monorepos, it prompts for app selection; in single repos, it scans the current directory. Displays a summary report of unused items. ```bash # Single repo — scan current directory pruny # Monorepo — interactive app picker pruny ``` ```text # Expected output: # 🔍 Scanning for unused API routes... # # 👉 Scanning App: web... # # 📊 Summary Report for App: web # ┌─────────────────────────────┬───────┬──────┬────────┐ # │ (index) │ Total │ Used │ Unused │ # ├─────────────────────────────┼───────┼──────┼────────┤ # │ API Routes (Next.js) (web) │ 12 │ 9 │ 3 │ # │ Public Files (public/) │ 24 │ 20 │ 4 │ # │ Internal Links │ 87 │ 84 │ 3 │ # │ Code Files (.ts/.js) │ 142 │ 138 │ 4 │ # │ Named Exports │ 310 │ 295 │ 15 │ # └─────────────────────────────┴───────┴──────┴────────┘ # # ⏱️ Completed in 2.34s ``` -------------------------------- ### Run Pruny in Interactive Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Scan the current directory or a specific app/directory for unused code and interactively review issues. ```bash npx pruny # Scan current directory npx pruny --app web # Scan a specific app in a monorepo npx pruny --dir ./src # Scan a specific directory ``` -------------------------------- ### Load Pruny Configuration Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use `loadConfig` to load and merge configuration from `pruny.config.json`, `.prunyrc.json`, or `.prunyrc` files. It also incorporates patterns from `.gitignore`. Basic usage requires a directory; an explicit config path and exclusion options are also available. ```typescript import { loadConfig } from 'pruny/dist/config.js'; // Basic usage const config = loadConfig({ dir: './apps/web' }); // With explicit config path const config2 = loadConfig({ dir: './', config: './configs/pruny.custom.json', excludePublic: true, }); console.log(config.ignore.folders); // merged ignore list including .gitignore entries console.log(config.nestGlobalPrefix); // e.g. 'api/v1' console.log(config.extensions); // ['.ts', '.tsx', '.js', '.jsx'] ``` -------------------------------- ### Simulate Cleanup with Pruny Dry Run Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Runs a simulation of the fix-mode cleanup without modifying any files. Generates a `pruny-dry-run.json` report detailing the proposed changes. ```bash pruny --dry-run ``` ```text # Writes: pruny-dry-run.json ``` -------------------------------- ### Pruny CLI Commands for Monorepos Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Commands to manage scanning within a monorepo. Use `--all` for CI, `--app` to specify an app, and `--ignore-apps` to exclude specific applications from the scan. ```bash # Scan all apps (CI-friendly, exits 1 on issues) pruny --all ``` ```bash # Scan a specific app pruny --app web ``` ```bash # Skip certain apps pruny --ignore-apps admin,docs ``` -------------------------------- ### Programmatic Usage: `scan(config)` with Pruny Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Import and use the `scan` function for programmatic analysis. It requires a configuration object and returns a `ScanResult` containing details on unused routes, exports, and broken links. Iterate through the results to identify specific issues. ```typescript import { scan } from 'pruny/dist/scanner.js'; import { loadConfig } from 'pruny/dist/config.js'; const config = loadConfig({ dir: './apps/web' }); const result = await scan(config); console.log(`Found ${result.unused} unused routes`); console.log(`Found ${result.unusedExports?.unused} unused exports`); console.log(`Found ${result.brokenLinks?.total} broken links`); // Iterate unused routes for (const route of result.routes.filter(r => !r.used)) { console.log(`Unused: ${route.path} (${route.type}) → ${route.filePath}`); } // Iterate broken links for (const link of result.brokenLinks?.links ?? []) { console.log(`Broken link: ${link.path}`); for (const ref of link.references) { console.log(` Referenced in: ${ref}`); } } // Iterate unused exports for (const exp of result.unusedExports?.exports ?? []) { console.log(`Unused export: ${exp.name} at ${exp.file}:${exp.line}`); } ``` -------------------------------- ### Quick Cleanup with Pruny Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Target specific categories for cleanup without the interactive menu. ```bash npx pruny --cleanup routes # Only clean unused routes npx pruny --cleanup routes,exports # Clean routes and exports npx pruny --cleanup public,files # Clean assets and files ``` -------------------------------- ### Run Pruny in Interactive Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt Initiate an interactive scan for unused code. Use the --app flag to specify a particular application within a monorepo. ```bash npx pruny # Scan interactively (auto-detects monorepo) npx pruny --app web # Scan a specific app in a monorepo ``` -------------------------------- ### Perform Interactive Cleanup with Pruny Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Enables interactive cleanup of unused items. Presents a menu to select categories for deletion and performs a cascading cleanup. Warns if no .git directory is found. ```bash pruny --fix ``` ```text # Menu prompt: # ? Select items to clean up: # ❯ Unused API Routes (3 items in 2 files) # Unused Public Files (4) # Unused Code Files (4) # Unused Exports (15 items in 8 files) # Unused NestJS Service Methods (2 items in 1 files) # ✅ Internal Links (0) - All good! # Cancel / Exit # # ? How do you want to proceed with routes? # ❯ 🗑️ Delete (Fix) # 📝 Dry Run (JSON Report) # ❌ Cancel # # After deletion: # 🗑️ Cleaning up API routes... # Deleted: app/api/legacy-users # Fixed: Removed DELETE from apps/api/src/users/users.controller.ts (/api/users) # # 🔄 Checking for cascading dead code (newly unused implementation)... # Found 2 newly unused items/methods after pruning. # Fixed: legacyUserMapper in src/lib/mappers.ts ``` -------------------------------- ### Pruny CLI with Other Flags Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt Utilize various flags to customize Pruny's scanning behavior, such as specifying directories, folders, cleanup targets, filters, ignored apps, and output formats. ```bash npx pruny --dir ./src # Scan specific directory npx pruny --folder src/api # Scan specific folder npx pruny --cleanup routes,exports # Quick targeted cleanup npx pruny --filter "users" # Filter results by pattern npx pruny --ignore-apps admin,docs # Skip specific apps npx pruny --no-public # Skip public asset scanning npx pruny --json # JSON output npx pruny -v # Verbose debug logging npx pruny init # Generate pruny.config.json ``` -------------------------------- ### Pruny Configuration: Ignore Folders Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Define directories to be excluded from all scanning. Pruny automatically ignores common directories like node_modules and .git. ```json { "ignore": { "folders": ["scripts", "migrations"] } } ``` -------------------------------- ### Run Pruny in Dry Run Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Simulate the fix mode without making any changes, outputting a JSON report of potential deletions. ```bash npx pruny --dry-run ``` -------------------------------- ### Broken-Links Scanner Verification Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/testing.md Create a scratch file with Next.js Link components to test template-literal `${}` capture and gitignore-pattern handling. Verify that broken internal links are reported. ```tsx // /app/__test_broken_links.tsx import Link from "next/link"; const id = "x"; export const A = () => dead; export const B = () => static dead; ``` -------------------------------- ### Enable Pruny Debug Mode Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Set the `DEBUG_PRUNY=1` environment variable to enable verbose logging for all Pruny scanners. This provides detailed output for route extraction, reference matching, static params, and NestJS analysis. ```bash DEBUG_PRUNY=1 pruny # Sample debug output: # [DEBUG] Extracted Route: /api/users from apps/api/src/users/users.controller.ts # [DEBUG] Known routes: /, /dashboard, /dashboard/[id], /profile, /settings # [DEBUG USE] formatUser used via import in src/components/UserCard.tsx # [DEBUG] Static params for /blog/[slug]: slug=42 # [DEBUG] NestJS route /admin de-marked: Next.js replacement exists at /api/admin ``` -------------------------------- ### Pruny CLI with Filter and Ignore Flags Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Use filter and ignore flags to customize the scan results and skip specific apps. ```bash npx pruny --filter "users" # Filter results by pattern npx pruny --ignore-apps admin,docs # Skip apps in monorepo scan npx pruny --folder src/api # Scan a specific folder only npx pruny --no-public # Skip public asset scanning npx pruny --json # Output as JSON npx pruny -v, --verbose # Verbose debug output npx pruny -c, --config # Specify config file path ``` -------------------------------- ### Run Pruny in CI Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt Execute Pruny in CI mode to scan all applications and exit with a non-zero status code if issues are found. This is suitable for automated checks. ```bash npx pruny --all # Scan all apps, exit 1 if issues found ``` -------------------------------- ### Enable Pruny Debug Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Run Pruny with the DEBUG_PRUNY environment variable set to 1 to enable verbose logging across all scanners for detailed debugging information. ```bash DEBUG_PRUNY=1 pruny ``` -------------------------------- ### Pruny Configuration: Ignore Files Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Specify file patterns to exclude from scanning, such as test files or storybook components. ```json { "ignore": { "files": ["*.test.ts", "*.spec.ts", "*.stories.tsx"] } } ``` -------------------------------- ### scanBrokenLinks(config) Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Scans all source files for various link references (e.g., ``, `router.push()`, `href:`) and validates them against the Next.js file-based route map. It returns a result object detailing the total broken links, the number of scanned paths, and a list of broken links with their references. ```APIDOC ## scanBrokenLinks(config) ### Description Scans all source files for ``, `router.push()`, `redirect()`, `href:`, ``, `revalidatePath()`, and `pathname ===` references, validating each against the Next.js file-based route map. ### Parameters #### Path Parameters - **config** (object) - Required - Configuration object for the scanner. ### Request Example ```typescript import { scanBrokenLinks } from 'pruny/dist/scanner.js'; import { loadConfig } from 'pruny/dist/config.js'; const config = loadConfig({ dir: './apps/web' }); const result = await scanBrokenLinks(config); // { total: 3, scanned: 87, links: [...] } console.log(`Scanned ${result.scanned} unique link paths, found ${result.total} broken`); for (const link of result.links) { console.log(`Broken: ${link.path}`); link.references.forEach(ref => console.log(` → ${ref}`)); } // Broken: /user-profile // → src/components/Navbar.tsx:42 // → src/app/dashboard/page.tsx:18 ``` ### Response #### Success Response (200) - **total** (number) - The total number of broken links found. - **scanned** (number) - The number of unique link paths scanned. - **links** (array) - An array of objects, where each object represents a broken link and contains `path` and `references` properties. ``` -------------------------------- ### Pruny Configuration: Ignore Links Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Suppress warnings for broken internal links for specific paths. Useful for multi-tenant apps, reverse proxy routes, or external redirects. ```json { "ignore": { "links": ["/view_seat", "/review", "/admin/*"] } } ``` -------------------------------- ### Scan Specific App Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use the --app flag to scan only a specific application within a monorepo. This is useful for targeted analysis while still considering cross-app references. ```bash pruny --app web pruny --app api ``` ```text # Expected: # 🔍 Scanning for unused API routes... # 📦 Detected monorepo root: /projects/my-monorepo # # 👉 Scanning App: web... # [summary table for web only] ``` -------------------------------- ### Run Pruny in Fix Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Interactively select unused items to delete and perform a second pass to catch newly orphaned code. ```bash npx pruny --fix ``` -------------------------------- ### Skip Apps in Monorepo Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use the --ignore-apps flag to exclude specific applications from scanning in a monorepo. Accepts a comma-separated list of app directory names. ```bash pruny --ignore-apps admin,docs pruny --all --ignore-apps storybook,e2e ``` ```text # Expected: All apps EXCEPT 'admin' and 'docs' are scanned. ``` -------------------------------- ### Mandatory Smoke Tests Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/testing.md After code changes, verify against two real-world projects to catch regressions. Ensure there are 0 unused items or only pre-existing issues. ```bash bun run build node dist/index.js --dir /Users/webnaresh/coding-line/practice-stack --ignore-apps extension node dist/index.js --dir /Users/webnaresh/coding-line/abhyaiska ``` -------------------------------- ### JSON Output with jq Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use the --json flag to output the full scan result as JSON. This is useful for integrating with other tools like jq for advanced filtering and processing. ```bash pruny --json | jq '.routes[] | select(.used == false) | .path' ``` ```json { "total": 12, "used": 9, "unused": 3, "routes": [ { "type": "nextjs", "path": "/api/legacy-users", "filePath": "app/api/legacy-users/route.ts", "used": false, "references": [], "methods": ["GET"], "unusedMethods": ["GET"], "methodLines": { "GET": 3 } } ], "publicAssets": { "total": 24, "used": 20, "unused": 4, "assets": [...] }, "brokenLinks": { "total": 3, "scanned": 87, "links": [...] }, "unusedFiles": { "total": 4, "used": 138, "unused": 4, "files": [...] }, "unusedExports": { "total": 310, "used": 295, "unused": 15, "exports": [...] }, "unusedServices": { "total": 2, "methods": [...] } } ``` -------------------------------- ### Scan Specific Folder Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use the --folder flag to restrict route and export scanning to a specific subfolder. This is helpful for checking only a section of the codebase, while references are still checked project-wide. ```bash pruny --folder src/billing pruny --folder apps/web/app/api/payments ``` ```text # Expected: Only routes and exports found under the specified folder are reported. # References are still checked across the full project. ``` -------------------------------- ### Vercel Cron Detection Configuration Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/README.md Configure Vercel cron jobs to automatically mark specific API routes as used, preventing them from being flagged as dead code by Pruny. ```json { "crons": [{ "path": "/api/cron/cleanup", "schedule": "0 0 * * *" }] } ``` -------------------------------- ### Vercel Cron & Rewrite Integration with Pruny Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Routes defined in `vercel.json` for cron jobs, rewrites, and redirects are automatically marked as used by Pruny. This prevents them from being reported as unused. ```json // vercel.json { "crons": [ { "path": "/api/cron/cleanup", "schedule": "0 0 * * *" }, { "path": "/api/cron/send-digests", "schedule": "0 9 * * 1" } ], "rewrites": [ { "source": "/healthz", "destination": "/api/health" } ] } ``` ```bash pruny # /api/cron/cleanup → marked as used (vercel.json) # /api/cron/send-digests → marked as used (vercel.json) # /api/health → marked as used (vercel.json rewrite target) ``` -------------------------------- ### Skip Public Asset Scanning Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Disable scanning of the `public/` directory for unused assets by using the --no-public flag. This can speed up scans on projects with large asset directories. ```bash pruny --no-public pruny --all --no-public ``` -------------------------------- ### Pruny Configuration: Ignore Routes Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Specify glob patterns for API routes to be ignored during scanning, useful for external endpoints like webhooks or cron jobs. ```json { "ignore": { "routes": ["/api/webhooks/**", "/api/cron/**", "/api/stripe/webhook"] } } ``` -------------------------------- ### Non-Interactive Batch Cleanup Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Perform cleanup of specific categories without interactive prompts using the --cleanup flag. Accepts a comma-separated list of items: 'routes', 'exports', 'public', 'files'. ```bash # Clean up unused routes and public assets in one command pruny --cleanup routes,public # Clean only exports (useful in CI auto-fix workflows) pruny --cleanup exports # Combined with --app for targeted monorepo cleanup pruny --app web --cleanup routes,files ``` -------------------------------- ### Auto-Detected External Routes with Pruny Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Pruny automatically recognizes popular libraries like `next-auth` and `inngest` that register external route handlers. This prevents false positives by marking their routes as used. ```json // package.json (auto-detected by pruny) { "dependencies": { "next-auth": "^5.0.0", "inngest": "^3.0.0" } } ``` ```bash pruny # /api/auth/[...nextauth] → marked as used (auto-detected: next-auth) # /api/inngest → marked as used (auto-detected: inngest) ``` -------------------------------- ### Run Pruny in Fix Mode Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/llms.txt Use fix mode to interactively delete detected unused items. The --dry-run flag simulates the process and outputs a JSON report without making changes. ```bash npx pruny --fix # Interactively delete unused items npx pruny --dry-run # Simulate and output JSON report ``` -------------------------------- ### Vercel Cron Job Configuration Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Automatically mark routes used by Vercel cron jobs as 'used' by listing them in the `vercel.json` configuration file. This prevents accidental deletion of server-side cron handlers. ```json { "crons": [ { "path": "/api/cron/cleanup", "schedule": "0 0 * * *" } ] } ``` -------------------------------- ### scanUnusedServices(config) Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Scans NestJS *.service.ts files for methods that are never called by controllers, other services, or modules. It returns a result object containing the total count of unused methods and a list of these methods with their details. ```APIDOC ## scanUnusedServices(config) ### Description Scans NestJS `*.service.ts` files for methods never called by controllers, other services, or modules. ### Parameters #### Path Parameters - **config** (object) - Required - Configuration object for the scanner. ### Request Example ```typescript import { scanUnusedServices } from 'pruny/dist/scanner.js'; import { loadConfig } from 'pruny/dist/config.js'; const config = loadConfig({ dir: './apps/api' }); const result = await scanUnusedServices(config); // { total: 2, methods: [...] } for (const method of result.methods) { console.log(`${method.name} (${method.serviceClassName}) at ${method.file}:${method.line}`); } // deleteOldSessions (SessionService) at src/session/session.service.ts:87 // generateLegacyToken (AuthService) at src/auth/auth.service.ts:134 ``` ### Response #### Success Response (200) - **total** (number) - The total number of unused methods found. - **methods** (array) - An array of objects, where each object represents an unused method and contains `name`, `serviceClassName`, `file`, and `line` properties. ``` -------------------------------- ### Programmatic Usage: `scanUnusedExports(config)` with Pruny Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use `scanUnusedExports` for focused scanning of unused named exports. This function leverages worker threads for performance on large projects (500+ files). The result includes counts and a list of unused exports with their location and internal usage status. ```typescript import { scanUnusedExports } from 'pruny/dist/scanner.js'; import { loadConfig } from 'pruny/dist/config.js'; const config = loadConfig({ dir: './' }); const result = await scanUnusedExports(config); // { total: 310, used: 295, unused: 15, exports: [...] } for (const exp of result.exports) { console.log(`${exp.name} in ${exp.file}:${exp.line} (usedInternally: ${exp.usedInternally})`); } // formatDate in src/lib/date-utils.ts:12 (usedInternally: false) // legacyMapper in src/lib/mappers.ts:45 (usedInternally: false) ``` -------------------------------- ### Filter Results by Pattern Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use the --filter flag to limit all output to items matching a given pattern (case-insensitive path/name match). Summary table counters are recalculated to reflect filtered results. ```bash pruny --filter billing pruny --filter src/components ``` ```text # Only results whose file path or API path contains 'billing' are displayed. # Summary table counters are also recalculated to reflect filtered results. ``` -------------------------------- ### API Route Detection Patterns Source: https://github.com/navibyte-innovations-pvt-ltd/pruny/blob/main/docs/index.md Pruny detects API route usage by scanning for string literal patterns in fetch calls, axios requests, useSWR hooks, and other common HTTP client libraries. It does not detect fully dynamic URL variables. ```text - Detected: `fetch('/api/users')`, `` fetch(`/api/users/${id}`) ``, `axios.get('/api/items')`, `useSWR('/api/data')` - Not detected: `fetch(myUrlVariable)` where the path is fully dynamic with no `/api/` prefix ``` -------------------------------- ### Scan Unused NestJS Services Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Use `scanUnusedServices` to find methods in `*.service.ts` files that are not called by controllers, other services, or modules. Requires a configuration object. ```typescript import { scanUnusedServices } from 'pruny/dist/scanner.js'; import { loadConfig } from 'pruny/dist/config.js'; const config = loadConfig({ dir: './apps/api' }); const result = await scanUnusedServices(config); // { total: 2, methods: [...] } for (const method of result.methods) { console.log(`${method.name} (${method.serviceClassName}) at ${method.file}:${method.line}`); } // deleteOldSessions (SessionService) at src/session/session.service.ts:87 // generateLegacyToken (AuthService) at src/auth/auth.service.ts:134 ``` -------------------------------- ### Scan Broken Links in Next.js Source: https://context7.com/navibyte-innovations-pvt-ltd/pruny/llms.txt Utilize `scanBrokenLinks` to validate internal navigation links within your Next.js application. It checks references from ``, `router.push()`, `redirect()`, `href:`, ``, `revalidatePath()`, and `pathname ===` against the route map. Requires a configuration object. ```typescript import { scanBrokenLinks } from 'pruny/dist/scanner.js'; import { loadConfig } from 'pruny/dist/config.js'; const config = loadConfig({ dir: './apps/web' }); const result = await scanBrokenLinks(config); // { total: 3, scanned: 87, links: [...] } console.log(`Scanned ${result.scanned} unique link paths, found ${result.total} broken`); for (const link of result.links) { console.log(`Broken: ${link.path}`); link.references.forEach(ref => console.log(` → ${ref}`)); } // Broken: /user-profile // → src/components/Navbar.tsx:42 // → src/app/dashboard/page.tsx:18 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.