All Projects → HugoDF → yarn-workspaces-simple-monorepo

HugoDF / yarn-workspaces-simple-monorepo

Licence: MIT license
Yarn Workspaces basic monorepo management without Lerna for coding examples

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to yarn-workspaces-simple-monorepo

React-Native-Web-TypeScript-Prettier-Boilerplate
A starterkit to work with nextjs, react-native, storybook… all with prettified typescript and in a monorepo
Stars: ✭ 16 (-48.39%)
Mutual labels:  yarn, monorepo, yarn-workspaces
mock-spy-module-import
JavaScript import/require module testing do's and don'ts with Jest
Stars: ✭ 40 (+29.03%)
Mutual labels:  yarn, monorepo, yarn-workspaces
Yerna
A Lerna-like tool for managing Javascript monorepos using Yarn
Stars: ✭ 140 (+351.61%)
Mutual labels:  yarn, monorepo
Lrnwebcomponents
@lrnwebcomponents Monorepo for NPM based element definitions
Stars: ✭ 166 (+435.48%)
Mutual labels:  yarn, monorepo
monorepo-utils
A collection of utilities for monorepo/lerna. Tools for TypeScript project references etc..
Stars: ✭ 143 (+361.29%)
Mutual labels:  yarn, monorepo
Vitamin Web
Decathlon Design System libraries for web applications
Stars: ✭ 70 (+125.81%)
Mutual labels:  yarn, monorepo
Create React App
Yarn Workspaces Monorepo support for Create-React-App / React-Scripts.
Stars: ✭ 76 (+145.16%)
Mutual labels:  yarn, monorepo
zsh-yarn-completions
Yarn completions for Z-shell that supports yarn workspaces
Stars: ✭ 35 (+12.9%)
Mutual labels:  yarn, yarn-workspaces
Lerna Yarn Workspaces Example
How to build TypeScript mono-repo project with yarn and lerna
Stars: ✭ 787 (+2438.71%)
Mutual labels:  yarn, monorepo
devto-monorepo
Source code for the Dev.to article - Next.js, Apollo Client and Server on a single Express app
Stars: ✭ 33 (+6.45%)
Mutual labels:  monorepo, yarn-workspaces
cra-monorepo-demo
Monorepo example using create-react-app and common component library structure with yarn workspaces
Stars: ✭ 37 (+19.35%)
Mutual labels:  monorepo, yarn-workspaces
nextjs-monorepo-example
Collection of monorepo tips & tricks
Stars: ✭ 874 (+2719.35%)
Mutual labels:  yarn, monorepo
Eslint Plugin Monorepo
ESLint Plugin for monorepos
Stars: ✭ 56 (+80.65%)
Mutual labels:  yarn, monorepo
Next Express Monorepo Starter
NextJS, Express and Now as Microservices with Yarn & Lerna Workspaces
Stars: ✭ 50 (+61.29%)
Mutual labels:  yarn, monorepo
Flow Mono Cli
A command line interface that aims to solve a few issues while working with flow typed codebases in a mono-repo.
Stars: ✭ 84 (+170.97%)
Mutual labels:  yarn, monorepo
Oao
A Yarn-based, opinionated monorepo management tool
Stars: ✭ 796 (+2467.74%)
Mutual labels:  yarn, monorepo
introduction-nodejs
Introduction to NodeJS
Stars: ✭ 13 (-58.06%)
Mutual labels:  yarn, monorepo
react-monorepo
a simple monorepo setup for react & react-native using yarn workspaces.
Stars: ✭ 40 (+29.03%)
Mutual labels:  monorepo, yarn-workspaces
Syncpack
Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces
Stars: ✭ 356 (+1048.39%)
Mutual labels:  yarn, monorepo
React Workspaces Playground
⚛️ 🐈 Zero Config Create-React-App Monorepos with Yarn Workspaces, Lerna and React Storybook.
Stars: ✭ 658 (+2022.58%)
Mutual labels:  yarn, monorepo

Yarn Workspaces basic monorepo management without Lerna (for coding examples)

Yarn workspaces give reasonable primitives to work with non-package (library/module) code (eg. application monorepo, coding examples monorepo).

Requirements

  • Node 10+
  • Yarn 1.x

Setup

  1. Clone the repository
  2. Run yarn to install all required dependencies.

npm scripts

  • yarn test will run test script for each of the packages in the monorepo
  • yarn lint will lint all of the files with xo
  • yarn format will run lint with --fix option on all the examples files (and tests).

Guide

Pros 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.

Cons of workspaces: If you're dealing with a monorepo of packages (npm modules, libraries), Lerna provides tooling around publishing/testing only changed files.

Note: Lerna and Yarn Workspaces are in fact designed to work together, just use "npmClient": "yarn" in your lerna.json.

Set up Yarn workspaces

{
  "private": true,
  "workspaces": [ "examples/*", "other-example"]
}

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": [].

Bootstrapping the monorepo

Equivalent with Lerna would include a lerna bootstrap, which run npm install in all the packages.

With workspaces since the dependencies are locked from root, you just need to do a yarn at the top-level.

For workspaces to work, your "workspace" folders need to have a package.json that contain a name and version.

Managing your monorepo with yarn workspace and yarn workspaces commands

Run commands in a single package

To run commands in a single package in your monorepo, use the following syntax:

yarn workspace <package-name> <yarn-command>

For example:

$ yarn workspace example-1 run test

yarn workspace v1.x.x
yarn run v1.x.x
$ node test.js
test from example 1
✨  Done in 0.23s.
✨  Done in 0.86s.

or

$ yarn workspace example-2 remove lodash.omit

yarn workspace v1.x.x
yarn remove v1.x.x
[1/2] 🗑  Removing module lodash.omit...
[2/2] 🔨  Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
✨  Done in 2.83s.
✨  Done in 3.58s.

"package-name" should be the value of found in the package.json under the name key.

Run commands in all packages

To run commands in every package in your monorepo, use the following syntax:

yarn workspaces <yarn-command>

For example:

$ yarn workspaces run test

yarn workspaces v1.x.x
yarn run v1.x.x
$ node test.js
test from example 1
✨  Done in 0.22s.
yarn run v1.x.x
$ node test.js
{ public: 'data' } 'Should not display "secret"'
✨  Done in 0.23s.
yarn run v1.x.x
$ echo "Other Example"
Other Example
✨  Done in 0.11s.
✨  Done in 2.15s.

or

$ yarn workspaces run add lodash.omit@latest

yarn workspaces v1.x.x
yarn add v1.x.x
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
info All dependencies
└─ [email protected]
✨  Done in 3.31s.
yarn add v1.x.x
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
info All dependencies
└─ [email protected]
✨  Done in 2.76s.
yarn add v1.x.x
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
info All dependencies
└─ [email protected]
✨  Done in 2.63s.
✨  Done in 10.82s.

LICENSE

Code is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].