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-gaugePublished 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 points
main(resolved like Node:+.js,/index.js),module,browser,types/typings, everybin(plus a#!shebang check) and everyexportstarget, including subpath patterns (./utils/*), conditions and fallback arrays. exportsrulestargets must start with./and stay inside the package; subpaths and conditions can't be mixed;typesmust come first anddefaultlast…filesevery entry point must be published (npm always includespackage.json, README, LICENSE,mainandbin), and entries that match nothing are reported.- Metadatanpm name rules, SemVer version, field types,
typevalue, description, keywords, SPDX license, repository format and agreement withgit remote origin, homepage/bugs, deprecated fields (preferGlobal,typings,licenses…)… - Outputtext, JSON, SARIF 2.1.0 and Markdown, with
package.jsonline 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 }