Discovers workspaces defined in the nearest root package.json. Walks up from a given directory to find a package.json with a workspaces field, then resolves the glob patterns to return workspace metadata. Supports both flat array (workspaces: ["packages/*"]) and Yarn's object format (workspaces: { packages: ["packages/*"] }). Drop-in replacement for the get-yarn-workspaces package.
list(params?: ListWorkspacesParams): WorkspaceInfo[]— List all workspace directories. Returns{ name, path }for each workspace. ThrowsWorkspaceRootNotFoundErrorif no rootpackage.jsonwithworkspacesis found.
ListWorkspacesParams—{ cwd?: string }. Directory to start searching from. Defaults toprocess.cwd().WorkspaceInfo—{ name: string, path: string }. Package name from the workspace'spackage.json(falls back to folder name), and absolute path.WorkspaceRootNotFoundError— Thrown when nopackage.jsonwith aworkspacesfield is found walking up fromcwd.
import { Container } from "@webiny/di";
import { WorkspaceTool, WorkspaceToolFeature } from "@webiny/stdlib/node";
const container = new Container();
WorkspaceToolFeature.register(container);
const tool = container.resolve(WorkspaceTool);
const workspaces = tool.list({ cwd: "/path/to/monorepo" });
// [{ name: "@scope/pkg-a", path: "/path/to/monorepo/packages/pkg-a" }, ...]import { createWorkspaceTool } from "@webiny/stdlib/node";
const tool = createWorkspaceTool();
const workspaces = tool.list();import { listWorkspaces } from "@webiny/stdlib/node";
const workspaces = listWorkspaces({ cwd: "/path/to/monorepo" });
// [{ name: "@scope/pkg-a", path: "/path/to/monorepo/packages/pkg-a" }, ...]