---
title: "@vltpkg/workspaces: Reference — vlt docs"
description: "Documentation for the vlt client and the vlt registry."
url: "https://docs.vlt.io/client/api-reference/workspaces/reference"
image: "https://docs.vlt.io/og/client/api-reference/workspaces/reference"
lang: "en"
---

# Reference

## Classes

### Monorepo

Defined in: index.ts:334

Class representing a Monorepo containing multiple workspaces.

Does not automatically look up the root, but that can be provided by running `Config.load()`, since it stops seeking the route when a `vlt.json` file is encountered.

#### Constructors

##### new Monorepo()

```ts
new Monorepo(projectRoot, options): Monorepo
```

Defined in: index.ts:353

###### Parameters

| Parameter     | Type                                                                                                  |
| ------------- | ----------------------------------------------------------------------------------------------------- |
| `projectRoot` | `string`                                                                                              |
| `options`     | [`MonorepoOptions`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepooptions) |

###### Returns

[`Monorepo`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepo)

#### Properties

| Property      | Type                                                                                            | Description                                                |
| ------------- | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| `packageJson` | [`PackageJson`](https://docs.vlt.io/client/api-reference/package-json/reference.md#packagejson) | -                                                          |
| `projectRoot` | `string`                                                                                        | The project root where vlt.json is found                   |
| `scurry`      | [`PathScurry`](https://isaacs.github.io/path-scurry/)                                           | Scurry object to cache all filesystem calls (mostly globs) |

#### Accessors

##### config

###### Get Signature

```ts
get config(): WorkspaceConfigObject
```

Defined in: index.ts:371

Load the workspace definitions from vlt.json, else the root package.json, else pnpm-workspace.yaml (see [resolveWSConfig](https://docs.vlt.io/client/api-reference/workspaces/reference.md#resolvewsconfig)), canonicalizing the result into the effective `{[group:string]:string[]}` form.

Eg:

- `"src/*"` => `{packages:["src/*"]}`
- `{"apps": "src/*"}` => `{apps: ["src/*"]}`

###### Returns

[`WorkspaceConfigObject`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject)

##### size

###### Get Signature

```ts
get size(): number
```

Defined in: index.ts:349

Number of [Workspace](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace) objects loaded in this Monorepo

###### Returns

`number`

#### Methods

##### \[asyncIterator]\()

```ts
asyncIterator: AsyncGenerator<Workspace, void, void>
```

Defined in: index.ts:398

Iterating the Monorepo object yields the workspace objects, in as close to topological dependency order as possible.

###### Returns

`AsyncGenerator`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace), `void`, `void`>

##### \[iterator]\()

```ts
iterator: Generator<Workspace, void, void>
```

Defined in: index.ts:384

Iterating the Monorepo object yields the workspace objects, in as close to topological dependency order as possible.

###### Returns

`Generator`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace), `void`, `void`>

##### filter()

```ts
filter(__namedParameters): Generator<Workspace, void, unknown>
```

Defined in: index.ts:760

Filter the monorepo object yielding the workspace objects that matches either of the [WorkspacesLoadedConfig](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspacesloadedconfig) options provided, in as close to topological dependency order as possible.

###### Parameters

| Parameter           | Type                                                                                                                |
| ------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `__namedParameters` | [`WorkspacesLoadedConfig`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspacesloadedconfig) |

###### Returns

`Generator`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace), `void`, `unknown`>

##### get()

```ts
get(nameOrPath): undefined | Workspace
```

Defined in: index.ts:707

Get a loaded workspace by path or name.

Note that this can only return workspaces that were ingested via a previous call to [Monorepo#load](https://docs.vlt.io/client/api-reference/workspaces/reference.md#load).

###### Parameters

| Parameter    | Type     |
| ------------ | -------- |
| `nameOrPath` | `string` |

###### Returns

`undefined` | [`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)

##### getDeps()

```ts
getDeps(ws, forceLoad): Workspace[]
```

Defined in: index.ts:623

Return the array of workspace dependencies that are found in the loaded set, for use in calculating dependency graph order for build operations.

This does _not_ get the full set of dependencies, or expand any `workspace:` dependencies that are not loaded.

Bare semver specs are matched by name, and linked only when the local workspace version satisfies the range -- the same test `@vltpkg/satisfies` applies at resolution time, so the two agree on which deps are local. Specs that aren't parseable ranges, such as dist-tags, still match by name alone.

Call with the `forceLoad` param set to `true` to attempt a full load if any deps are not currently loaded.

###### Parameters

| Parameter   | Type                                                                                      | Default value |
| ----------- | ----------------------------------------------------------------------------------------- | ------------- |
| `ws`        | [`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace) | `undefined`   |
| `forceLoad` | `boolean`                                                                                 | `false`       |

###### Returns

[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)\[]

##### group()

```ts
group(group): undefined | Set<Workspace>
```

Defined in: index.ts:697

Return the set of workspaces in the named group. If the group is not one we know about, then undefined is returned.

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `group`   | `string` |

###### Returns

`undefined` | `Set`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)>

##### keys()

```ts
keys(): Generator<string, void, unknown>
```

Defined in: index.ts:748

Get all the keys (package names and paths) for loaded workspaces. Union of [Monorepo#names](https://docs.vlt.io/client/api-reference/workspaces/reference.md#names) and [Monorepo#paths](https://docs.vlt.io/client/api-reference/workspaces/reference.md#paths)

###### Returns

`Generator`<`string`, `void`, `unknown`>

##### load()

```ts
load(query): this
```

Defined in: index.ts:425

By default, loads all workspaces reachable in the Monorepo.

If provided with one (`string`)or more (`string[]`) group names in the [LoadQuery#groups](https://docs.vlt.io/client/api-reference/workspaces/reference.md#groups-1) field, then only Workspaces in the named group(s) will be considered. Note that group names are unique string matches, not globs.

If provided with a set of arbitrary path arguments, then only paths patching the provided pattern(s) will be included.

These two options intersect, so `load({groups:'foo', paths:'./foo/[xy]*'})` will only load the workspaces in the group `foo` that match the paths glob.

###### Parameters

| Parameter | Type                                                                                      |
| --------- | ----------------------------------------------------------------------------------------- |
| `query`   | [`LoadQuery`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#loadquery) |

###### Returns

`this`

##### names()

```ts
names(): Generator<string, void, unknown>
```

Defined in: index.ts:714

get the list of all loaded workspace names used as keys

###### Returns

`Generator`<`string`, `void`, `unknown`>

##### onCycle()

```ts
onCycle(
   _ws, 
   _cycle, 
   _depPath): void
```

Defined in: index.ts:679

###### Parameters

| Parameter  | Type                                                                                         |
| ---------- | -------------------------------------------------------------------------------------------- |
| `_ws`      | [`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)    |
| `_cycle`   | [`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)\[] |
| `_depPath` | [`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)\[] |

###### Returns

`void`

##### paths()

```ts
paths(): Generator<string, void, unknown>
```

Defined in: index.ts:723

get the list of all loaded workspace paths used as keys

###### Returns

`Generator`<`string`, `void`, `unknown`>

##### run()

```ts
run<R>(operation, forceLoad): Promise<Map<Workspace, R>>
```

Defined in: index.ts:803

Run an operation asynchronously over all loaded workspaces

If the `forceLoad` param is true, then it will attempt to do a full load when encountering a `workspace:` dependency that isn't loaded.

Note that because the return type appears in the parameters of the operation function, it must be set explicitly either in the operation function signature or by calling `run<MyType>` or it'll fall back to `unknown`, similar to `Array.reduce()`, and for the same reason.

###### Type Parameters

| Type Parameter |
| -------------- |
| `R`            |

###### Parameters

| Parameter   | Type                                                   | Default value |
| ----------- | ------------------------------------------------------ | ------------- |
| `operation` | (`s`, `signal`, `depResults`) => `R` \| `Promise`<`R`> | `undefined`   |
| `forceLoad` | `boolean`                                              | `false`       |

###### Returns

`Promise`<`Map`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace), `R`>>

##### runSync()

```ts
runSync<R>(operation, forceLoad): Map<Workspace, R>
```

Defined in: index.ts:836

Run an operation synchronously over all loaded workspaces

If the `forceLoad` param is true, then it will attempt to do a full load when encountering a `workspace:` dependency that isn't loaded.

Note that because the return type appears in the parameters of the operation function, it must be set explicitly either in the operation function signature or by calling `runSync<MyType>` or it'll fall back to `unknown`, similar to `Array.reduce()`, and for the same reason.

###### Type Parameters

| Type Parameter |
| -------------- |
| `R`            |

###### Parameters

| Parameter   | Type                                 | Default value |
| ----------- | ------------------------------------ | ------------- |
| `operation` | (`s`, `signal`, `depResults`) => `R` | `undefined`   |
| `forceLoad` | `boolean`                            | `false`       |

###### Returns

`Map`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace), `R`>

##### values()

```ts
values(): Generator<Workspace, void, unknown>
```

Defined in: index.ts:735

get the workspace objects in no particular order. this is ever so slightly faster than iterating, because it doesn't explore the graph to yield results in topological dependency order, and should be used instead when order doesn't matter.

###### Returns

`Generator`<[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace), `void`, `unknown`>

##### load()

```ts
static load(projectRoot, options): Monorepo
```

Defined in: index.ts:886

Convenience method to instantiate and load in one call. Throws if called on a directory that is not a workspaces root.

###### Parameters

| Parameter     | Type                                                                                                  |
| ------------- | ----------------------------------------------------------------------------------------------------- |
| `projectRoot` | `string`                                                                                              |
| `options`     | [`MonorepoOptions`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepooptions) |

###### Returns

[`Monorepo`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepo)

##### maybeLoad()

```ts
static maybeLoad(projectRoot, options): undefined | Monorepo
```

Defined in: index.ts:865

Convenience method to instantiate and load in one call. Returns undefined if the project is not a monorepo workspaces root, meaning none of `vlt.json`, the root `package.json` or `pnpm-workspace.yaml` declares any workspaces. Otherwise returns the loaded Monorepo.

###### Parameters

| Parameter     | Type                                                                                                  |
| ------------- | ----------------------------------------------------------------------------------------------------- |
| `projectRoot` | `string`                                                                                              |
| `options`     | [`MonorepoOptions`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepooptions) |

###### Returns

`undefined` | [`Monorepo`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepo)

---

### Workspace

Defined in: index.ts:900

Class representing a single Workspace in a [Monorepo](https://docs.vlt.io/client/api-reference/workspaces/reference.md#monorepo)

#### Constructors

##### new Workspace()

```ts
new Workspace(
   path, 
   manifest, 
   fullpath): Workspace
```

Defined in: index.ts:909

###### Parameters

| Parameter  | Type                                                                                  |
| ---------- | ------------------------------------------------------------------------------------- |
| `path`     | `string`                                                                              |
| `manifest` | [`Override`](https://docs.vlt.io/client/api-reference/types/reference.md#overridet-r) |
| `fullpath` | `string`                                                                              |

###### Returns

[`Workspace`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace)

#### Properties

| Property   | Type                                                                                  | Default value |
| ---------- | ------------------------------------------------------------------------------------- | ------------- |
| `fullpath` | `string`                                                                              | `undefined`   |
| `groups`   | `string`\[]                                                                           | `[]`          |
| `id`       | [`DepID`](https://docs.vlt.io/client/api-reference/dep-id/browser.md#depid)           | `undefined`   |
| `manifest` | [`Override`](https://docs.vlt.io/client/api-reference/types/reference.md#overridet-r) | `undefined`   |
| `name`     | `string`                                                                              | `undefined`   |
| `path`     | `string`                                                                              | `undefined`   |

#### Accessors

##### keys

###### Get Signature

```ts
get keys(): string[]
```

Defined in: index.ts:922

###### Returns

`string`\[]

## Type Aliases

### LoadQuery

```ts
type LoadQuery = object;
```

Defined in: index.ts:46

The object passed to the constructor or [Monorepo#load](https://docs.vlt.io/client/api-reference/workspaces/reference.md#load) to limit which [Workspaces](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspace) get loaded.

#### Type declaration

| Name      | Type                    | Description                                                                                                       |
| --------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `groups`? | `string`\[] \| `string` | A string, or an array of strings. If set, only workspaces in the specified groups named will be included, if set. |
| `paths`?  | `string`\[] \| `string` | A glob pattern string, or an array of them. Only workspaces found in paths matched will be loaded.                |

---

### MonorepoOptions

```ts
type MonorepoOptions = object;
```

Defined in: index.ts:305

#### Type declaration

| Name           | Type                                                                                                              | Description                                                                                                                                        |
| -------------- | ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `config`?      | [`WorkspaceConfigObject`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject) | Parsed normalized contents of the workspaces, from `vlt.json`, `package.json` or `pnpm-workspace.yaml`. If set, the file is not read again.        |
| `load`?        | [`LoadQuery`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#loadquery)                         | If set, then [Monorepo#load](https://docs.vlt.io/client/api-reference/workspaces/reference.md#load) will be called immediately with this argument. |
| `packageJson`? | [`PackageJson`](https://docs.vlt.io/client/api-reference/package-json/reference.md#packagejson)                   | A [PackageJson](https://docs.vlt.io/client/api-reference/package-json/reference.md#packagejson) object, for sharing manifest caches                |
| `scurry`?      | [`PathScurry`](https://isaacs.github.io/path-scurry/)                                                             | A [PathScurry](https://isaacs.github.io/path-scurry/) object, for use in globs                                                                     |

---

### ResolvedWorkspaceConfig

```ts
type ResolvedWorkspaceConfig = object;
```

Defined in: index.ts:200

#### Type declaration

| Name      | Type                                                                                                              | Description                                                                                                                                                                                |
| --------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `config`  | [`WorkspaceConfigObject`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject) | -                                                                                                                                                                                          |
| `source`? | [`WorkspaceConfigSource`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigsource) | The file the config came from, or `undefined` when none of `vlt.json`, the root `package.json` or `pnpm-workspace.yaml` declares any workspaces -- ie, when the project is not a monorepo. |

---

### WorkspaceConfig

```ts
type WorkspaceConfig = 
  | string[]
  | WorkspaceConfigObject
  | string;
```

Defined in: index.ts:68

Allowed datatype in the `workspaces` field of the `vlt.json` file.

---

### WorkspaceConfigObject

```ts
type WorkspaceConfigObject = Record<string, string[]>;
```

Defined in: index.ts:63

Canonical form of the [WorkspaceConfig](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfig), used internally for consistency.

---

### WorkspaceConfigSource

```ts
type WorkspaceConfigSource = "vlt.json" | "package.json" | "pnpm-workspace.yaml";
```

Defined in: index.ts:197

Which file a project's workspace definitions came from.

---

### WorkspacesLoadedConfig

```ts
type WorkspacesLoadedConfig = object;
```

Defined in: index.ts:37

#### Type declaration

| Name               | Type        |
| ------------------ | ----------- |
| `workspace`?       | `string`\[] |
| `workspace-group`? | `string`\[] |

## Variables

### workspaceCache

```ts
const workspaceCache: Map<string, Workspace>;
```

Defined in: index.ts:895

## Functions

### asManifestWSConfig()

```ts
function asManifestWSConfig(conf, path): WorkspaceConfigObject
```

Defined in: index.ts:168

Turn the `workspaces` field of a root `package.json` into a [WorkspaceConfigObject](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject).

Only the shapes npm and yarn-classic actually understand are accepted: a glob string, an array of them, or `{packages: [...]}`. vlt's named workspace groups are deliberately _not_ accepted here -- a `package.json` using them would be meaningless to every other package manager, so they have to live in `vlt.json`.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `conf`    | `unknown` |
| `path`    | `string`  |

#### Returns

[`WorkspaceConfigObject`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject)

---

### assertWSConfig()

```ts
function assertWSConfig(conf, path?): asserts conf is WorkspaceConfig
```

Defined in: index.ts:95

Throw if the provided value is not a valid [WorkspaceConfig](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfig)

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `conf`    | `unknown` |
| `path`?   | `string`  |

#### Returns

`asserts conf is WorkspaceConfig`

---

### asWSConfig()

```ts
function asWSConfig(conf, path?): WorkspaceConfigObject
```

Defined in: index.ts:75

Turn a [WorkspaceConfig](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfig) into a [WorkspaceConfigObject](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject), or throw if it's not valid.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `conf`    | `unknown` |
| `path`?   | `string`  |

#### Returns

[`WorkspaceConfigObject`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#workspaceconfigobject)

---

### migratableWSConfig()

```ts
function migratableWSConfig(__namedParameters): undefined | string[]
```

Defined in: index.ts:266

Globs to save to `vlt.json` for workspaces declared in `package.json` or `pnpm-workspace.yaml`: plain array, in order, `!` kept (yarn `nohoist` already dropped). `undefined` if from `vlt.json` or none.

#### Parameters

| Parameter           | Type                                                                                                                  |
| ------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `__namedParameters` | [`ResolvedWorkspaceConfig`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#resolvedworkspaceconfig) |

#### Returns

`undefined` | `string`\[]

---

### resolveWSConfig()

```ts
function resolveWSConfig(
   projectRoot, 
   packageJson, 
   vltJsonOnlyArg): ResolvedWorkspaceConfig
```

Defined in: index.ts:233

Resolve the effective workspace definitions for a project.

`vlt.json` wins whenever it has a `workspaces` field; otherwise the npm/yarn-style `workspaces` field of the project root's `package.json` is used, then the `packages` list of a root `pnpm-workspace.yaml`. Note the precedence is keyed on the _field_, not the file: a `vlt.json` that exists but says nothing about workspaces still falls through to `package.json`.

`vltJsonOnlyArg` skips both fallbacks (default: [setVltJsonOnly](https://docs.vlt.io/client/api-reference/workspaces/reference.md#setvltjsononly)).

#### Parameters

| Parameter        | Type                                                                                            | Default value |
| ---------------- | ----------------------------------------------------------------------------------------------- | ------------- |
| `projectRoot`    | `string`                                                                                        | `undefined`   |
| `packageJson`    | [`PackageJson`](https://docs.vlt.io/client/api-reference/package-json/reference.md#packagejson) | `...`         |
| `vltJsonOnlyArg` | `boolean`                                                                                       | `vltJsonOnly` |

#### Returns

[`ResolvedWorkspaceConfig`](https://docs.vlt.io/client/api-reference/workspaces/reference.md#resolvedworkspaceconfig)

---

### setVltJsonOnly()

```ts
function setVltJsonOnly(value): void
```

Defined in: index.ts:217

Process-wide: when true, [resolveWSConfig](https://docs.vlt.io/client/api-reference/workspaces/reference.md#resolvewsconfig) reads `vlt.json` only, ignoring `package.json` and `pnpm-workspace.yaml`. Set by `vlt ci`.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `value`   | `boolean` |

#### Returns

`void`

---

### splitNegatedPatterns()

```ts
function splitNegatedPatterns(all): object
```

Defined in: index.ts:284

Split a list of glob patterns into the positive patterns and the npm-compatible `!`-negated ones, which become ignore patterns.

Follows npm's `map-workspaces` rules: an even number of leading `!` is a positive pattern (`!!foo` means `foo`), a leading `./` or `/` is stripped, and a later positive pattern un-negates any earlier negation it matches, so `['a/**', '!a/b/**', 'a/b/c']` keeps `a/b/c`.

#### Parameters

| Parameter | Type        |
| --------- | ----------- |
| `all`     | `string`\[] |

#### Returns

`object`

| Name       | Type        |
| ---------- | ----------- |
| `ignore`   | `string`\[] |
| `patterns` | `string`\[] |
