melos icon indicating copy to clipboard operation
melos copied to clipboard

request: Smarter support for `path` dependencies on shared-dependencies

Open mugbug opened this issue 1 year ago • 2 comments

Is there an existing feature request for this?

  • [X] I have searched the existing issues.

Command

No response

Description

I expect melos' shared-dependencies feature to be able to understand the path reference I've set for a given dependency and use it based on the reference of the melos.yaml file. So, if my local package is under packages/core/my_local_package, I want to be able to set something like the following and it will adapt the path value based on the folder the package using this dependency is

# melos.yaml

# ...
command:
  bootstrap:
    dependencies:
      my_local_package:
        path: packages/core/my_local_package

Reasoning

When using shared dependencies feature, where one of the dependencies is referenced using path relation, and considering a monorepo structure where we have multiple levels of folders with packages in each of those, we can't just copy-paste the path reference defined inside the melos.yaml file. For instance, consider the following scenario:

Folder structure:

.
├── apps
│   ├── app1
│   └── app2
├── melos.yaml
└── packages
    ├── context1
    ├── context2
    ├── core
    │   └── my_local_package
    ├── features
    │   ├── feature_package1
    │   └── feature_package2
    ├── package1
    └── package2

If I define a library foo to be shared between all of those packages:

# melos.yaml

# ...
command:
  bootstrap:
    dependencies:
      my_local_package:
        path: packages/core/my_local_package # this is clear but won't work for any package
        path: ../core/my_local_package # this will only work for `package1` and `package2`
        path: ../../core/my_local_package # this will only work for `feature_package1` and `feature_package2`

We can't get a path to set that would work for all packages with that local dependency.

Additional context and comments

We probably do something similar with melos bs while creating the pubspec_overrides.yaml file, and I'm not sure shared-dependencies is the best feature for this tbh

mugbug avatar Jul 22 '24 12:07 mugbug