invertase / melos

πŸŒ‹ A tool for managing Dart projects with multiple packages. With IntelliJ and Vscode IDE support. Supports automated versioning, changelogs & publishing via Conventional Commits.
https://melos.invertase.dev/~melos-latest
Apache License 2.0
1.19k stars 206 forks source link

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

Open mugbug opened 4 months ago

mugbug commented 4 months ago

Is there an existing feature request for this?

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

jifferon commented 2 months ago

This feature is really needed

spydon commented 2 months ago

@mugbug What is the reason for not using the automatic resolution of that package, it looks like it is within your monorepo?