GSoC 2020: Easy package management with Lerna
Welcome to another article about the Node Cloud project. In the previous week, I integrated Lerna to the Node Cloud project which helps to manage all Node Cloud plugins in a single repository using the Monorepo architecture. Monorepo is a software development strategy where the code base of many projects is stored in the same repository. Where in this case Node Cloud core, class generation tool, and all the Node Cloud plugins are stored in a single GitHub repository.
Lerna can be used with yarn or npm client. Since yarn provides workspaces it’s always better to use Lerna with yarn as workspaces are great to manage monorepos. The below diagram shows the new project structure of Node Cloud. The class generator, Node Cloud common module(Node Cloud core) and all the Node Cloud plugins have its own yarn workspace. Each workspace has its own package.json.
The Node Cloud common module and all the Node Cloud plugins are Lerna managed packages. These are located in a directory called packages, which is the default setting in Lerna. With the new project structure, all the plugin names are renamed with the prefix “@nodecloud”.
So those are the main changes in the project structure but now you might be wondering what’s the advantage here or does it really worth doing this change. In simple terms, yes it’s really easy to manage code, run unit tests and publish packages with Lerna in a project like Node Cloud where it has multiple plugins. I will give some examples of scenarios where Lerna does an amazing job.
- When adding or linking a dependency to a package the Lerna add command is very useful. It installs or links the dependency in the root node_modules directory where there won’t be a node_modules directory for each Lerna managed package. The scope can be set to the relevant packages that require the dependency and the package.json of those packages will be updated with the relevant dependency name and the version.
lerna add aws-sdk --scope=@nodecloud/aws-plugin
- Each Node Cloud plugin has its own testing command and a unique way of how testings have been written. But with the help of Lerna run command, we can execute all the unit tests at once and get the output of those separately. which makes executing scripts easy and efficient.
lerna run test
That’s all about Lerna and the new project structure of Node Cloud. I am currently implementing a transformer which will be used to generate JavaScript classes in the Node Cloud GCP plugin and completing the code generation process of the GCP plugin is the main goal of this week.
So that’s pretty much it for this article. Keep in touch for more updates about the Node Cloud project.
Goodbye :) …