{"id":16222108,"url":"https://github.com/hugodf/yarn-workspaces-simple-monorepo","last_synced_at":"2025-03-19T11:31:17.771Z","repository":{"id":44102293,"uuid":"199329794","full_name":"HugoDF/yarn-workspaces-simple-monorepo","owner":"HugoDF","description":"Yarn Workspaces basic monorepo management without Lerna for coding examples","archived":false,"fork":false,"pushed_at":"2022-12-04T05:03:03.000Z","size":268,"stargazers_count":31,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T06:51:20.224Z","etag":null,"topics":["monorepo","nodejs","yarn","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HugoDF.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-28T19:40:44.000Z","updated_at":"2024-10-17T13:42:26.000Z","dependencies_parsed_at":"2023-01-23T08:15:54.404Z","dependency_job_id":null,"html_url":"https://github.com/HugoDF/yarn-workspaces-simple-monorepo","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoDF%2Fyarn-workspaces-simple-monorepo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoDF%2Fyarn-workspaces-simple-monorepo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoDF%2Fyarn-workspaces-simple-monorepo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoDF%2Fyarn-workspaces-simple-monorepo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HugoDF","download_url":"https://codeload.github.com/HugoDF/yarn-workspaces-simple-monorepo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244416974,"owners_count":20449373,"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":["monorepo","nodejs","yarn","yarn-workspaces"],"created_at":"2024-10-10T12:11:12.782Z","updated_at":"2025-03-19T11:31:17.424Z","avatar_url":"https://github.com/HugoDF.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yarn Workspaces basic monorepo management without Lerna (for coding examples)\n\nYarn workspaces give reasonable primitives to work with non-package (library/module) code (eg. application monorepo, coding examples monorepo).\n\n\n## Requirements\n\n- Node 10+\n- Yarn 1.x \n\n## Setup\n\n1. Clone the repository\n2. Run `yarn` to install all required dependencies.\n\n## npm scripts\n\n- `yarn test` will run `test` script for each of the packages in the monorepo\n- `yarn lint` will lint all of the files with [xo](https://github.com/xojs/xo)\n- `yarn format` will run lint with `--fix` option on all the examples files (and tests).\n\n## Guide\n\nPros of using workspaces: Yarn Workspaces are part of the standard Yarn toolchain (not downloading an extra dependency). It's very limited in scope, and de-dupes your installs (ie. makes them faster). This is perfect for managing code examples or a monorepo of applications.\n\nCons of workspaces: If you're dealing with a monorepo of _packages_ (npm modules, libraries), Lerna provides tooling around publishing/testing only changed files.\n\nNote: Lerna and Yarn Workspaces are _in fact_ designed to work together, just use `\"npmClient\": \"yarn\"` in your `lerna.json`.\n\n### Set up Yarn workspaces\n\n```json\n{\n  \"private\": true,\n  \"workspaces\": [ \"examples/*\", \"other-example\"]\n}\n```\n\n**Note**: each of the workspaces (packages) need to have a package.json with a unique `name` and a valid `version`. The root package.json doesn't need to, it just needs to have `\"private\": true` and `\"workspaces\": []`.\n\n### Bootstrapping the monorepo\n\nEquivalent with Lerna would include a `lerna bootstrap`, which run `npm install` in all the packages.\n\nWith workspaces since the dependencies are locked from root, you just need to do a `yarn` at the top-level.\n\nFor workspaces to work, your \"workspace\" folders need to have a package.json that contain a `name` and `version`.\n\n### Managing your monorepo with `yarn workspace` and `yarn workspaces` commands\n\n#### Run commands in a single package\n\nTo run commands in a single package in your monorepo, use the following syntax:\n\n```sh\nyarn workspace \u003cpackage-name\u003e \u003cyarn-command\u003e\n```\n\nFor example:\n\n```sh\n$ yarn workspace example-1 run test\n\nyarn workspace v1.x.x\nyarn run v1.x.x\n$ node test.js\ntest from example 1\n✨  Done in 0.23s.\n✨  Done in 0.86s.\n```\n\nor\n\n```sh\n$ yarn workspace example-2 remove lodash.omit\n\nyarn workspace v1.x.x\nyarn remove v1.x.x\n[1/2] 🗑  Removing module lodash.omit...\n[2/2] 🔨  Regenerating lockfile and installing missing dependencies...\nsuccess Uninstalled packages.\n✨  Done in 2.83s.\n✨  Done in 3.58s.\n```\n\n\n\"package-name\" should be the value of found in the package.json under the `name` key.\n\n#### Run commands in all packages\n\nTo run commands in every package in your monorepo, use the following syntax:\n\n```sh\nyarn workspaces \u003cyarn-command\u003e\n```\n\nFor example:\n\n```sh\n$ yarn workspaces run test\n\nyarn workspaces v1.x.x\nyarn run v1.x.x\n$ node test.js\ntest from example 1\n✨  Done in 0.22s.\nyarn run v1.x.x\n$ node test.js\n{ public: 'data' } 'Should not display \"secret\"'\n✨  Done in 0.23s.\nyarn run v1.x.x\n$ echo \"Other Example\"\nOther Example\n✨  Done in 0.11s.\n✨  Done in 2.15s.\n```\n\nor\n\n```sh\n$ yarn workspaces run add lodash.omit@latest\n\nyarn workspaces v1.x.x\nyarn add v1.x.x\n[1/4] 🔍  Resolving packages...\n[2/4] 🚚  Fetching packages...\n[3/4] 🔗  Linking dependencies...\n[4/4] 🔨  Building fresh packages...\nsuccess Saved 1 new dependency.\ninfo Direct dependencies\ninfo All dependencies\n└─ lodash.omit@4.5.0\n✨  Done in 3.31s.\nyarn add v1.x.x\n[1/4] 🔍  Resolving packages...\n[2/4] 🚚  Fetching packages...\n[3/4] 🔗  Linking dependencies...\n[4/4] 🔨  Building fresh packages...\nsuccess Saved 1 new dependency.\ninfo Direct dependencies\ninfo All dependencies\n└─ lodash.omit@4.5.0\n✨  Done in 2.76s.\nyarn add v1.x.x\n[1/4] 🔍  Resolving packages...\n[2/4] 🚚  Fetching packages...\n[3/4] 🔗  Linking dependencies...\n[4/4] 🔨  Building fresh packages...\nsuccess Saved 1 new dependency.\ninfo Direct dependencies\ninfo All dependencies\n└─ lodash.omit@4.5.0\n✨  Done in 2.63s.\n✨  Done in 10.82s.\n\n```\n\n## LICENSE\n\nCode is licensed under the [MIT License](./LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugodf%2Fyarn-workspaces-simple-monorepo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugodf%2Fyarn-workspaces-simple-monorepo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugodf%2Fyarn-workspaces-simple-monorepo/lists"}