Published all packages to an npm registry with a single command.įor more on Lerna, including their solution to the duplication problem (hoisting), I recommend their excellent docs at.Bumped the version of all packages and committed to git with a single command.Added three new scoped packages to our monorepo.If this command succeeded, you’ve successfully published all packages in your first monorepo to npm. Lerna lets us do this with a single command. The last step is to publish these packages to npm. This command not only bumps every package to 1.0.0, but also pushes the version update to git for you. ![]() Now we can bump the version of all packages with one command. $ git commit -m “Initial commit” $ git remote add origin $ git push -u origin master Before we can increment the version, we need to commit what we’ve got so far and create a remote for git: $ lerna create $ lerna create $ lerna create you chose the default settings for each package, you’ll now have three packages (a, b, c) in the test scope with version 0.0.0. We now add a few scoped packages to our monorepo. If your packages won’t have a scope, you can omit the –scope flag. Next, we authenticate to the registry with a user that has publish permissions. If you’re publishing somewhere other than the public npm registry (for example, npm Enterprise), you’ll first need to set your registry. Before we add them, we should login to our registry so lerna sets the publishConfig correctly on each new package. However, there aren’t any packages in our monorepo yet. $ cat lerna.json Īs seen above, the version for all of the packages in our monorepo is 0.0.0. If you look at the contents of lerna.json, you can see where the version and packages are defined. $ mkdir monorepo_example $ cd monorepo_example $ lerna init Next, we need to create new lerna repository: Since lerna works with npm, let’s take a look at how it implements monorepos. So how do monorepos work with npm? The two most popular solutions are Yarn workspaces and lerna. But if this is acceptable, monorepos can give you all the benefits of modularization with very straightforward source code management. ![]() Obviously, you have to be okay with granting access to all of the code or none of the code. Discovery, access control, and versioning are all simpler by virtue of everything being in the same place. This “monorepo” is then the only thing a developer needs in order to do development with your application. Instead of one code repository per module, you put all modules in the same code repository. Monorepos are a popular solution to this problem. This encourages reuse but also means that some packages are likely duplicated in every package you develop. Some ecosystems, npm in particular, are highly modular.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |