Update published npm packages using np

Trevor Miller
InstructorTrevor Miller

Share this video with your friends

Send Tweet
Published 5 years ago
Updated 3 years ago

When we want to update our package we need to do a few things: pull latest from our git remote, bump the npm version and git tag, push to our remote, push tags to our remote, and then run npm publish. Phew, that’s a lot. In this lesson, we will set up a release script using the np package to simplify this process.

[00:00] Let's open up our package.json in our code editor. Let's create a new script. Let's call this the release script. Let's have it run the np package. Let's save and close this file, and let's install the np package, npm-install np. We'll save that to our development dependencies.

[00:21] Let's make a small change to our package. I'm going to go inside of my test. Let's change everywhere there is three asterisks to be four asterisks. We'll save that. Let's do the same thing in our source file.

[00:37] Let's go back to our terminal and run nmp-run release. It says, "Select semver-increment or specify new version." Let's make this a minor update. It says this is going to bump it from 1.0to 1.1. Is that good?

[00:53] Let's say, "Yes." It failed and said that we have a unclean working directory. It says that we need to commit or stash our changes first. I'm going to stage and commit my changes. Now, we can run nmp-run release again.

[01:09] Again, it says some minor increment. Yes. Now, it's running through the different checks to make sure everything's good to go. It will also run our tests, and bump our versions, and then publish and push the latest.

[01:21] Everything we've needed to do to update our package has been done, and our new package version has been published. Our Git repo now shows a new tag for our new version, and our npm page for the package now has the latest version, as well.

Yuri Bett
Yuri Bett
~ 4 years ago

Great course! An fast all in one course :) Very useful

Bolaji Ayodeji
Bolaji Ayodeji
~ 3 years ago

I followed this till the end, but my package is still not published after running npm publish Any tips?

Bolaji Ayodeji
Bolaji Ayodeji
~ 3 years ago

I followed this till the end, but my package is still not published after running npm publish Any tips?

Bolaji Ayodeji
Bolaji Ayodeji
~ 3 years ago

I followed this till the end, but my package is still not published after running npm publish Any tips?