{"id":26738632,"url":"https://github.com/tomfern/semaphore-demo-monorepo-javascript","last_synced_at":"2025-10-18T23:58:58.786Z","repository":{"id":45900582,"uuid":"358007618","full_name":"TomFern/semaphore-demo-monorepo-javascript","owner":"TomFern","description":"Demo project to try out Yarn workspaces and Lerna features for monorepos.","archived":false,"fork":false,"pushed_at":"2021-06-16T15:10:57.000Z","size":25344,"stargazers_count":14,"open_issues_count":2,"forks_count":36,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-28T03:34:54.803Z","etag":null,"topics":["demo","monorepo","workspaces","yarn-workspaces"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomFern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-14T18:40:23.000Z","updated_at":"2023-11-05T10:39:43.000Z","dependencies_parsed_at":"2022-08-06T09:16:47.675Z","dependency_job_id":null,"html_url":"https://github.com/TomFern/semaphore-demo-monorepo-javascript","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomFern%2Fsemaphore-demo-monorepo-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomFern%2Fsemaphore-demo-monorepo-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomFern%2Fsemaphore-demo-monorepo-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomFern%2Fsemaphore-demo-monorepo-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomFern","download_url":"https://codeload.github.com/TomFern/semaphore-demo-monorepo-javascript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248898561,"owners_count":21179793,"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":["demo","monorepo","workspaces","yarn-workspaces"],"created_at":"2025-03-28T03:34:59.227Z","updated_at":"2025-10-18T23:58:53.753Z","avatar_url":"https://github.com/TomFern.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript Monorepo Demo\n\n[![Build Status](https://semaphore-demos.semaphoreci.com/badges/semaphore-demo-monorepo-javascript/branches/final.svg)](https://semaphore-demos.semaphoreci.com/projects/semaphore-demo-monorepo-javascript)\n\nThis demo repository teaches you how to use [Yarn Workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) and [Lerna](https://lerna.js.org/) to manage JavaScript [monorepos](https://semaphoreci.com/blog/what-is-monorepo). You’ll build a monorepo from two separate applications.\n\nCheck the `final` branch to see the end result.\n\n## Contents\n\nThis repository contains two projects. Their folders are:\n\n- `api`: An API that returns geographical information.\n- `web`: A static website generated from the information returned by the API.\n\nYou can run each project independently or in combination. Check each folder to learn how to run them piecemeal. The next section shows how to run them together.\n\n## Setup monorepo with Yarn workspaces\n\n1. Fork this repo.\n2. Clone it to your machine.\n3. Download latest yarn version.\n    ```bash\n    $ yarn set version berry\n    ```\n4. Initialize top-level `package.json`.\n    ```bash\n    $ yarn init -w\n    ```\n5. Move projects to their workspaces.\n    ```bash\n    $ git mv api web packages\n    $ yarn workspaces list\n    ```\n6. Install all modules.\n    ```bash\n    $ yarn install\n    ```\n7. Delete old `yarn.lock`\n    ```bash\n    $ git rm packages/api/yarn.lock packages/web/yarn.lock\n    ```\n7. Add the new files to the repository. This will also commit all dependencies.\n    ```bash\n    $ git add .yarnrc.yml .yarn yarn.lock .gitattributes .gitignore package.json .pnp.js\n    $ git commit -m \"finalize monorepo setup\"\n    $ git push\n    ```\nYou can peek at the final state of the pipeline in the `final` branch.\n\n![Final pipeline](./pipeline.png)\n\n## Run development version\n\n```bash\n$ yarn workspace api start \u0026\n$ yarn workspace web dev\n```\n\n### Run tests\n\n```bash\n# Linting\n$ yarn workspace api lint\n$ yarn workspace web test\n\n# Unit tests - api\n$ yarn workspace api start \u0026\n$ yarn workspace api test\n\n# Unit tests - web\n$ yarn workspace web test\n\n# Integration tests\n$ yarn workspace api start \u0026\n$ yarn workspace web build\n$ yarn workspace web start \u0026\n$ yarn workspace web test-integration\n```\n### Add modules in one workspace\n\n```bash\n$ yarn workspace \u003cworkspace-name\u003e add \u003cpackage-name\u003e\n```\n### Run scripts\n\n```bash\n$ yarn worksapce \u003cworkspace-name\u003e run \u003cscript-name\u003e\n```\n## Build static site\n\n```bash\n$ yarn workspace api start \u0026\n$ yarn workspace web build\n$ yarn workspace web export\n```\n\n## Tips for Yarn\n\nA note about Yarn Plug’n’play: scripts running from `Scripts` in `package.json` or with the `yarn run` command will work. But if you run a program directly as `node app.js` it will fail. Instead, run it like `yarn node app.js` this will initialize PnP.\n\nIf you’re using zero-installs and accepting PRs from untrusted sources, it’s a good idea to add a cache check job somewhere in your CI pipeline. This command will re-download all the modules and check them against the cache to ensure none of the dependencies were modified maliciously.\n\n```bash\nyarn install --check-cache\n```\n\n## Setup a monorepo with Lerna\n\nTo setup a monorepo with Lerna + NPM, first initialize the repository.\n\n```bash\n$ lerna init\n$ lerna import api\n$ lerna import web\n```\n\nNow Lerna should detect the monorepo.\n\n```bash\n$ lerna ls\napi\nweb\nfound 2 packages\n```\n\nWith `bootstrap`, Lerna downloads dependencies with NPM and links the packages.\n\n```bash\n$ lerna bootstrap\n```\n\nRun the tests for each package in the monorepo.\n\n```bash\n$ lerna exec npm run lint\n$ lerna exec npm dev \u0026\n$ lerna exec npm test\n$ lerna exec npm run test integration\n```\n\nPush the updates to the repository.\n\n```bash\n$ git add lerna.json package.json packages\n$ git commit -m \"install lerna, ready to publish\"\n```\n\nPublish the new version to NPM. You need to be already-authenticated with `npm login`.\n\n```bash\n$ lerna version\n$ lerna publish from-git\n```\n\n## Tips for coupling Lerna and Workspaces\n\nAdd the following lines to `lerna.json`.\n\n```json\n \"npmClient\": \"yarn\",\n \"useWorkspaces\": true\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2021 Rendered Text\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomfern%2Fsemaphore-demo-monorepo-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomfern%2Fsemaphore-demo-monorepo-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomfern%2Fsemaphore-demo-monorepo-javascript/lists"}