Lerna and Verdaccio

Verdaccio #

Verdaccio is a local npm proxy we can use locally.

yarn add -WD verdaccio
yarn verdaccio

A npm repository is now available at http://localhost:4873/

Now we need to configure our registry creating a .npmrc file, in the root of our respository, with:

registry=http://localhost:4873

We need to create a Verdaccio User to be able to publish packages to our repository. Create it and then do:

yarn login

Before doing the publish we need to configure our git repository and push the master branch. Lerna will be using it to understand changes on packages. We can even execute:

yarn lerna changed

After that, we should now be able to publish our packages with lerna using:

yarn lerna publish

Not sure why, but I needed to setup a git repository and before any publish, lerna forces me to commit any change, which makes sense.

After trying the command I had some problems authenticating in my local registry, lerna was always trying to publish on npm registry.

After a while I tried the following, explicitly configuring my local registry:

yarn lerna publish --yes --registry http://localhost:4873

UPDATE
Updated this command to use from-package, since I want it to check changes locally, and publish artifacts not published yet:
"Similar to the from-git keyword except the list of packages to publish is determined by inspecting each package.json and determining if any package version is not present in the registry. Any versions not present in the registry will be published. This is useful when a previous lerna publish failed to publish all packages to the registry."

yarn lerna publish from-package --yes --registry http://localhost:4873

It worked, and now I have the artifacts on my local verdaccio repository. Another solution, would be Nexus. I have use it in some projects, however it requires more work to set up. I will keep experimenting with Verdaccio.

I have found about the problem with yarn authentication here and here

Also, some work needs to be done to have it working smoothly in Continuos Integration, Delivery and Deployment environment.

I will tackle it later.

Published