Skip to content

feat(stdlib): add WorkspaceTool for workspace discovery#31

Merged
brunozoric merged 1 commit into
mainfrom
bruno/feat/list-workspaces
Jul 22, 2026
Merged

feat(stdlib): add WorkspaceTool for workspace discovery#31
brunozoric merged 1 commit into
mainfrom
bruno/feat/list-workspaces

Conversation

@brunozoric

Copy link
Copy Markdown
Contributor

Summary

  • Add WorkspaceTool to @webiny/stdlib/node as a drop-in replacement for the get-yarn-workspaces package
  • Walks up from a given cwd to find the nearest package.json with a workspaces field, resolves glob patterns using fast-glob.sync(), and returns { name, path }[] for each workspace
  • Supports both flat array (workspaces: ["packages/*"]) and Yarn's object format (workspaces: { packages: ["packages/*"] })
  • Zero new dependencies — uses fast-glob already in stdlib

Exports

Export Description
WorkspaceTool DI abstraction token ("Node/WorkspaceTool")
WorkspaceToolFeature Registers WorkspaceTool in singleton scope
createWorkspaceTool() Factory function for non-DI usage
listWorkspaces(params?) Standalone function — direct replacement for getYarnWorkspaces()
WorkspaceRootNotFoundError Thrown when no root with workspaces is found
WorkspaceInfo { name: string, path: string }
ListWorkspacesParams { cwd?: string }

Migration from get-yarn-workspaces

// Before
import getYarnWorkspaces from "get-yarn-workspaces";
const paths: string[] = getYarnWorkspaces();

// After
import { listWorkspaces } from "@webiny/stdlib/node";
const workspaces = listWorkspaces(); // { name, path }[]
const paths = workspaces.map(w => w.path); // if you need string[] only

Test plan

  • Flat array workspaces format
  • { packages: [] } object format
  • Skips directories without package.json
  • Falls back to folder name when package.json has no name field
  • Walks up directory tree to find workspace root
  • Multiple glob patterns
  • Empty result when patterns match nothing
  • Throws WorkspaceRootNotFoundError when no workspace root found
  • Defaults cwd to process.cwd()
  • Returns absolute paths
  • Factory function (createWorkspaceTool)
  • Standalone function (listWorkspaces)

12 tests added, 0 existing tests modified. Full pre-commit chain passes.

Drop-in replacement for the get-yarn-workspaces package. Walks up from
a given directory to find the nearest package.json with a workspaces
field, resolves glob patterns with fast-glob, and returns workspace
metadata ({ name, path }). Supports both flat array and Yarn's
{ packages: [] } formats.

Exports: WorkspaceTool (DI), WorkspaceToolFeature, createWorkspaceTool,
listWorkspaces (standalone), WorkspaceRootNotFoundError.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brunozoric brunozoric self-assigned this Jul 22, 2026
@brunozoric
brunozoric merged commit 3b7c40e into main Jul 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant