-
Notifications
You must be signed in to change notification settings - Fork 220
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
feat: add support for Dart/Flutter SDK at custom sdkPath
#284
Conversation
Just a question - shouldn't a version manager reconfigure the PATH so that invoked scripts are already the fvm-correct invoked scripts? I ask because version managers come and go, there always ends up being more than one, and in the react-native ecosystem at least, after a while there were too many of them to support, and they finally scrapped supporting any of them and said "use your version manager before invoking our scripts, if the version manager is doing it's job on PATH correctly, our scripts will work with your version-manager's binaries..." |
I see your point, it's not great to make melos opinionated like that. It appears that just trying to wrap the melos command with |
Perhaps a better approach is like what #81 is asking for - instead of |
🤔 I see what you mean. It quickly becomes a rabbit-hole, in the node ecosystem it's typically to have 'nvm' to alter PATH, and 'auto-nvm' installed in combination with an .nvmrc or .node_version file in a directory and if auto-nvm sees it it will Not sure there even is a good way to do it - it's kind of all hacks 😆 - I think opening up path config vs having an opinion on a specific tool is better though, personally. I'm not deeply invested in this though - I just wanted to bring in other-ecosystem experience where other-ecosystem finally just threw up their hands and said "we're not supporting specific version managers" because of proliferation. If I can predict the future here, it's that |
Ok i've updated it to just pass an optional This way if you use fvm you can just set this in your melos.yaml: sdk_path: .fvm/flutter_sdk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, we assume that melos runs with the same version of Dart as the dart
tool that is invoked by Melos:
melos/packages/melos/lib/src/common/utils.dart
Lines 107 to 109 in 1fdff16
Version get currentDartVersion { | |
return Version.parse(currentPlatform.version.split(' ')[0]); | |
} |
currentDartVersion
needs to become a function that takes the sdk path, invokes dart --version
and parses its output.
@@ -123,6 +123,12 @@ abstract class MelosCommand extends Command<void> { | |||
'matches the other filters. The included packages skip --ignore ' | |||
'and --since checks.', | |||
); | |||
|
|||
argParser.addOption( | |||
filterOptionSdkPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this option should be a filter option. We could add a new GlobalOptions
object for which the argParser
is setup in setupGlobalOptionsParser
and is parsed in parseGlobalOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. What is a filter option supposed to be used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter options are used to select a subset of the packages in a workspace, for example to only bootstrap Flutter packages and not pure Dart packages you could use melos bootstrap --flutter
.
final execArgs = package.isFlutterPackage | ||
? ['flutter', ...pubGetArgs] | ||
: [if (utils.isPubSubcommand()) 'dart', ...pubGetArgs]; | ||
late final List<String> execArgs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just this?
final execArgs = [
if (package.isFlutterApp)
'${workspace.sdkPath}flutter'
else if (utils.isPubSubcommand(sdkPath: workspace.sdkPath))
'${workspace.sdkPath}dart',
'pub',
'get',
]
Of if workspace.sdkPath
is nullable:
final execArgs = [
if (package.isFlutterApp)
'${workspace.sdkPath ?? ''}flutter'
else if (utils.isPubSubcommand(sdkPath: workspace.sdkPath))
'${workspace.sdkPath ?? ''}dart',
'pub',
'get',
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified in ca2d3a8 (includes tests)
@@ -46,6 +46,7 @@ const filterOptionDependsOn = 'depends-on'; | |||
const filterOptionNoDependsOn = 'no-depends-on'; | |||
const filterOptionIncludeDependents = 'include-dependents'; | |||
const filterOptionIncludeDependencies = 'include-dependencies'; | |||
const filterOptionSdkPath = 'sdk-path'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterOptionSdkPath
-> globalOptionSdkPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed in 7a9a915
@@ -98,6 +128,9 @@ class MelosWorkspace { | |||
late final bool isFlutterWorkspace = | |||
allPackages.values.any((package) => package.isFlutterPackage); | |||
|
|||
/// Optionally specify sdk path for dart/flutter | |||
late final String sdkPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field does not need to be late
.
I would prefere it if this field is nullable to signify that the sdk path is not overriden and not the empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future<Map<String, Set<String>>> getDependencyGraph() async { | ||
Future<Map<String, Set<String>>> getDependencyGraph({ | ||
required String sdkPath, | ||
}) async { | ||
final pubDepsExecArgs = ['--style=list', '--dev']; | ||
final pubListCommandOutput = await Process.run( | ||
isFlutterWorkspace | ||
? 'flutter' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also use the sdkPath here and and wherever else we invoke flutter
and dart
to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -418,10 +419,16 @@ class MelosWorkspaceConfig { | |||
map: yaml, | |||
); | |||
|
|||
final sdkPath = assertKeyIsA<String?>( | |||
key: 'sdk_path', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdk_path
-> sdkPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ebe5de7
I'm experiencing an issue and I can't tell if it's my branch or the v2 release.
But if I run it again it works. |
We changed to bootstrapping packages in parallel in 2.0.0, which was disabled because of a race condition in |
It might be that there is another race condition specific to git dependencies. |
Interesting- good context to have. In my case i'm on dart 2.17 from the flutter master channel. In my project, 4 of my packages rely on the same external git dependency in that error message (same version)- maybe it's something with shared git dependencies when run in parallel. |
Not as a feature. To validate your code in this PR you could temporarily hard-code to return
Yeah, that might be it. Once the repo directory exists in the pub cache, |
I can confirm this worked. I filed dart-lang/pub#3404 for it. |
Just pushed some refactoring from your feedback- thanks for that. While we're in there for that we should make one for doing pub in parallel since that is broken for at least my use case (and currently published like that). |
sdkPath
Thanks for this PR, BTW! I have created a separate PR for the option to disable running |
Cheers! That would be great. Want me to add you as a contributor to my fork or what's easiest for you? |
If you have "Allow edits from maintainers" on this PR enabled, I should be able to update the feature branch. |
I dont see that option for some reason, but I just invited you as a maintainer to the fork in case that works. |
Is there a trick to get around this problem? Every time I run bootstrap, i can't use the flutter pub command:
I can do |
I think you're running into #117. Until this is fixed, a workaround is to run |
Weird i guess bootstrap never worked for me then! i was using This is what my lockfiles look like for modules when doing the melos pub get:
And then if i run bootstrap the lock file changes to this:
|
I guess my workaround for now is to just use |
I just tried to push to |
@acoutts OK, the tip of |
Opened #288 |
Description
This PR adds a new
melos.yaml
configuration settingsdk_path
which allows someone to specify the path to their dart/flutter sdk instead of relying on what's in the path.This makes melos compatible with flutter version manager.
Closes #81
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 refactorci
-- Build configuration changedocs
-- Documentationchore
-- Chore