Skip to content

discoverWorkspacePackages

discoverWorkspacePackages(repoRoot, options?): WorkspacePackageEntry[]

Defined in: discover-workspace-packages.ts:97

Every package the repo’s workspace declares, as listWorkspacePackagesSync() entries. Where the patterns come from, in order of preference:

  1. the packages: list of pnpm-workspace.yaml;
  2. otherwise the workspaces field of the root package.json (an array, or { "packages": [...] }), the npm and yarn form;
  3. otherwise the DEFAULT_WORKSPACE_ROOTS as <root>/*.

pnpm-workspace.yaml wins when both files exist, as it does in pnpm.

The patterns are applied in order, the way pnpm applies packages:: an entry adds the packages it matches and a !pattern entry removes the ones collected so far that it matches. The syntax understood:

  • * matches within one path segment (clients/*, pkg-*) and ? one character;
  • ** as a whole segment matches any number of directories, none included (apps/**);
  • a literal directory is that package (observability, docs/theme).

A wildcard never enters node_modules or a hidden directory. A directory is a package only if it has a readable package.json holding a JSON object. The repo root (.) is not a workspace child and is skipped; callers that treat a root-only repo as a single package read the root manifest themselves.

A pattern it cannot interpret (braces, character classes, .. or an absolute path) never throws: it is skipped and handed to options.onSkippedPattern. A directory that does not exist contributes no packages.

The result is de-duplicated by directory and stable: patterns in the order given, the packages one pattern finds sorted by path. Nothing is filtered by name, version or private; that is the caller’s call, as for listWorkspacePackagesSync().

string

DiscoverWorkspacePackagesOptions = {}

WorkspacePackageEntry[]

import { discoverWorkspacePackages } from "@theholocron/pkg-utils";
const names = discoverWorkspacePackages(repoRoot, { group: "clients" }).map((p) => p.name);