fvm icon indicating copy to clipboard operation
fvm copied to clipboard

[BUG] Does not use .fvmrc of parent directory on Windows 11

Open saibotma opened this issue 5 months ago • 3 comments

To Reproduce Steps to reproduce the behavior:

  • Make sure that Flutter is NOT added to the path, because otherwise fvm will use Flutter from path in the example below.
  • Create a directory fvm_test
  • cd into that directory and create a subdirectory sub
  • cd ..
  • Run fvm use 3.16.9 (or any other flutter version)
  • fvm_test now contains the .fvm directory and .fvmrc file.
  • Running fvm flutter doctor -v works without any problems, showing that flutter from the fvm cache is used.
  • cd into any of the sub dir and run fvm flutter doctor -v there.
  • Notice that is shows error message "'flutter' is not recognized as an internal or external command, operable program or batch file"

Expected behavior fvm flutter should use the flutter version specified in its parent .fvmrc file.

Logs Please provide the verbose logs by running --verbose after the command.

Desktop (please complete the following information):

  • OS: Windows 11
  • FVM Version 3.0.10
  • If Windows: Which Powershell are you using? 5.1.22621.2506

Additional context Running the same commands on Mac shows the expected behaviour.

saibotma avatar Feb 27 '24 15:02 saibotma

@saibotma This is because fvm is looking for a config and a pubspec to determine the configuration; this helps with constraints and dependency checking.

I was able to replicate this on Mac also by doing the following:

$ mkdir fvm_test
$ cd fvm_test
$ fvm use stable --force
$ mkdir sub_test
$ cd sub_test
$ fvm --verbose flutter --version

The last command indicates it's running on the flutter sdk found the path. After adding a pubspec.yaml, it behaved correctly.

Let me know what the use case is so I can understand.

leoafarias avatar Feb 27 '24 15:02 leoafarias

The example I used is a simplified one. This happened in a repository containing two flutter projects, each having pubspec.yaml and all other files required by flutter. Having a missing pubspec.yaml is not the reason, for sure.

I also tried executing your example on my Mac. This is the output of fvm --verbose flutter --version:

Argument information:
  Top level options:
  - verbose: true

Command: flutter

fvm: Running Flutter SDK from version stable

Starting to update environment variables...

Running: /Users/tobias/fvm/versions/stable/bin/flutter

Flutter 3.19.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision abb292a07e (7 days ago) • 2024-02-20 14:35:05 -0800
Engine • revision 04817c99c9
Tools • Dart 3.3.0 • DevTools 2.31.1

Contrary to your observations, this is running using Flutter provided by fvm and not from path. Can you share your output, please?

saibotma avatar Feb 27 '24 16:02 saibotma

I followed the initial instructions which caused the behavior I described. Will mark as a bug based on the information you provided so I can take a look.

leoafarias avatar Feb 27 '24 16:02 leoafarias

I also logged a ticket for this, but it got closed... https://github.com/leoafarias/fvm/issues/624 the docs indeed say it should go up in the folder and that is also how it worked on version 2 https://fvm.app/documentation/getting-started/faq#monorepo-support We have about 20 packages and example apps in one repo, I was waiting for a fix but now it looks like you cannot install version 2 anymore with brew

krispypen avatar Mar 05 '24 09:03 krispypen

@krispypen this issue is related to windows as it works in Mac based on the initial comment.

You need to have a pubspec at the root of the monorepo.

leoafarias avatar Mar 05 '24 12:03 leoafarias

oh ok, why would you need a pubspec at the root of the monorepo? is that somewhere documented? 🙏

krispypen avatar Mar 05 '24 14:03 krispypen

I was able to replicate the issue mentioned by @saibotma

leoafarias avatar Mar 05 '24 15:03 leoafarias

@saibotma I was able to reproduce, but than noticed that .fvmrc was not setup on the root of the project. If the root of the project, has a pubspec.yaml. One thing based on the previous comment.

The root of the project needs to have a .fvmrc and a pubspec.yaml. If those 2 things exist, I am not able to reproduce the error.

Here are the commands I ran.

  1. mkdir test_dir
  2. cd test_dir
  3. Create pubspec.yaml with name: test_dir needed for parsing error.
  4. fvm use stable
  5. .fvm and .fvmrc created within test_dir
  6. mkdir sub1
  7. cd sub1
  8. Create pubspec.yaml with name: sub
  9. fvm flutter --version this outputs stable sdk
  10. cd..
  11. fvm use beta
  12. fvm flutter --version outputs beta sdk
  13. cd sub1
  14. fvm flutter --version also outputs beta sdk

After reading the messages again @saibotma can you confirm that there is a pubspec also at the root of the file? You need a pubspec, even with just a name to determine that is the root of a project.

leoafarias avatar Mar 05 '24 19:03 leoafarias

@leoafarias Thanks for the detailed response. Yeah, did not know that I had to put a pubspec.yaml in the root of the project. I can confirm that it works this way, though.

I was confused, because it works on Mac without pubspec in the root dir, but does not on Windows. I think this is worthy of keeping this issue open.

saibotma avatar Mar 07 '24 16:03 saibotma

I added a warning if this happens on the latest version. I wonder if there was a .fvmrc in the sub1 on the Mac.

leoafarias avatar Mar 07 '24 20:03 leoafarias

Thanks for adding the warning. No, there was no .fvmrc in the sub1 folder on the Mac. There seems to be different behaviour on both platforms.

saibotma avatar Mar 08 '24 10:03 saibotma

I would like to understand why the pubspec is required. This sounds like a small workaround to me or am I wrong? The use case for this is for example a mono repo. We might have a folder that contains several packages and flutter apps that should use one fvm config/flutter version.

Imaging a structure like this:

core/
ui_shared/
my_branding_app_core/
  .fvmrc --> configures flutter 3.19
  my_branding_app_1/pubspec.yaml
  my_branding_app_2/pubspec.yaml
  my_branding_app_2/pubspec.yaml
my_web_branding_app/
  .fvmrc --> configures flutter 3.13 due to some bug we don't want to upgrade
  my_web_branding_app_1/pubspec.yaml
  my_web_branding_app_1/pubspec.yaml
  my_web_branding_app_1/pubspec.yaml

Of course I could do that:

my_web_branding_app/
  .fvmrc
  pubspec.yaml
  my_web_branding_app_1/pubspec.yaml
  my_web_branding_app_1/pubspec.yaml
  my_web_branding_app_1/pubspec.yaml

But why? This worked previously and the only reason for adding the pubspec would be to get fvm to work as it previously did 🤔 Are there any adventages for having a root pubspec.yaml file?

JulianBissekkou avatar Mar 21 '24 17:03 JulianBissekkou

@JulianBissekkou, good question. The main issue that this resolves is by being explicit about the root directory you want to resolve the file from. There were many cases where .fvmrc was configured in a different directory than the project, causing inconsistencies in user expectations.

Another future reason for this change is that .fvm also performs constraint checking, which helps maintain consistent constraints across all projects. There are a few other benefits as well, but these are the main reasons.

Let me know if you have suggestions on how to improve this.

leoafarias avatar Mar 21 '24 20:03 leoafarias

I work a lot with mono repos that have the mentioned structure and it would be nice if fvm would give me the ability to have more flexibility. If I remember correctly we used to have something like fvm install --force if you install the flutter sdk in a folder that has no pubspec.yaml.

Warning the user about potential problems and forcing certain operations with a --force flag sounds like a good compromise to me. The problems of most users will be caught, but we can still proceed if we know what we are doing.

We felt like a feature that we previously used was taken away and we are now locked with an older version of fvm :/

I think in general its quite hard to meet everybodys expectations when it comes to designing a library and the final decision is totally up to you. Those features have to maintained and I don't know how much effort that is. However, from my perspective more and more people are moving towards a more modular project structure since flutter is also getting used by bigger companies and therefore bigger apps. Is that also true for most developers that use fvm? I don't know 🤷🏽

No matter how you decide in the end, I would recommend having a guide on how to use fvm in mono repos or repositories with multiple packages. 👍🏽 I still have a few questions on how those feature like constraint check might work, how my pubspec.yaml should look like and if my IDE will pick up the correct configuration 🤔

JulianBissekkou avatar Mar 22 '24 08:03 JulianBissekkou

Adding a root pubspec.yaml file in a monorepo project seems to break running tests with intellIJ based IDEs as it will try to use the dependencies from this file instead of the child project

NicolaVerbeeck avatar Mar 22 '24 08:03 NicolaVerbeeck

@JulianBissekkou can you open an issue from this, so I can revisit?

leoafarias avatar Mar 22 '24 14:03 leoafarias

I don't think this is required anymore since in the recent release the constraint was removed. Thanks for fast response and listening to the community 👍🏽

JulianBissekkou avatar Apr 09 '24 05:04 JulianBissekkou