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

Depcheck

Depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are missing from package.json.

Package Information

  • Name: depcheck
  • Type: Node.js dependency analysis tool
  • Language: JavaScript/TypeScript
  • Package Manager: npm
  • Installation: npm install -g depcheck or npm install depcheck

Core Imports

ESM (ES modules):

import depcheck from 'depcheck';

CommonJS:

const depcheck = require('depcheck');

Basic Usage

import depcheck from 'depcheck';

const options = {
  ignoreBinPackage: false,
  skipMissing: false,
  ignorePatterns: ['dist', 'coverage']
};

depcheck('/path/to/project', options).then((unused) => {
  console.log(unused.dependencies);    // unused dependencies
  console.log(unused.devDependencies); // unused devDependencies  
  console.log(unused.missing);         // missing dependencies
});

Architecture

Depcheck uses a modular architecture with three main components:

  • Parsers: Extract dependencies from different file types (JS, TS, Vue, etc.)
  • Detectors: Find dependency usage patterns (import, require, etc.)
  • Specials: Handle framework-specific configurations (ESLint, Webpack, etc.)

Main Analysis Function

function depcheck(
  rootDir: string,
  options: DepcheckOptions,
  callback?: (result: DepcheckResults) => void
): Promise<DepcheckResults>;

The primary function analyzes a project directory and returns dependency usage information.

Parameters:

  • rootDir: Path to the project root directory (where package.json is located)
  • options: Configuration options for the analysis
  • callback: Optional callback function (if omitted, returns a Promise)

Returns: Promise resolving to DepcheckResults object with:

  • dependencies: Array of unused dependencies
  • devDependencies: Array of unused devDependencies
  • missing: Object mapping missing dependencies to files that use them
  • using: Object mapping dependencies to files that use them
  • invalidFiles: Array of files that couldn't be parsed
  • invalidDirs: Array of directories that couldn't be accessed

Configuration Options

interface DepcheckOptions {
  ignoreBinPackage?: boolean;
  skipMissing?: boolean;
  ignorePatterns?: string[];
  ignoreDirs?: string[];
  ignoreMatches?: string[];
  ignorePath?: string;
  parsers?: { [pattern: string]: Parser | Parser[] };
  detectors?: Detector[];
  specials?: Special[];
  package?: PackageJson;
}

Extensible Components

Depcheck provides access to its internal parsers, detectors, and special handlers:

// Available parsers for different file types
depcheck.parser: {
  coffee: Parser;
  es6: Parser;
  es7: Parser;
  graphql: Parser;
  jsx: Parser;
  sass: Parser;
  storybook: Parser;
  tsconfig: Parser;
  typescript: Parser;
  vue: Parser;
  svelte: Parser;
}

// Available detectors for finding dependencies
depcheck.detector: {
  exportDeclaration: Detector;
  expressViewEngine: Detector;
  gruntLoadTaskCallExpression: Detector;
  importCallExpression: Detector;
  importDeclaration: Detector;
  requireCallExpression: Detector;
  requireResolveCallExpression: Detector;
  typescriptImportEqualsDeclaration: Detector;
}

// Special parsers for framework configurations
depcheck.special: {
  babel: Special;
  bin: Special;
  commitizen: Special;
  eslint: Special;
  'feross-standard': Special;
  gatsby: Special;
  'gulp-load-plugins': Special;
  husky: Special;
  istanbul: Special;
  jest: Special;
  karma: Special;
  'lint-staged': Special;
  mocha: Special;
  prettier: Special;
  react17: Special;
  serverless: Special;
  tslint: Special;
  ttypescript: Special;
  webpack: Special;
}

Type Definitions

interface DepcheckResults {
  dependencies: string[];
  devDependencies: string[];
  missing: { [dependency: string]: string[] };
  using: { [dependency: string]: string[] };
  invalidFiles: string[];
  invalidDirs: string[];
}

interface PackageJson {
  dependencies?: { [name: string]: string };
  devDependencies?: { [name: string]: string };
  peerDependencies?: { [name: string]: string };
  optionalDependencies?: { [name: string]: string };
  imports?: { [key: string]: any };
}

type Parser = (content: string, filePath: string, deps: string[], rootDir: string) => string[];
type Detector = (node: any, deps: string[]) => string[];  
type Special = (filePath: string, deps: string[], rootDir: string) => Promise<string[]>;

Command Line Interface

For CLI usage patterns and options, see CLI Interface.

Parser Configuration

For detailed parser configuration and custom parser setup, see Parsers.

Special Configuration Handlers

For framework-specific configuration parsing (ESLint, Webpack, etc.), see Special Handlers.

Install with Tessl CLI

npx tessl i tessl/npm-depcheck
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/depcheck@1.4.x
Publish Source
CLI
Badge
tessl/npm-depcheck badge