pub
pub copied to clipboard
Make `getExecutableForCommand` logic reusable
https://github.com/dart-lang/pub/blob/531fcd4ad5733b41edb1953789d7b6e53be87e40/lib/src/executable.dart#L279-L287
This computes the package and command, and does a bunch of other stuff.
This logic should be reusable (and not do "bunch of other stuff"). @jonasfj mentioned before that it should probably not live in pub.
Filing an issue so I have somewhere to point to.
Yeah - I think this should really live in dartdev (and the recompilation logic should also not live in pub) The only thing pub should provide here is a "resolutionIsUpToDate" check (or maybe "ensureResolutionUpToDate").
I think this should really live in dartdev
What about flutter pub run though? That should share logic with dart run. And package:flutter_tools does not import package:dartdev. We don't want to duplicate the logic between dart and flutter.
flutter pub run is deprecated and should be removed. We should only have dart run and flutter run (different resolution logic).
One possible complication is that pub is (currently) the one knowing if a package is a direct or transitive dependency. And it only allows running executables from direct (dev-)dependencies. We probably have to put this information into .dart_tool/package_config.json.
flutter pub runis deprecated and should be removed. We should only havedart runandflutter run(different resolution logic).
So, if one uses for example FFIgen in their project. They would need to run dart run ffigen --config ffigen.yaml inside their flutter project? (That also explains why flutter complains if I have a dart from the Dart SDK instead of the flutter SDK on my path.)
Since I'm most likely going to keep running into this, we should clean this up soon.
@sigurdm Do you have a rough idea of what you want to be moved over to dartdev?
- Everything in pub/lib/src/executable.dart ?
- Some stuff from pub/lib/src/entrypoint.dart ?
- I presume some of this stuff is also used in pub itself. So these classes should then be public API of pub?
Sorry - never got to answer this.
Everything in pub/lib/src/executable.dart ?
resolving executable
Yes - I believe finding the executable from a command should be computable by just looking at .dart_tool/package_config.json
One problem is that currently we restrict executables to be from the root package and its direct dependencies. (So you can run executables from app and test but not from test_core.) that information is not available in package_config.json - but requires us to parse the pubspec.yaml which we really don't want to do on the fast-path of dart run.
So either we communicate dependencies of the root package in package_config.json (or another file) or we simply lift this restriction and allow running executables from any dependency.
compiling executable to snapshot
I'd really like this not to be the responsibility of pub. I think the VM has a more information available and can chose the best way to do this.
Some stuff from pub/lib/src/entrypoint.dart ?
Not sure what that would be. I think most of that stuff should remain pub territory. I'd like pub to only expose a single ensureResolutionUpToDate function. (Perhaps also a checkResolutionUpToDate for IDE's to check if they should suggest a pub get...)