dead-deps-gauge

Gauge · package quality

dead-deps-gauge

Find dependencies you declare but never use, and imports that are missing from package.json.

npm i -D @mrlouiswright/dead-deps-gauge

Published to GitHub Packages: add @mrlouiswright:registry=https://npm.pkg.github.com to .npmrc first (installing needs a token with read:packages).

What it checks

  • Import extractionwithout a parser: import/export … from, import type, side-effect imports, require, require.resolve, dynamic import(), TypeScript import x = require(), jest.mock/vi.mock, and /// <reference types> headers…
  • More than importsbinaries run from package.json scripts (resolved through each dependency's bin, or a table of well-known tools), ESLint/Babel/Prettier/Jest/commitlint/stylelint/TypeScript config files and their short plugin names…
  • Production vs developmenttests, fixtures, scripts, examples, stories and *.config.* files are dev-only. If package.json has "files", anything that isn't published is dev-only too. install/postinstall scripts of published packages count as production.
  • Monoreposnested packages are skipped. A workspace root's devDependencies satisfy dev imports inside packages, but production imports must still be declared locally, which catches "works only because it's hoisted" bugs.
  • Outputtext, JSON, SARIF 2.1.0 and Markdown; --fail-on; exit codes 0/1/2; allowlist entries with expiry dates.

Quick usage

CLI

npx dead-deps-gauge                              # scan the current package
npx dead-deps-gauge packages/api --fail-on medium
npx dead-deps-gauge --ignore "generated/**" --ignore-deps "@company/runtime-*"
npx dead-deps-gauge -f json > deps-report.json

API

import { check, extractImports, packageName } from 'dead-deps-gauge';
const report = check('.', { ignoreDeps: ['reflect-metadata'] });
extractImports("import x from 'lodash/fp'"); // [{ spec: 'lodash/fp', line: 1, typeOnly: false }]
packageName('lodash/fp');                    // 'lodash'

Every option is documented in the dead-deps-gauge docs.

CI / GitHub Action

permissions:
  contents: read
  security-events: write   # only needed for the SARIF upload
jobs:
  dead-deps-gauge:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with: { persist-credentials: false }
      - uses: MrLouisWright/dead-deps-gauge@v1
        with:
          fail-on: high
          sarif: dead-deps-gauge.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: dead-deps-gauge.sarif }