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

[Feature Request] fvm exec #317

Closed
2ZeroSix opened this issue Jun 12, 2021 · 8 comments · Fixed by #399
Closed

[Feature Request] fvm exec #317

2ZeroSix opened this issue Jun 12, 2021 · 8 comments · Fixed by #399
Labels
enhancement New feature or request

Comments

@2ZeroSix
Copy link

2ZeroSix commented Jun 12, 2021

Describe the solution you'd like
command to execute any command with environment set up for flutter sdk found by fvm
fvm exec

Describe alternatives you've considered
currently it's accomplished by overriding PATH like this

export PATH="$(pwd)/.fvm/flutter_sdk/bin:$PATH"

but this code is not portable between windows and posix systems

Additional context
many repositories use custom scripts to maintain repository/infrastructure, setup something specific or add shortcuts for some flutter/dart commands

It would become similar to what bundler does in bundle exec

@2ZeroSix 2ZeroSix added the enhancement New feature or request label Jun 12, 2021
@leoafarias
Copy link
Owner

@2ZeroSix Do you mind going into a bit more detail on this, right now we have the spawn command which is made to exec commands on particular flutter versions. Does that solve you problem? https://fvm.app/docs/guides/running_flutter/#spawn-command

@2ZeroSix
Copy link
Author

2ZeroSix commented Jun 14, 2021

  • spawn execute a specific command in flutter cli
  • exec would allow to execute arbitrary command in environment of flutter found by fvm

simplified example of common use case in proprietary projects:

(when os is always posix)
we could have some script my_custom_script_to_accomplish_task_with_many_commands.sh

flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs --verbose
flutter analyze
flutter test
  • without fvm exec
    PATH="$(pwd)/.fvm/flutter_sdk/bin:$PATH" ./my_custom_script_to_accomplish_task_with_many_commands.sh
  • with fvm exec
    fvm exec ./my_custom_script_to_accomplish_task_with_many_commands.sh

real life example of open source repo

melos commands in FlutterFire repo: https://github.com/FirebaseExtended/flutterfire/blob/master/melos.yaml
they does support both windows and posix systems

  • without fvm exec
    shell:

    PATH="$(pwd)/.fvm/flutter_sdk/bin:$PATH" melos lint:all

    batch:

    set PATH="C:\absolute\path\to\project\.fvm\flutter_sdk;%PATH%"
    melos lint:all

    powershell:

    $env:Path = "C:\absolute\path\to\project\.fvm\flutter_sdk;" + $env:Path
    melos lint:all
  • with fvm exec anywhere

    fvm exec melos lint:all
    

@leoafarias
Copy link
Owner

@2ZeroSix Sorry for the delay, there seems to be a similar conversation to helping solve this on Melos through invertase/melos#81, I am not opposed to the idea, but not sure when I will be able to get to it, is that something you would like to do a PR for?

@leoafarias
Copy link
Owner

@2ZeroSix I took a better look at it, and I think all the pieces are there to be able to accomplish this, its very similar to the fvm flutter command. I will go ahead and give it a try and if you can help me test and review it would be great

@festelo
Copy link

festelo commented Aug 17, 2021

You can also create small scripts with names dart and flutter which will forward your commands to fvm:

file dart

#!/bin/bash
fvm dart "$@"

file flutter

#!/bin/bash
fvm flutter "$@"

Add these scripts to your path and you will be able to use flutter and dart commands as usually, so you can directly execute your my_custom_script_to_accomplish_task_with_many_commands.sh.

This is useful when you only have flutter installed from fvm.

@sunlimiter
Copy link

mac os

/Users/.pub-cache/bin/melos

#!/usr/bin/env sh
# This file was created by pub v2.16.1.
# Package: melos
# Version: 1.4.0
# Executable: melos
# Script: melos
if [ -f /Users/litianyi/.pub-cache/global_packages/melos/bin/melos.dart-2.16.1.snapshot ]; then
  dart "/Users/litianyi/.pub-cache/global_packages/melos/bin/melos.dart-2.16.1.snapshot" "$@"
  # The VM exits with code 253 if the snapshot version is out-of-date.	
  # If it is, we need to delete it and run "pub global" manually.	
  exit_code=$?	
  if [ $exit_code != 253 ]; then	
    exit $exit_code	
  fi	
  fvm flutter pub global run melos:melos "$@"
else
  fvm flutter pub global run melos:melos "$@"
fi

dart pub global run melos:melos => fvm flutter pub global run melos:melos

@festelo good

@leoafarias
Copy link
Owner

Prerelease version on https://pub.dev/packages/fvm/versions/2.3.0-dev.0 would appreciate some testing on any of the use cases mentioned. Will leave this open for comments

@leoafarias leoafarias reopened this Mar 11, 2022
@leoafarias
Copy link
Owner

This has been deployed live on 2.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants