Publish npm Packages
Build an npm publication process that follows the package's existing conventions. Include only the required parts. Make each part easy to inspect.
Workflow
- Confirm that the repository produces a publishable npm package and identify the exact workspace or package directory.
- Inspect
package.json and the repository's lockfile before you propose changes. Identify the package manager and supported Node.js versions. Inspect exports, included files, repository metadata, release conventions, workflows, and repository instructions.
- Run the repository's normal validation and build commands. Create the exact tarball with
npm pack. Inspect its manifest and contents. Test an isolated installation when the request depends on package contents or type declarations.
- Configure npm Trusted Publishing around the repository's approved release event:
- Use a supported hosted runner and a compatible Node.js and npm pair.
- Grant
id-token: write only to the publishing job.
- Keep ordinary repository permissions read-only.
- Match the npm package, GitHub owner and repository, workflow filename, environment, and allowed publish action exactly.
- Publish the exact validated tarball. Do not rebuild it in the publishing job.
- Use Trusted Publishing's automatic provenance for eligible public packages. Disable it only when the repository documents a specific reason.
- For a first publication, use this bootstrap sequence:
- Determine whether the package name already exists.
- Determine whether npm permits Trusted Publishing configuration before the first publication.
- If the first publication needs authentication, validate the exact tarball.
- Apply the authorization rule in Safety Rules before the first publication.
- For a release to multiple registries, apply the applicable publishing skill to each registry. Derive all package versions from one approved release identity. Complete preflight for every package file before any publisher runs.
- Before publication, validate YAML, package metadata, archive contents, permissions, event semantics, and all manual GitHub and npm settings.
- If one registry accepts the release and another registry fails, preserve the successful immutable release. Retry only the failed publisher. Use the files that preflight preserved for that registry. Use the exact tarball for npm. Use the exact wheel and source distribution for PyPI. Do not rebuild the files. Do not publish the successful version again.
- After an authorized release, verify registry metadata, expected provenance, and a clean installation. Identify each external setting or publication result that you could not verify.
Verify Current Information
Check current primary documentation before you change action references, Node.js matrices, or npm requirements. Also check it before you change Trusted Publishing, provenance, or staged-publishing settings. Check applicable upstream releases. Follow repository pinning or SHA policies when they exist. Otherwise, use supported action references that you verify during the task. Do not state that a fixed reference is current unless you verified it. Record relevant versions or the verification date when they affect the change.
Safety Rules
- Respect the repository's package manager for dependency installation and validation. Use the npm CLI for npm registry operations that require it.
- Do not introduce a long-lived npm publish token unless the user explicitly requires token-based publishing. Keep any token needed to install private dependencies read-only and separate from publication.
- Require explicit authorization to create or push tags, publish a release, configure registry trust, alter repository settings, bootstrap a package, or perform a live upload. Use authorization already given in the conversation when it covers the action. Ask only for actions outside that scope. Do not treat configuration approval as publication approval.
- Treat package names and versions as immutable registry coordinates. Recheck name availability immediately before a first publication. Do not try to overwrite an existing version.
- Inspect lifecycle scripts and the tarball before publication.
npm pack and npm publish can execute package scripts.
- Scope workspace commands to the intended package. Do not assume trust-management commands understand npm workspaces.
- Preserve existing workflow names and release conventions unless changing them is necessary to make the publishing identity correct.
Resources
- Read references/workflow-templates.md when you create or substantially change a GitHub Actions workflow. Also read it when you configure a trusted publisher or handle an initial package bootstrap. Read it when you coordinate npm with another registry. Adapt the patterns after you verify current primary documentation and action references.
Output
Include only applicable sections. Keep the report proportional to the scope and results. Report:
- Existing npm release coverage and gaps.
- Workflow changes and the reason for each permission or event.
- Manual GitHub and npm settings, including whether an initial bootstrap remains.
- Package and tarball validation results. Include anything that you could not verify externally.
- Coordination with each other registry in the release.
- Authorized next steps, clearly separating configuration from live release actions.
1---2name: publish-npm-package3description: Configure or troubleshoot npm package publication with GitHub Actions and npm Trusted Publishing. Use this skill for JavaScript or TypeScript packages. Also use it for the npm package in a mixed-language repository. Do not use it for applications or repositories without an npm package. Do not use it for generic CI, containers, or token publishing unless the user requests token publishing.4---56# Publish npm Packages78Build an npm publication process that follows the package's existing conventions. Include only the required parts. Make each part easy to inspect.910## Workflow11121. Confirm that the repository produces a publishable npm package and identify the exact workspace or package directory.132. Inspect `package.json` and the repository's lockfile before you propose changes. Identify the package manager and supported Node.js versions. Inspect exports, included files, repository metadata, release conventions, workflows, and repository instructions.143. Run the repository's normal validation and build commands. Create the exact tarball with `npm pack`. Inspect its manifest and contents. Test an isolated installation when the request depends on package contents or type declarations.154. Configure npm Trusted Publishing around the repository's approved release event:16 - Use a supported hosted runner and a compatible Node.js and npm pair.17 - Grant `id-token: write` only to the publishing job.18 - Keep ordinary repository permissions read-only.19 - Match the npm package, GitHub owner and repository, workflow filename, environment, and allowed publish action exactly.20 - Publish the exact validated tarball. Do not rebuild it in the publishing job.21 - Use Trusted Publishing's automatic provenance for eligible public packages. Disable it only when the repository documents a specific reason.225. For a first publication, use this bootstrap sequence:23 - Determine whether the package name already exists.24 - Determine whether npm permits Trusted Publishing configuration before the first publication.25 - If the first publication needs authentication, validate the exact tarball.26 - Apply the authorization rule in Safety Rules before the first publication.276. For a release to multiple registries, apply the applicable publishing skill to each registry. Derive all package versions from one approved release identity. Complete preflight for every package file before any publisher runs.287. Before publication, validate YAML, package metadata, archive contents, permissions, event semantics, and all manual GitHub and npm settings.298. If one registry accepts the release and another registry fails, preserve the successful immutable release. Retry only the failed publisher. Use the files that preflight preserved for that registry. Use the exact tarball for npm. Use the exact wheel and source distribution for PyPI. Do not rebuild the files. Do not publish the successful version again.309. After an authorized release, verify registry metadata, expected provenance, and a clean installation. Identify each external setting or publication result that you could not verify.3132## Verify Current Information3334Check current primary documentation before you change action references, Node.js matrices, or npm requirements. Also check it before you change Trusted Publishing, provenance, or staged-publishing settings. Check applicable upstream releases. Follow repository pinning or SHA policies when they exist. Otherwise, use supported action references that you verify during the task. Do not state that a fixed reference is current unless you verified it. Record relevant versions or the verification date when they affect the change.3536## Safety Rules3738- Respect the repository's package manager for dependency installation and validation. Use the npm CLI for npm registry operations that require it.39- Do not introduce a long-lived npm publish token unless the user explicitly requires token-based publishing. Keep any token needed to install private dependencies read-only and separate from publication.40- Require explicit authorization to create or push tags, publish a release, configure registry trust, alter repository settings, bootstrap a package, or perform a live upload. Use authorization already given in the conversation when it covers the action. Ask only for actions outside that scope. Do not treat configuration approval as publication approval.41- Treat package names and versions as immutable registry coordinates. Recheck name availability immediately before a first publication. Do not try to overwrite an existing version.42- Inspect lifecycle scripts and the tarball before publication. `npm pack` and `npm publish` can execute package scripts.43- Scope workspace commands to the intended package. Do not assume trust-management commands understand npm workspaces.44- Preserve existing workflow names and release conventions unless changing them is necessary to make the publishing identity correct.4546## Resources4748- Read [references/workflow-templates.md](references/workflow-templates.md) when you create or substantially change a GitHub Actions workflow. Also read it when you configure a trusted publisher or handle an initial package bootstrap. Read it when you coordinate npm with another registry. Adapt the patterns after you verify current primary documentation and action references.4950## Output5152Include only applicable sections. Keep the report proportional to the scope and results. Report:53541. Existing npm release coverage and gaps.552. Workflow changes and the reason for each permission or event.563. Manual GitHub and npm settings, including whether an initial bootstrap remains.574. Package and tarball validation results. Include anything that you could not verify externally.585. Coordination with each other registry in the release.596. Authorized next steps, clearly separating configuration from live release actions.