npm Publishing Guidelines
Validate publish-readiness and publish packages idempotently, with correct access, provenance, dist-tags, and platform fields.
Core Principles
- npm requires only name + version:
license/repository/filesare house policy, not npm rules, andprivate: trueblocks publishing outright, see references/publish-check.md - Provenance needs CI + OIDC:
--provenanceonly works from a supported runner withid-tokenpermission, the public registry, and a matchingrepository; it errors elsewhere, see references/publish.md - Access is derived: unscoped packages are always public; scoped packages default to restricted and need
--access publicon first publish, see references/publish.md - Platform packages gate install:
os/cpu/libcrestrict where a native-binary package installs; inject and restore those fields safely, see references/publish.md
Operations
- publish-check: validate a package.json is publish-ready, separating npm rules from policy, see references/publish-check.md
- publish: publish a package idempotently with provenance / access / dist-tag / platform handling, see references/publish.md
Gotchas
- Hard-requiring
license/repository/filesexceeds npm (it warns, it doesn't block), and rejecting arepositoryshorthand string likegithub:org/repois wrong: treat the three as policy publishConfig.accessis only meaningful for@scopednames; unscoped packages cannot be restricted: don't hard-require it universally--provenancefails outside a supported CI/OIDC environment: gate it on CI, never expect a local no-opfilessupports globs anddist/is built later: don't existence-check glob entries or build outputs;package.json/README/LICENSE/mainare always included- Inject-then-restore of
os/cpu/libcmust restore on failure (try/finally), andlibcis a silent no-op unlessosincludeslinux - A pre-release published without
--taglands onlatestand installs by default: derive a dist-tag from the version
Progressive Disclosure
- Read references/publish-check.md - Load when validating that a package is ready to publish
- Read references/publish.md - Load when publishing (idempotency, provenance, access, dist-tag, platform fields)