Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: usage of potentially wrong melos version during script execution #783

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bspinner
Copy link

@bspinner bspinner commented Oct 29, 2024

Description

See long comment at https://github.com/invertase/melos/pull/783/files#diff-35f09e1c67ac8d5bd4889489c6ce0f6dc320b1491828444f2eca21c0f8ff765cR343 :)

Type of Change

  • feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

Copy link

docs-page bot commented Oct 29, 2024

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/melos~783

Documentation is deployed and generated using docs.page.

@CLAassistant
Copy link

CLAassistant commented Oct 29, 2024

CLA assistant check
All committers have signed the CLA.

@bspinner bspinner force-pushed the fix/executable_path_handling branch from daa7230 to c040977 Compare October 29, 2024 13:10
@bspinner bspinner changed the title Fixes use of potentially wrong melos version during script execution Fix: usage of potentially wrong melos version during script execution Oct 29, 2024
@bspinner bspinner changed the title Fix: usage of potentially wrong melos version during script execution fix: usage of potentially wrong melos version during script execution Oct 29, 2024
Copy link
Collaborator

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick glance it looks like a sound idea!

/// i.e. usually the globally activated version. If there is one.
///
/// This can cause issues when melos is started with `dart run melos`,
/// which will prefer the melos version specified via (dev_)dependencies.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Melos should always run scripts etc with the version that is defined in dev_dependencies, even if it is started directly from the version on path.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for the quick review.

Is this a future enhancement request or already implemented? 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overarching goal of this PR is to eliminate ambiguity and surprises in the build process of Dart/Flutter applications. In line with that, I believe it would be ideal for Melos to behave in a consistent and predictable way.

Here’s what I think could be considered "unexpected" behavior:

  • If Melos uses different versions of itself for script execution (i.e. for subprocesses of itself)
    • This will be addressed with this PR!? :)
  • If Melos silently switches to a different version at startup (i.e., in the main process)
    • This could be especially challenging when intentionally testing a specific version.
    • Perhaps an optional strict mode (e.g., for CI environments) could help, where Melos would verify that its version matches the one specified in pubspec.lock.
      • The version in dev_dependencies might only define a minimum version, which wouldn’t fully address this, as you likely know as well. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a future enhancement request or already implemented? 🙂

It's already implemented, try pinning you melos version to an older version an see what happens. :)

The version in dev_dependencies might only define a minimum version, which wouldn’t fully address this, as you likely know as well. :)

If one wants a specific version of melos, why not just pin the version in pubspec? I don't see the need for any separate feature for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spydon Am I correct in understanding that you're unhappy with the comment in the code? If so, could you suggest a better or more accurate phrasing? :)

Additionally, if the only remaining blocker for merging is the failing tests, I’d be happy to look into the breaking cod – given it's likely the changes will be merged. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if this is really needed/wanted, if I haven't misunderstood what this PR is trying to achieve.
If you run dart run melos --version you'll get the version specified in pubspec.yaml, which is the intentional behavior, no matter what melos binary that started it, the scripts should run with the melos version specified in the pubspec by the constraints.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bspinner any updated on this? Am I correct in that this PR would change so that it doesn't run with the melos version specified in the root pubspec?

Copy link
Author

@bspinner bspinner Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spydon Sorry for the unexpected delay. Life is full of surprises... :|

According to my very basic knowledge of this codebase, this change does not interfere with anything happening during melos' start.
All it does is using the absolute path to the melos binary already running. So when melos starts itself another time for a script/command, the same melos binary will be used.
So this PR's changes apply to starting a subprocess, not melos' startup and checks. :)

Doing this differently could lead to heisenbugs, as behaviour could differ between directly executing a command and executing a command nested in another melos command.
Because which binary is used for the nested command execution currently depends on the user's shell environment.

Furthermore, it enables usage of melos in situations in which you don't have melos in your environmental PATH (which is the case in one of our CI environments).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Life is full of surprises...

It is indeed, I hope you're all good!

Alright, that sounds like it makes sense, could you just add a test that runs melos --version inside of a script and checks that it is the same melos version as specified in the pubspec, if you pin a version in there.

@bspinner
Copy link
Author

@spydon I'm unsure if this could/should/must be applied to other places as well, since this is the first time I had a look at the code.

@bspinner bspinner marked this pull request as ready for review October 29, 2024 14:28
@spydon
Copy link
Collaborator

spydon commented Jan 10, 2025

I'll close this for now since I don't think it will properly take the version in dev_depenendencies into consideration, if it does we can re-open it.

@spydon spydon closed this Jan 10, 2025
@spydon spydon reopened this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants