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:
- the
packages:list ofpnpm-workspace.yaml; - otherwise the
workspacesfield of the rootpackage.json(an array, or{ "packages": [...] }), the npm and yarn form; - 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().
Parameters
Section titled “Parameters”repoRoot
Section titled “repoRoot”string
options?
Section titled “options?”DiscoverWorkspacePackagesOptions = {}
Returns
Section titled “Returns”Example
Section titled “Example”import { discoverWorkspacePackages } from "@theholocron/pkg-utils";
const names = discoverWorkspacePackages(repoRoot, { group: "clients" }).map((p) => p.name);