Commit d15b553
authored
feat: recursively discover packages in nested workspaces (#968)
## 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
- [x] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [ ] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [x] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [ ] 🗑️ `chore` -- Chore1 parent 4457e07 commit d15b553
File tree
7 files changed
+489
-2
lines changed- docs/configuration
- packages/melos
- lib/src
- command_runner
- test
7 files changed
+489
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
101 | 144 | | |
102 | 145 | | |
103 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
| 537 | + | |
537 | 538 | | |
538 | 539 | | |
539 | 540 | | |
| |||
543 | 544 | | |
544 | 545 | | |
545 | 546 | | |
| 547 | + | |
546 | 548 | | |
547 | 549 | | |
548 | 550 | | |
| |||
621 | 623 | | |
622 | 624 | | |
623 | 625 | | |
| 626 | + | |
624 | 627 | | |
625 | 628 | | |
626 | 629 | | |
| |||
637 | 640 | | |
638 | 641 | | |
639 | 642 | | |
640 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
641 | 757 | | |
642 | 758 | | |
643 | 759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| |||
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
378 | 386 | | |
379 | 387 | | |
380 | 388 | | |
| |||
404 | 412 | | |
405 | 413 | | |
406 | 414 | | |
| 415 | + | |
407 | 416 | | |
408 | 417 | | |
409 | 418 | | |
| |||
414 | 423 | | |
415 | 424 | | |
416 | 425 | | |
| 426 | + | |
417 | 427 | | |
418 | 428 | | |
419 | 429 | | |
420 | 430 | | |
421 | 431 | | |
422 | 432 | | |
423 | 433 | | |
| 434 | + | |
424 | 435 | | |
425 | 436 | | |
426 | 437 | | |
427 | 438 | | |
428 | 439 | | |
429 | 440 | | |
| 441 | + | |
430 | 442 | | |
431 | 443 | | |
432 | 444 | | |
| |||
579 | 591 | | |
580 | 592 | | |
581 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
582 | 598 | | |
583 | 599 | | |
584 | 600 | | |
| |||
615 | 631 | | |
616 | 632 | | |
617 | 633 | | |
| 634 | + | |
618 | 635 | | |
619 | 636 | | |
620 | 637 | | |
| |||
633 | 650 | | |
634 | 651 | | |
635 | 652 | | |
| 653 | + | |
636 | 654 | | |
637 | 655 | | |
638 | 656 | | |
| |||
645 | 663 | | |
646 | 664 | | |
647 | 665 | | |
| 666 | + | |
| 667 | + | |
648 | 668 | | |
649 | 669 | | |
650 | 670 | | |
| |||
0 commit comments