Closed wujek-srujek closed 6 months ago
You shouldn't have a package/app in the root of the monorepo, that's where the workspace pubspec lives and it should not be mixed with the dependencies of your main app/package.
I recommend that you use a directory structure like this:
mono_repo
βββ apps
βΒ Β βββ my_app
βΒ Β βββ pubspec.yaml
βββ packages
βΒ Β βββ my_package
βΒ Β βββ pubspec.yaml
βββ melos.yaml
βββ pubspec.yaml
It would be very helpful if this were mentioned in the Melos documentation somewhere, like a 'recommended repository structure' section. AFAIK as I was starting off with 3.1.1 the documentation didn't mention this. To the contrary, this does imply that having a Melos-managed project in the root of the monorepo is a normal thing to do - it mentions specifying .
in the packages
list.
Yeah, I agree that this should be updated, and with a suggested directory structure.
It is now mentioned in the documentation.
Is there an existing issue for this?
Version
3.1.1
Description
I have a project with a root package (the main app) and some packages in the
packages
folder, the main app uses paths to the packages. When I invokeflutter pub get
in all of the packages, and then in the main package,git diff
shows me nothing.Now I add Melos, the only changes are:
melos: ^3.1.1
to dev_dependencies.melos.yaml
.Here is the diff (
git diff --staged .
):Calling
melos bootstrap
adds quite some stuff topubpec.lock
, but surprisingly it also downgrades one of the transitive dependencies:Without Melos, the
file
dependency is coming throughbuild_runner
->glob
(^2.0.0: https://github.com/dart-lang/build/blob/master/build_runner/pubspec.yaml#L28) ->file
(file: '>=6.1.3 <8.0.0': https://github.com/dart-lang/glob/blob/master/pubspec.yaml#L12) and is set to7.0.0
as of right now; introducing Melos downgrades it because of this: https://github.com/invertase/melos/blob/main/packages/melos/pubspec.yaml#L24In this case it will all work, and it is also easy to fix for you - you can very likely update the version specification to also allow ^7.0.0, just like
glob
does; but in the general case, is it a good idea for themelos
dependency, which is basically 'just' a binary, to force package downgrades?Now imagine (or follow the 'steps to reproduce' section) that I actually have a dependency on
file: ^7.0.0
in mypubspec.yaml
- the project will fail to build because of Melos interfering.Steps to reproduce
Create a new Flutter project and replace
pubspec.yaml
with this:flutter pub get
- thefile
dependency is set to7.0.0
as of right now.melos bootstrap
- thefile
dependnecy is downgraded to6.1.4
as of now.file: ^7.0.0
topubspec.yaml
.melos bootstrap
- this fails due toflutter pub get
failure with the following cause:Expected behavior
Melos, which is an external tool, doesn't influence the dependencies in my project. For example, I don't expect, say,
fvm
to be in my pubspec and force versions upon me.Screenshots
No response
Additional context and comments
I do understand why you want to put it into
pubspec.yaml
(make sure developers use the same version consistently), but the cost is great as it messes around with project dependencies, and there are solutions for this to not be the case.I can imagine a different strategy for Melos:
.melos.version
(or similar) which contains the version to use in the project.melos
binary is a shim that can check this file and make sure there is a locally installed version that corresponds to it: if it exists in its 'cache' it uses it, if not, it downloads it and uses it..melos.version
file, when themelos
binary is called, it will notice a new version and look for it locally and download and cache if needed.This would allow project developers to share the version of Melos, but do so in a way that doesn't interfere with the dependencies of their project. This strategy is also nothing new, this is how tools like Gradle Wrapper (https://docs.gradle.org/current/userguide/gradle_wrapper.html), Maven Wrapper (https://maven.apache.org/wrapper/) and others work, FVM does something similar with its
.fvm/flutter_sdk
file.I guess this bug could also be considered a feature/improvement request.