JavaScript and TypeScript Monorepos

Publishing with Verdaccio

JavaScript and TypeScript Monorepos

Check out a free preview of the full JavaScript and TypeScript Monorepos course

The "Publishing with Verdaccio" Lesson is part of the full, JavaScript and TypeScript Monorepos course featured in this preview video. Here's what you'd learn in this lesson:

Mike introduces Verdaccio, a local npm proxy, explains that it allows developers to track internal package changes and publish internal package changes easily without having to keep track of each individual dependency version.

Preview
Close

Transcript from the "Publishing with Verdaccio" Lesson

[00:00:00]
>> So normally, publishing packages would be a really annoying thing for us to do in the workshop. Because to really experience publishing, you have to pollute NPM. You have to actually send packages into NPM. Don't want to have us do that. And in particular, as you're playing around with this and as you're learning this, I want you to feel like you have a thing that you can make messy and then throw it away.

[00:00:29]
We're going to use something called for Dotto, which is a local NPM proxy. Here's how it works. You're gonna go and all I did here is I opened up a second shell because I want my Verdaccio kind of running in the background here. So I did, you can do like volta install Verdaccio, I already have the latest version installed.

[00:01:00]
And then here's how you started. Just run through dacha So What we have now is A local packaging industry. So you can see this is this is mine. This is like the web UI. So I just went to localhost 4873. Right, which is just the same thing that it originally told me right after it started up.

[00:01:35]
Yet right here 4873 and you can see that there's some stuff in here already. Now so this it knows how to talk like NPM talks. Your your ci tools will think that this is NPM we just have to do one little thing real quick. And that is in our project.

[00:01:58]
I think I left a file here for us. I did not because it's so trivial So all we need to do is create an NPMRC file which will tell yarn and learner To use this as our registry. That's it. That's all you have to do. Now when you run yarn install, it's going to look at prodotto instead of NPM.

[00:02:30]
And by the way, for dacha if it doesn't have something cached and sort of local overrides, it'll just go ask NPM for you, This is also great. By the way, if you're, if you're attending a workshop at a conference, or if you, you have to do some work in a place where like the connectivity is bad.

[00:02:52]
This can be like a cache of your NPM packages that work offline since it's all running off localhost. If there's an internet connection, it'll get stuff, you know, get the latest things. Otherwise you can use what you have songs, it's recent enough that it satisfies the version constraints.So I'm gonna leave this running in the background.

[00:03:13]
And in fact, I already have some junk in there. I want to clean it out. So we're all looking at the same thing and we have a clean slate. On Mac OS, it would be like this rm rf Local share production, just blow it away. Let's see, I might have to restart it.

[00:03:32]
I didn't even have to restart it. Now we're back in the brand new state. So all I had to do was that just blew away my packages. So let's try publishing some stuff now. Because I can do this and you can too. Even though we're all using the same package name, I'm publishing just to another thing on my laptop.

[00:03:52]
So we're not gonna collide in terms of names and versions. So I'll say that this is, I'm just gonna make a comment. This is a making a fix to the types package and we'll say reductio. All right now I'm going to say learner publish. Conventional ,commits. Enter. It says there are no changes to publish, interesting.

[00:04:39]
Let me see if there's anything here. This first step is a little bit hard here. Learn is very good once we have a version that already exists cuz some of how it determines that the bump to the version number is it looks at the last release and compares to the code you have now.

[00:05:00]
There is no last release at this time. So I think I just need to publish each package manually. Which is simple as this learner exact, by the way, isn't it good that we have like this local thing now, we can just try this. If it doesn't work, we just float away.

[00:05:16]
Nothing's in NPM everything's depletable right? learner exec, actually learner, run, publish No, it's gonna be learning exact yarn publish. Because while it is like yarn build, it's not an NPM script is a yarn sub command. And I'm going to wrap quotes around this just so that It is clear whose argument is passed to who.

[00:05:58]
I'm just keeping the same version numbers. And let's see what we've got. There we go. Publish two versions A app has no idea that this did not end up on NPM. And if I look I've got this fix here. So let's make a change. I'm just gonna go to really want this to work.

[00:06:24]
I think it will. Go to this type card. You know what we can do here. There is a legit improvement I can make here. Okay here. So this is meant to check to see if an array of items, they're all of the same type. So I filter out Any mismatches, I get all mismatches.

[00:06:49]
And then I check to see if there are greater than 0 mismatches. This is not ideal from a performance standpoint because as soon as I find the first violator, I know that I'm going to return false. I do not need to check every single item in this array.

[00:07:07]
So, I can just use some array.some, If some of the items fail to check return false, otherwise, return true. So in theory, I've just sped this up, made it a little bit faster. And I wanna make one more change here. In my learner, I want to get change this version from 1 0 0 to independent.

[00:07:54]
Right to that there's a reason we've been like, regardless of what we touched, it's always a new release of everything, everything, everything. Independent allows us To just say, look, only types changed. So types will get released and anything that depends on types because it needs a bump. It may get released.

[00:08:17]
And I'll call this a chore. We'll see if it's happy with no scope here. Called independent versioning seems happy with it. All right, now let's learn a command for changed. Let's see what this looks like. Lerna changed 2 packages ready to publish. There's one explanation here. Yep, two packages.

[00:09:00]
Types got bumped utili depends on types. It gets pumped too

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now