monorepo-gauge

Gauge · package quality

monorepo-gauge

Hygiene checks for npm, yarn and pnpm workspaces: circular internal deps, mismatched shared deps, version drift and missing fields.

npm i -D @mrlouiswright/monorepo-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

  • Workspace discoverypackage.json workspaces (array or { packages }), pnpm-workspace.yaml and lerna.json, with *, ` and !exclusions. The package manager is detected from the lockfile, .yarnrc.yml and packageManager`.
  • Internal graphcycles through dependencies/peerDependencies/optionalDependencies (high) and through devDependencies (low), each reported once as a → b → c → a…
  • Shared dependency driftthe same external dependency with different majors (medium) or different ranges in the same major (low) across packages and the root, listing who uses what.
  • Package fields, delegated to pkg-field-gaugeevery workspace runs through pkg-field-gauge's checkPackage (entry points, exports, types, bin, files, licence, repository, description…
  • workspace: protocolmixed workspace:^ / workspace:~ / workspace:* / workspace:<range> styles are flagged (workspace-protocol-inconsistent, majority wins or set workspaceProtocolStyle), and workspace: under npm or yarn classic…
  • Version groups (syncpack-style)versionGroups assign dependencies × packages to a policy: pin (exact pinVersion), sameRange, banned or ignored. Unmatched dependencies use the default "highest range wins" drift check.
  • --fixrewrites package.json files in place (keeping indentation): internal ranges, workspace: protocol and style, fixed-mode versions, same-major range drift, pin groups and repository.directory…
  • Outputtext, JSON, SARIF 2.1.0 and Markdown; --fail-on; exit codes 0/1/2; allowlist entries with expiry dates.

Quick usage

CLI

npx monorepo-gauge                       # run at the monorepo root
npx monorepo-gauge --fail-on medium
npx monorepo-gauge --versioning fixed    # all publishable packages share one version
npx monorepo-gauge --ignore-packages "playground-*,examples/**"

API

import { check, applyFixes, satisfies, findCycles } from 'monorepo-gauge';
const report = check('.', { versioning: 'fixed' });
check('.', { fix: true, fixDryRun: true }).fixed; // [{ rule, file, path, from, to }]
for (const p of report.info.packages) console.log(p.name, p.internalDeps);
satisfies('2.0.0', '^1.0.0'); // false

Every option is documented in the monorepo-gauge docs.

CI / GitHub Action

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