How to Publish an npm Package
Publish a Node.js package to your organization’s npm registry using the npm publish command.
Prerequisites
- An organization on pckgs.io with an npm registry. See Create an Organization.
- A pckgs.io access token with write access to your organization. See Create an Access Token.
- Authentication configured. See npm Package Registry Authentication.
Configure package.json
Your package name must be scoped, an unscoped name is rejected by the registry. Point publishConfig.registry at your organization’s registry so the package can never be published to
the wrong place by accident:
{ "name": "@<YOUR_SCOPE>/my-package", "version": "1.0.0", "publishConfig": { "registry": "https://npm.pckgs.io/<YOUR_ORG_SLUG>/" }}Without publishConfig, npm publishes scoped packages to whatever registry the scope is mapped to
in your .npmrc.
Publish the Package
Run the following command from your package root:
npm publishnpm packs your files into a tarball, uploads it to pckgs.io using your stored access token.
Visibility
Scoped packages default to --access restricted which uploads the package as private. If you want
to upload a public package you can use --access public with your npm publish command as
npm publish --access publicOnce package is uploaded to pckgs.io you can manage it’s visibility from package’s settings page as long as you have manage permission for that specific package.
Preview Before Publishing
To see exactly which files would be included without uploading anything:
npm publish --dry-runPublishing a New Version
A version that already exists cannot be overwritten. Bump it first:
npm version patchnpm publishPublishing from CI
Write the scope mapping and token into .npmrc at the start of the job, then publish:
echo "@<YOUR_SCOPE>:registry=https://npm.pckgs.io/<YOUR_ORG_SLUG>/" >> .npmrcecho "//npm.pckgs.io/<YOUR_ORG_SLUG>/:_authToken=${PCKGS_TOKEN}" >> .npmrcnpm publishStore PCKGS_TOKEN as an encrypted secret in your CI provider never in the repository.
Managing a Published Package
Dist Tags
Publish a prerelease under its own tag, then promote it when it’s ready:
npm publish --tag nextnpm dist-tag add @<YOUR_SCOPE>/my-package@2.0.0 latestnpm dist-tag ls @<YOUR_SCOPE>/my-packageDeprecate a Version
npm deprecate @<YOUR_SCOPE>/my-package@"<2.0.0" "Upgrade to v2 — v1 is no longer maintained"Unpublish
Unpublish via npm unpublish is not supported since in pckgs.io access token can only read or write to a package.
To unpublish a package you go to the package’s setting page and delete the package from there.
Related
- npm Package Registry
- How to Install an npm Package
- npm Package Registry Authentication
- How to Import an npm Package
Need help? Contact us here or at support@pckgs.io.