question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Workflow for test-publishing to a local registry, e.g. Verdaccio

See original GitHub issue

As discussed on https://github.com/lerna/lerna/issues/805 there’s no Lerna “unpublish” command or general support for overwriting an existing published version because lerna publish is intended for best-practice publication to a public registry like NPM.

I’m wondering what would be a good approach for test-publishing to a local registry, such as Verdaccio running on http://localhost:4873, where you might want to repeatedly publish locally to the same version number, until the published version works as intended and you are ready to publish a real new version to the public repository.

Is there an intended approach for this? There are lots of good pointers on using things like from-git and from-package with CI but I can’t see anything clean for this case.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
evertonfragacommented, Sep 8, 2020

lerna publish was meant to do a lot. And that’s OK. Personally, I think it’s an unnecessary risk having to add several flags to suppress “production” behaviors (I could end up publishing git tags to remote unknowingly).

I’d rather play on the safe side, using lerna exec "npm publish …"

It executes commands in a bottom-up way, so leaf packages are executed first, which is perfect for my use case. Below is a pretty much generic solution, that publishes all packages to Verdaccio, then unpublishes them. You can use additional heuristics for version numbers and all.

@gaurav5430 so you can simply run:

# publish
lerna exec "npm publish --registry http://localhost:4873"

# unpublish
lerna exec "npm unpublish \$LERNA_PACKAGE_NAME --registry http://localhost:4873"
1reaction
AlanSlcommented, Nov 25, 2019

Currently I’m experimenting with something like this, which seems to work reasonably well for my case (several prepublish and postpublish scripts, plus a create-* package intended to be used from the registry with npm init or yarn create). I’ve also seen similar scripts to my local-unpublish-all in the wild:

{
  ...
  "scripts": {
    "local-publish": "lerna publish --no-git-tag-version --no-push --registry=\"http://localhost:4873/\"",
    "local-unpublish": "lerna exec -- npm unpublish --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}@\\$(npm view \\$LERNA_PACKAGE_NAME version)\"",
    "local-unpublish-all": "lerna exec -- npm unpublish -f --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}\"",
    ...
  },
  ...
}

local-publish puts all packages on the local registry without changing tags (bumps versions by default but that can be undone with a hard git reset), and local-unpublish removes the latest version of each package from the local registry. local-unpublish-all nukes all the packages on the local registry in case something went wrong.

So the usual workflow to test that everything in a branch works correctly when published and pulled from a registry is:

  • npm run local-unpublish, unless there’s nothing on the local registry (e.g. if this is the first time this has been done or local-unpublish-all has been done to start again after something went wrong)
  • npm run local-publish, optionally passing a version number if all packages are intended to be locally published to the same version, e.g. npm run local-publish 0.0.1
  • Test that everything works and is bundled as expected when pulled from the registry; repeat if it doesn’t.

Is there anything existing or in the roadmap that fits this kind of local testing better than the above?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using a private registry
Setting up a private registry is quite easy on all major Package managers and can be achieved in a few different ways depenging...
Read more >
How to test publishing your JavaScript package locally
There are a couple of options to perform this workflow, but in this article, I'm gonna show you how to do that using...
Read more >
Testing Packages Locally Using Lerna & Verdaccio
Verdaccio is a proxy registry. That means when configured it intercepts requests to NPM, and serves packages you've published to it locally.
Read more >
Five use cases where a npm private proxy fits in your ...
I recognize that having a local registry is pretty handy. ... Verdaccio is ready for Docker and even there is a example repository...
Read more >
Local npm repository - MilanoIngegneria
Verdaccio comes out of the box with its own tiny database, and the ability to proxy other registries (eg. Select your CodeArtifact repository...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found