Javascript - MonoRepo

About

MonoRepo (vs ManyRepos) in the Javascript context

When starting with monorepo, integrate first the leaf projects of the dependency graph (ie project without dependency).

File System Dependency Resolution

To use the library locally without publishing to a remote npm registry.

With the help of symlink, you create a symlink in the parent project to node_modules/dependency that links to the local path of the project dependency.

yarn 1) and npm have a link command

Example of steps with one application and one package dependency.

  • Yarn
# go to your package
cd ../my-package
yarn install
yarn link # Create a link from the dependency
# go to your app or package that depends on the first package
cd ../my-app
yarn link my-package
yarn run build
  • Npm
~/my-package$ npm install
~/my-package$ npm link
~/my-package$ cd myApp
~/my-app$ npm link /path/to/my-package

Env

NODE_PATH may be used to emulate a monorepo

NODE_PATH=src

Workspace

Package manager have automated the link concept and made it easier to create them via the concept of workspace.

They are automating the link operation.

Yarn Workspace

A workspace 2) is a local package managed by a workspace root.

It's actually a yarn concept that create link between Workspaces that depend on each other. The local dependency workspace-a is aliased as /node_modules/workspace-a via a symlink.

Yarn Workspaces permits to dedupe node_modules.

For cli that doesn't relate all path from the working directory, you can use a nohoist

See

Under a child workspace:

"workspaces": {
  "nohoist": ["react-native", "react-native/**"],
  "packages/*",
  "website",
  "examples/*"
}

Pnpm Workspace

Pnpm workspace 3)

Publishing

The below tools are versioning packages utility.

They are only needed if you publish them to a registry such as NPM for external consumption.

Lerna

MonoRepo Manager - Lerna helps to publish package and create changelogs.

It uses also Yarn workspace to get the link

ChangeSet

BeachBall

https://github.com/microsoft/beachball - the sunniest version bumping tool

Framework

Monorepo framework are bundler that are specialized for a monorepo.

Nx

Rush

Bolt

Turbo

Task Runner


Powered by ComboStrap