{"id":15382900,"url":"https://github.com/reggi/lerna-tutorial","last_synced_at":"2025-04-09T17:22:13.116Z","repository":{"id":129211359,"uuid":"61592509","full_name":"reggi/lerna-tutorial","owner":"reggi","description":":dragon: A basic description of how to use Lerna","archived":false,"fork":false,"pushed_at":"2019-03-12T20:23:39.000Z","size":13,"stargazers_count":291,"open_issues_count":2,"forks_count":41,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T11:50:05.282Z","etag":null,"topics":["lerna","monorepos","tutorial"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reggi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-21T01:29:53.000Z","updated_at":"2025-04-01T05:37:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c2a86a9-39dd-407d-bf85-9eee15006ef2","html_url":"https://github.com/reggi/lerna-tutorial","commit_stats":{"total_commits":9,"total_committers":6,"mean_commits":1.5,"dds":0.6666666666666667,"last_synced_commit":"cbb201fccdbd04d53c1d8b2fbba19ac57a105306"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reggi%2Flerna-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reggi%2Flerna-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reggi%2Flerna-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reggi%2Flerna-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reggi","download_url":"https://codeload.github.com/reggi/lerna-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075182,"owners_count":21043538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lerna","monorepos","tutorial"],"created_at":"2024-10-01T14:34:38.718Z","updated_at":"2025-04-09T17:22:13.085Z","avatar_url":"https://github.com/reggi.png","language":"JavaScript","readme":"# Lerna tutorial\n\n## TLDR;\n\n* `npm install` (installs lerna)\n* `lerna bootstrap` (connects all the packages)\n* `npm -C ./packages/usage run start` (console logs \"alpha\" and \"beta\" from combind use example module)\n\n* Tree Structure\n\n* `packages`\n  * `alpha` (`deps: []`)\n  * `beta` (`deps: []`)\n  * `usage` (`deps: [\"alpha\", \"beta\"]`)\n\n## Summary\n\nFirst off, What is [`lerna`](https://github.com/lerna/lerna)? [`lerna`](https://github.com/lerna/lerna) is a tool that allows you to maintain multiple `npm` packages within one repository.\n\nThere's a couple of benefits to this kind of approach, the paradigm is called a `monorepo`, and more can be read about it from the [source of `babel`, and `react`](https://github.com/babel/babel/blob/master/doc/design/monorepo.md).\n\nHere's the gist:\n\n* Single lint, build, test and release process.\n* Easy to coordinate changes across modules.\n* Single place to report issues.\n* Easier to setup a development environment.\n* Tests across modules are ran together which finds bugs that touch multiple modules easier.\n\n## Getting started.\n\nFor this demo I'm going to be using `lerna@2.0.0-beta.20`. [`lerna`](https://github.com/lerna/lerna) is a CLI (command line interface) tool. You're going to want to install it with the `--global` (`-g`) flag.\n\n```\nnpm i lerna@2.0.0-beta.20 -g\n```\n\nThen once it's done installing your going to want to run the following\n\n```\nmkdir my-monorepo \u0026\u0026 cd $_ \u0026\u0026 lerna init\n```\n\nThis will do a couple of things.\n\n* Creating packages folder.\n* Updating package.json.\n* Creating lerna.json.\n\nThe `/packages` folder is where all of your packages belong. Let's go about making a new package `alpha`.\n\n```\ncd packages\nmkdir alpha\ncd alpha\nnpm init -y\necho \"module.exports = 'alpha'\" \u003e index.js\n```\n\nLets go through the same steps for another package `beta`.\n\nFirst go up one directory:\n\n```\ncd ..\n```\n\nNow go about creating `beta`.\n\n```\nmkdir beta\ncd beta\nnpm init -y\necho \"module.exports = 'beta'\" \u003e index.js\n```\n\nNow we're going to create a `usage` package that uses both `alpha` and `beta` as dependencies.\n\nFirst go up one directory:\n\n```\ncd ..\n```\n\nNow go about creating `\\usage`.\n\n```\nmkdir usage\ncd usage\nnpm init -y\ntouch index.js\n```\n\nOpen up `/packages/usage/index.js` in a text editor and paste this in.\n\n```js\nvar alpha = require('alpha')\nvar beta = require('beta')\nconsole.log(alpha + \" \" + beta)\n```\n\nWe're almost there. At this point your whole project should look something like this:\n\n```\n.\n├── README.md\n├── lerna.json\n├── package.json\n└── packages\n    ├── alpha\n    │   ├── index.js\n    │   └── package.json\n    ├── beta\n    │   ├── index.js\n    │   └── package.json\n    └── usage\n        ├── index.js\n        └── package.json\n```\n\nWhat you want to do now is go into `/packages/usage/package.json` and add these lines under `dependencies`.\n\n```json\n{\n  \"dependencies\": {\n    \"alpha\": \"1.0.0\",\n    \"beta\": \"1.0.0\"  \n  }\n}\n```\n\nNow you need to wire everything up with this command.\n\n```\nlerna bootstrap\n```\n\nThe output from this command should look something like this:\n\n```\nLerna v2.0.0-beta.20\nLinking all dependencies\nSuccessfully bootstrapped 3 packages.\n```\n\nNow using the `tree` command once more (`brew install tree`) we can see the folder structure we can see what [`lerna`](https://github.com/lerna/lerna) did.\n\n```\n.\n├── README.md\n├── lerna.json\n├── package.json\n└── packages\n    ├── alpha\n    │   ├── index.js\n    │   ├── node_modules\n    │   └── package.json\n    ├── beta\n    │   ├── index.js\n    │   ├── node_modules\n    │   └── package.json\n    └── usage\n        ├── index.js\n        ├── node_modules\n        │   ├── alpha\n        │   │   ├── index.js\n        │   │   └── package.json\n        │   └── beta\n        │       ├── index.js\n        │       └── package.json\n        └── package.json\n```\n\nIt added two `stubbed` (my term not [`lerna`](https://github.com/lerna/lerna)'s) modules. If you peak inside `/packages/usage/node_modules/alpha/index.js` you can see what I mean.\n\n\u003e contents of `./packages/usage/node_modules/alpha/index.js`\n\n```js\nmodule.exports = require(\"/Users/thomas/Desktop/lerna-tutorial/packages/alpha\");\n```\n\n\u003e Note: This is an absolute path to the module. So if you ever move your lerna project you'll need to rerun `lerna bootstrap`.\n\nAnd voila! When we run `node ./packages/usage/index.js` we get our expected output!\n\n```\nalpha beta\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freggi%2Flerna-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freggi%2Flerna-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freggi%2Flerna-tutorial/lists"}