Skip to content

feat: auto-discover workspace packages#13

Merged
bennypowers merged 3 commits into
mainfrom
feat/auto-discover-workspaces
Jan 14, 2026
Merged

feat: auto-discover workspace packages#13
bennypowers merged 3 commits into
mainfrom
feat/auto-discover-workspaces

Conversation

@bennypowers

@bennypowers bennypowers commented Jan 14, 2026

Copy link
Copy Markdown
Owner

Closes #3

Summary by CodeRabbit

  • New Features

    • Support for multiple workspace formats in package.json (array or object)
    • Automatic discovery of workspace packages when none are explicitly configured
    • Explicit workspace configuration overrides automatic discovery
  • Tests

    • Added comprehensive tests for workspace parsing, discovery, resolver behavior, and override scenarios

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds workspace auto-discovery: package.json now preserves raw workspaces JSON and exposes WorkspacePatterns/HasWorkspaces. New discovery expands simple workspace globs, parses workspace package.json files, and the resolver auto-applies discovered workspace packages when none are explicitly configured. Tests added for parsing and discovery.

Changes

Cohort / File(s) Summary
PackageJSON Format Support
packagejson/packagejson.go
Replace Workspaces []string with RawWorkspaces json.RawMessage; add workspacesObjectFormat, WorkspacePatterns() and HasWorkspaces() to read array or object workspaces.
PackageJSON Tests
packagejson/packagejson_test.go
Add tests (TestWorkspacePatterns, TestHasWorkspaces) covering array/object/missing/empty workspace shapes and Parse integration.
Workspace Discovery Implementation
resolve/workspace.go
New functions: DiscoverWorkspacePackages(), expandWorkspacePattern(), parseWorkspacePackage() to read patterns, expand simple globs (e.g., packages/*), and parse workspace package.json into WorkspacePackage entries.
Workspace Discovery Tests
resolve/resolve_test.go
Add TestDiscoverWorkspacePackages table-driven tests for various patterns, object format, scoped patterns, missing workspaces, and multi-pattern expansion.
Resolver Integration
resolve/local/local.go
When no explicit workspacePackages configured, call DiscoverWorkspacePackages(); if packages found, apply WithWorkspacePackages(discovered) and resolve in workspace mode; log warnings on discovery errors.
Resolver Integration Tests
resolve/local/local_test.go
Add TestResolverAutoDiscoverWorkspaces and TestResolverExplicitWorkspacesOverrideAutoDiscovery to verify auto-discovery and explicit override behavior.
Resolver Check Update
resolve/resolve.go
Replace direct len(pkg.Workspaces) > 0 check with pkg.HasWorkspaces() for workspace-root detection.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Resolver as Resolver (local.go)
    participant Parser as PackageJSON Parser
    participant Discovery as Workspace Discovery
    participant FS as FileSystem
    participant ResolverCore as Workspace Resolver

    Caller->>Resolver: Resolve(rootDir)
    Resolver->>Parser: Parse root package.json
    Parser-->>Resolver: PackageJSON (with RawWorkspaces)

    alt No explicit workspacePackages
        Resolver->>Discovery: DiscoverWorkspacePackages(fsys, rootDir)
        Discovery->>Parser: WorkspacePatterns()
        Parser-->>Discovery: []patterns

        loop each pattern
            Discovery->>FS: expandWorkspacePattern(rootDir, pattern)
            FS-->>Discovery: []directories

            loop each directory
                Discovery->>FS: Read `<dir>/package.json`
                FS-->>Discovery: package.json bytes
                Discovery->>Parser: parseWorkspacePackage(dir)
                Parser-->>Discovery: WorkspacePackage (name, path)
            end
        end

        Discovery-->>Resolver: []WorkspacePackage
        Resolver->>Resolver: WithWorkspacePackages(discovered)
        Resolver->>ResolverCore: resolveWorkspace()
    end

    ResolverCore-->>Caller: Import map (including workspaces)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I sniffed the globs and hopped with glee,

packages/* and object tree,
I read each json, name in sight,
stitched them into maps by night,
Hooray — auto-workspaces, whee! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding automatic discovery of workspace packages from the workspaces field in package.json.
Linked Issues check ✅ Passed The PR implements all requirements from issue #3: workspaces field parsing (array/object formats), glob expansion, workspace package discovery, and auto-discovery in single-package mode.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing workspace auto-discovery as specified in issue #3; no unrelated functionality is introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4eba0e3 and b39eb1c.

📒 Files selected for processing (1)
  • packagejson/packagejson.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • packagejson/packagejson.go

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bennypowers bennypowers merged commit f2170b3 into main Jan 14, 2026
3 checks passed
@bennypowers bennypowers deleted the feat/auto-discover-workspaces branch January 14, 2026 15:59
@coderabbitai coderabbitai Bot mentioned this pull request Jan 14, 2026
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.

feat: auto-discover workspace packages from workspaces field

1 participant