Skip to content

Conversation

@MeandNi
Copy link
Contributor

@MeandNi MeandNi commented Nov 15, 2025

Description

This PR adds support for recursively discovering packages in nested workspaces, fixing the issue where fvm dart pub workspace list and fvm dart run melos list produce inconsistent results.

Problem

Currently, when a workspace root directory itself contains a workspace: configuration in its pubspec.yaml, melos does not recursively discover the packages listed in that nested workspace. This causes fvm dart run melos list to have different results compared to fvm dart pub workspace list.

Example

In a monorepo structure like:

packages/
  base/
    ui/                        # workspace root with workspace: ['core', 'components']
      pubspec.yaml             # defines workspace: ['core', 'components']
      core/                    # package
        pubspec.yaml
      components/              # package
        pubspec.yaml
      example/                 # nested workspace with example
        pubspec.yaml           # defines workspace: ['example']
        example/               # example package
          pubspec.yaml

Current behavior:

  • fvm dart pub workspace list discovers all packages including nested ones: ui, core, components, example
  • fvm dart run melos list only discovers the workspace root: packages/base/ui

This inconsistency makes it difficult to manage packages in monorepos with nested workspace structures.

Solution

  • Modified _resolvePubspecFiles to detect and recurse into nested workspaces
  • Added _isWorkspacePubspec helper to check if a pubspec.yaml defines a workspace
  • Added _discoverNestedWorkspacePackages to recursively discover packages in nested workspaces
  • Added comprehensive test cases covering various nested workspace scenarios

The implementation now matches dart pub workspace list behavior by recursively discovering all packages in nested workspaces.

Changes

  • packages/melos/lib/src/package.dart: Added recursive workspace discovery logic (353 lines added)
  • packages/melos/test/package_test.dart: Added 5 new test cases for nested workspace discovery

Testing

All existing tests pass, and 5 new test cases have been added:

  • ✅ Basic nested workspace discovery
  • ✅ Deeply nested workspaces (multiple levels)
  • ✅ Nested workspaces with example packages
  • ✅ Ignore patterns for nested packages
  • ✅ Complex nested workspace structures

Verification

After this fix, fvm dart run melos list and fvm dart pub workspace list will produce consistent results for nested workspace structures.

Related

Fixes the inconsistency between melos list and dart pub workspace list commands when dealing with nested workspaces.

Type of Change

  • feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

This commit adds support for recursively discovering packages in nested
workspaces, fixing the issue where melos would not discover packages
nested within workspace root directories.

Changes:
- Modified _resolvePubspecFiles to detect and recurse into nested workspaces
- Added _isWorkspacePubspec helper to check if a pubspec.yaml defines a workspace
- Added _discoverNestedWorkspacePackages to recursively discover packages in nested workspaces
- Added comprehensive test cases for nested workspace discovery

Fixes the issue where packages like forui_example, forui_assets, etc.
were not discovered when they were nested within a workspace root.

Test cases cover:
- Basic nested workspace discovery
- Deeply nested workspaces (multiple levels)
- Nested workspaces with example packages
- Ignore patterns for nested packages
- Complex nested workspace structures
@docs-page
Copy link

docs-page bot commented Nov 15, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/melos~968

Documentation is deployed and generated using docs.page.

@CLAassistant
Copy link

CLAassistant commented Nov 15, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! This is a breaking change, because now packages that are listed under another nested workspace will be included in run etc even though they are not listed in the root workspace list, which serves to show which packages that Melos should handle currently. So I think we need to introduce a bool config, like discoverNestedWorkspaces that checks whether the user wants the new behaviour.

@MeandNi
Copy link
Contributor Author

MeandNi commented Nov 16, 2025

Thanks for your contribution! This is a breaking change, because now packages that are listed under another nested workspace will be included in run etc even though they are not listed in the root workspace list, which serves to show which packages that Melos should handle currently. So I think we need to introduce a bool config, like discoverNestedWorkspaces that checks whether the user wants the new behaviour.

done.

@github-actions github-actions bot added the needs attention OP has responded and the issue needs looking at again. label Nov 16, 2025
Copy link
Collaborator

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@spydon spydon enabled auto-merge (squash) November 17, 2025 09:35
@spydon spydon merged commit d15b553 into invertase:main Nov 18, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs attention OP has responded and the issue needs looking at again.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants