CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-depcheck

Comprehensive dependency analysis tool for Node.js projects that identifies unused dependencies, missing dependencies, and provides detailed usage analysis.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

cli.mddocs/

CLI Interface

Depcheck provides a comprehensive command-line interface for analyzing project dependencies.

Basic Usage

depcheck [directory] [arguments]

The directory argument is the root directory of your project (where the package.json file is). If unspecified, defaults to current directory.

Command Line Options

interface CLIOptions {
  // Core options
  'ignore-bin-package'?: boolean;  // Default: false
  'skip-missing'?: boolean;        // Default: false
  'json'?: boolean;               // Output as JSON
  'oneline'?: boolean;            // Output as space-separated string
  'quiet'?: boolean;              // Suppress "No issue" messages
  
  // Filtering options
  'ignores'?: string;             // Comma-separated package names/globs
  'ignore-dirs'?: string;         // DEPRECATED: use ignore-patterns
  'ignore-path'?: string;         // Path to ignore file
  'ignore-patterns'?: string;     // Comma-separated ignore patterns
  
  // Advanced options
  'parsers'?: string;             // Custom parser configuration
  'detectors'?: string;           // Custom detector configuration  
  'specials'?: string;            // Custom special parser configuration
  'config'?: string;              // Configuration file path
  
  // Help
  'help'?: boolean;               // Show help message
}

Examples

Basic Analysis

# Analyze current directory
npx depcheck

# Analyze specific directory
npx depcheck /path/to/project

Output Formats

# JSON output
depcheck --json

# One-line output (space-separated)
depcheck --oneline

# Quiet mode (no "No issue" message)
depcheck --quiet

Filtering Options

# Ignore specific packages
depcheck --ignores="eslint,babel-*"

# Use ignore file
depcheck --ignore-path=.depcheckignore

# Ignore patterns (glob syntax)
depcheck --ignore-patterns="dist,coverage,*.log"

# Ignore binary packages
depcheck --ignore-bin-package=true

Advanced Configuration

# Skip missing dependency detection
depcheck --skip-missing=true

# Use custom configuration file
depcheck --config=.depcheckrc.json

Configuration Files

Depcheck supports configuration files with cosmiconfig. Supported formats:

  • .depcheckrc (YAML/JSON)
  • .depcheckrc.json
  • .depcheckrc.yaml / .depcheckrc.yml
  • .depcheckrc.js
  • depcheck field in package.json

Configuration File Example

{
  "ignores": ["eslint", "babel-*"],
  "skip-missing": true,
  "ignore-patterns": ["dist", "coverage"],
  "parsers": {
    "**/*.js": ["es6", "jsx"],
    "**/*.ts": "typescript"
  },
  "detectors": [
    "importDeclaration",
    "requireCallExpression"
  ],
  "specials": [
    "eslint",
    "webpack"
  ]
}

Exit Codes

// Exit codes
0   // No issues found
-1  // Issues found (unused/missing dependencies)
-1  // Error occurred during analysis

CLI Function Interface

The CLI is also available as a programmatic function:

function cli(
  args: string[],
  log: (message: string) => void,
  error: (message: string) => void,
  exit: (code: number) => void
): Promise<void>;

Parameters:

  • args: Command line arguments array
  • log: Function to handle standard output
  • error: Function to handle error output
  • exit: Function to handle process exit

Output Examples

Human-readable Output

Unused dependencies
* underscore
* lodash

Unused devDependencies  
* mocha
* jest

Missing dependencies
* express: ./src/server.js

JSON Output

{
  "dependencies": ["underscore", "lodash"],
  "devDependencies": ["mocha", "jest"],
  "missing": {
    "express": ["./src/server.js"]
  },
  "using": {
    "react": ["./src/app.js", "./src/components/header.js"]
  },
  "invalidFiles": [],
  "invalidDirs": []
}

One-line Output

underscore lodash mocha jest express

Install with Tessl CLI

npx tessl i tessl/npm-depcheck

docs

cli.md

index.md

parsers.md

specials.md

tile.json