melos icon indicating copy to clipboard operation
melos copied to clipboard

fix: melos suggests update, even though I dont use Dart 3.8.0 yet

Open LenWdk opened this issue 7 months ago • 7 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Version

6.3.2

Description

Hey there,

First of all, thank you for melos, I really appreciate your work.

I noticed something potentially confusing regarding the update prompt:

~ ❯ dart --version
Dart SDK version: 3.7.2 (stable) (Tue Mar 11 04:27:50 2025 -0700) on "macos_arm64"
~ ❯ which melos
/Users/lenwdk/.pub-cache/bin/melos
~ ❯ melos --version
6.3.2
? There is a new version of melos available (6.3.3). Would you like to update? (Y/n) » 

It seems melos suggest to update to version 6.3.3. However, according to the changelog:

6.3.3
- FIX: Bump to SDK 3.8.0. ([5d7521fe](https://github.com/invertase/melos/commit/5d7521fe48d35f1e2905a2a147d8f1d363b1133d))

Updating to 6.3.3 would cause an SDK mismatch since my current Dart SDK version is 3.7.2, not 3.8.0.

Is this intentional?

Thanks!

Steps to reproduce

  1. Install Dart SDK version 3.7.2.
  2. Install melos version 6.3.2.
  3. Run melos --version

Expected behavior

I expect melos not to suggest for an update when the update would lead to an SDK version mismatch.

Screenshots

No response

Additional context and comments

No response

Other

  • [ ] I'm interested in working on a PR for this.

LenWdk avatar Jun 04 '25 08:06 LenWdk

@russellwheatley Is there a reason why you had made the choice to set minimal Dart SDK to 3.8.0 ? Because on documentation, you are talking about 3.6.0 minimum Dart SDK version, and in fact, this is 3.8.0.

If you have 2 flutter projects, one with 3.6.0 dart Version and another with 3.8.0 version, how can I activate the latest Melos version (7.0.0-dev.9) and use it as globally package for my both projects ?

MobiliteDev avatar Jul 10 '25 15:07 MobiliteDev

@MobiliteDev that is unrelated to the issue that you commented on. The docs mention that 3.6.0 is the min SDK to use pub workspaces, but if you look a bit above that you can see that ^3.8.0 is defined. We could definitely make that clearer.

I upgraded to 3.8.0 due to get some changes needed from that SDK version, but they are not user facing, so you can use ^7.0.0-dev.8 and you can use 3.6.0.

spydon avatar Jul 10 '25 15:07 spydon

Hi, I’ve prepared a patch + test for the Dart SDK version mismatch (3.6.0 vs 3.8.0). Let me know if you’d like the ready-to-apply fix.

akku1906 avatar Sep 30 '25 09:09 akku1906

Hi, I’ve prepared a patch + test for the Dart SDK version mismatch (3.6.0 vs 3.8.0). Let me know if you’d like the ready-to-apply fix.

Post the fix here if you have one. Don't spam issues and PRs with messages about potential fixes without any actual content. That makes it seem like you are doing some LLM scam or similar (and will get you banned).

spydon avatar Sep 30 '25 09:09 spydon

Here’s a minimal patch to skip suggestions when the candidate SDK constraint isn’t compatible with the current Dart SDK:

--- a/packages/melos/lib/src/commands/version.dart
+++ b/packages/melos/lib/src/commands/version.dart
@@
-    log.info('New version $newVersion available!');
+    final rootPubspec = Pubspec.parse(await File('pubspec.yaml').readAsString());
+    final currentSdk = Version.parse(Platform.version.split(' ').first);
+    final candidatePubspec = Pubspec.parse(await File('${pkg.path}/pubspec.yaml').readAsString());
+    final candidateSdk = candidatePubspec.environment?['sdk'] ?? VersionConstraint.any;
+
+    if (candidateSdk.allows(currentSdk)) {
+      log.info('New version $newVersion available!');
+    } else {
+      log.fine('Skipped suggesting $newVersion (requires $candidateSdk, current $currentSdk)');
+    }

Happy to open a draft PR if useful.

akku1906 avatar Sep 30 '25 10:09 akku1906

@akku1906 it looks like that is doing some unnecessary stuff, or at least you're not using all the variables, but the gist of it looks correct.

Happy to open a draft PR if useful.

Yes, please open a PR including tests and we can discuss more on the PR.

spydon avatar Sep 30 '25 13:09 spydon

Fix prepared in PR: https://github.com/invertase/melos/pull/948

akku1906 avatar Oct 01 '25 15:10 akku1906