npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

npm-multi-publish

v2.2.0

Published

Publish an npm package to multiple registries

Downloads

106

Readme

npm-multi-publish Latest version Monthly downloads Install size

Publish an npm package to multiple registries

Features

  • 🙌 Streamlined Publishes to all registries in one npm publish!
  • 🔥 High compatibility Works with anything that uses npm publish (eg. monorepo)!
  • ⚡️ Easy setup Just add it to your npm publish hooks!
  • 🛡 VPN conscious Waits for you to switch VPNs if registry is unreachable!

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

🚀 Install

npm i -D npm-multi-publish

🚦 Quick Setup

  1. Open package.json
  2. Add npm-multi-publish to the prepublishOnly and postpublish hooks
  3. Convert publishConfig into an array of configs
  {
      ...,

      "scripts": {
+         "prepublishOnly": "npm-multi-publish",
+         "postpublish": "npm-multi-publish"
      },

      "publishConfig": [
+         {
+             "registry": "Registry URL 1"
+         },
+         {
+             "registry": "Registry URL 2"
+         },
+         ...
      ],

      ...
  }

If using Lerna, add this configuration to the respective package.json of each package in the monorepo (not necessary in the root package.json).

That's it! Next time you run npm publish or yarn publish it will automatically publish to all registries configured in your package.json publishConfig array.

If the registries require authentication, make sure you authenticate with them all using a single .npmrc file (toggling via npmrc will not work).

💁‍♀️ FAQ

Is it possible to authenticate to multiple npm registries with one .npmrc file?

Yes. This is actually the preferred way because npm publish loads the .npmrc file at the beginning, so toggling .npmrc files via npmrc during publish (even in npm-multi-publish) does not take effect.

To login to an enterprise/custom registry:

$ npm login --registry=https://registry.company-name.npme.io

To verify authentication on a specific registry:

$ npm whoami --registry=https://registry.company-name.npme.io

A .npmrc file authenticated with multiple registries should include something like this:

//registry-a-url/:_authToken=... # Registry A authentication token
//registry-b-url/:_authToken=... # Registry B authentication token

If you have certs for the respective registries, you can add multiple certs to your .npmrc file.

How can I test publishing to a registry?

Use verdaccio to create a local mock npm registry.

Install and start the verdaccio server:

$ npm i -g verdaccio
$ verdaccio # Start server

In a separate terminal window, configure npm to use your verdaccio server. I recommend using npmrc to create a new npmrc for the "verdaccio" profile so your default npmrc isn't polluted and so you can switch to it easily in the future:

$ npmrc -c verdaccio # (Optional) Create a new .npmrc not to pollute existing ones
$ npm set registry http://localhost:4873 # Set default registry
$ npm adduser --registry http://localhost:4873 # Login to registry

Now you can test publishing.

After your package is test-published to verdaccio, you can confirm the contents via their Web UI at http://localhost:4873 (or any other port it's listening on).