getExecutableForCommand
requires reading pubspec.yaml
#4222
Labels
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Discussion
Currently
dart run package:command
will only run commands if package is a direct (dev or non-dev) dependency of the current root package.This convention makes sense. Only the packages you directly depend on are the ones you should rely on running tools from.
But deciding if a package is in dependencies requires parsing
pubspec.yaml
of the root package. As this is in the hot path ofdart run
we would like to only rely on information from.dart_tool/package_config.json
. (json is faster to parse than yaml, it will be hot on the drive when passed to the VM that also needs the file).One solution would be to add the names of
dependencies
of each package to the package listing in.dart_tool/package_config.json
.One concern with this, is that the size of
.dart_tool/package_config.json
potentially will be O(n^2) in the number of packages in the resolution.This is information is also strictly more than we need. We really only need to know if a dependency is direct dependency of the root package or not. We could instead add a bit (i
s-direct-dependency-of-root
) to each package listed in the file.This is however not enough when we introduce workspaces to pub. Here a number of root packages share a
.dart_tool/package_config.json
, and when we dodart run
inside a packagea
in a workspace, we only want access to the packages that are direct dependencies ofa
, not of every root in the workspace.That leads to:
Proposal
Add the list of direct dependencies only to the root packages.
dart run
in a directoryx
would then need to find out which package is associated withx
and could thus see if the package is one of its dependencies.This would not have the O(n^2) behavior (unless o(n) of the packages are root packages...)
Example json:
If there are no dependencies associated with
x
we could eitherAllowing all packages would be backwards compatible, but I'm not sure that is needed, as we rewrite package_config.json when the dart sdk is updated.
Alternatives
We could also just let
dart run package:command
run commands from any package. I think that would rarely give any problems, but might be slightly less disciplined.The text was updated successfully, but these errors were encountered: