Monorepo support

Learn more about the monorepo support and which configurations are supported.

Omlet is designed to support monorepos and automatically detects each package as a separate project. Here are the details of how Omlet detects projects based on your package manager/build system.

npm/Yarn

Omlet will look for the workspace configuration in package.json, under workspaces or workspace.packages fields.

package.json
{
  ...
  "workspaces": {
    "packages": [
      "packages/ds",
      "packages/app"
    ],
  },
  ...
}
package.json
{
  ...
  "workspaces": [
    "packages/ds",
    "packages/app"
  ],
  ...
}
package.json
{
  ...
  "workspaces": [
    "packages/*",
  ],
  ...
}
pnpm

Omlet will look for the workspace configuration in pnpm-workspace.yaml, under packages filed.

pnpm-workspace.yaml
packages:
  - 'packages/*'
pnpm-workspace.yaml
packages:
  - 'packages/**'
  - 'apps/**'
Lerna

Omlet will look for the workspace configuration in lerna.json, under the packages filed.

lerna.json
{
  "packages": [
    "packages/*"
  ]
}
Bolt

Omlet will look for the workspace configuration in package.json, under bolt field.

package.json
{
  ...
  "bolt": {
    "workspaces": [
      "packages/*",
    ],
  },
  ...
}
Nx

Nx can be installed on top of other monorepo libraries. Omlet detects workspaces that are defined using another monorepo library configuration and ignores Nx. That said, a repository having nx.json doesn't mean that it's treated as an Nx monorepo. Other monorepo configurations take precedence.

If Nx is used as the main monorepo library, each workspace folder contains a project.json file and, optionally, a package.json file if the workspace is publishable. In this case, Omlet searches for both project.json and package.json files in the repository to figure out workspace folders. If package.json file exists, the name field in package.json is used as the workspace name. Otherwise, the name field in project.json (or the folder name if the name field doesn't exist) is combined with the name of the root package.json to generate the name of the workspace.

Lastly, package dependency resolution is handled by utilizing tsconfig.json files under each workspace. Each tsconfig.json file under a workspace, extends tsconfig.base.json file on the root folder, which contains the paths configuration needed for dependency resolution.

For instance, with the given configurations below, Omlet will detect the workspaces as @nx-monorepo/ds and @nx-monorepo/app.

package.json (root)
{
  ...
  "name": "@nx-monorepo",
  ...
}
tsconfig.base.json
{
  ...
  "compilerOptions": {
    "paths": {
      "@nx-monorepo/ds": ["path/to/ds/src/index.ts"],
    }
  }
  ...
}
path/to/ds/package.json
{
  ...
  "name": "@nx-monorepo/ds",
  ...
}
path/to/ds/project.json
{
  ...
  "name": "design-system",
  ...
}
path/to/ds/tsconfig.json
{
  ...
  "extends": "../../../tsconfig.base.json"
  ...
}
path/to/app/project.json
{
  ...
  "name": "app",
  ...
}
path/to/app/tsconfig.json
{
  ...
  "extends": "../../../tsconfig.base.json"
  ...
}

Last updated