pkg-field-gauge

Gauge · package quality

pkg-field-gauge

Validate package.json before you publish: exports/main/types consistency, files, repository, keywords and sideEffects.

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

  • Entry pointsmain (resolved like Node: +.js, /index.js), module, browser, types/typings, every bin (plus a #! shebang check) and every exports target, including subpath patterns (./utils/*), conditions and fallback arrays.
  • exports rulestargets must start with ./ and stay inside the package; subpaths and conditions can't be mixed; types must come first and default last…
  • filesevery entry point must be published (npm always includes package.json, README, LICENSE, main and bin), and entries that match nothing are reported.
  • Metadatanpm name rules, SemVer version, field types, type value, description, keywords, SPDX license, repository format and agreement with git remote origin, homepage/bugs, deprecated fields (preferGlobal, typings, licenses…)…
  • Outputtext, JSON, SARIF 2.1.0 and Markdown, with package.json line numbers; --fail-on; exit codes 0/1/2; allowlist entries with expiry dates.

Quick usage

CLI

npx pkg-field-gauge                         # check ./package.json (run after your build)
npx pkg-field-gauge packages/core --fail-on medium
npx pkg-field-gauge --require funding,author

API

import { check, validName, validLicense } from 'pkg-field-gauge';
const report = check('.');
validName('My-Package'); // ['contains uppercase letters']
validLicense('(MIT OR Apache-2.0)'); // true

Every option is documented in the pkg-field-gauge docs.

CI / GitHub Action

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