Pub Proposal: allow executables to specify their own dependencies #34837
Labels
area-pkg
Used for miscellaneous pkg/ packages not associated with specific area- teams.
type-enhancement
A request for a change that isn't a bug
Currently dependencies in a pubspec are split into
dependencies
anddev_dependencies
. This allows packages to specify what is needed in order to use the package (what packages are necessary to resolve imports inlib/
andbin/
), vs what is needed in order to develop the package (what packages are needed to resolve imports intest/
andtool/
, etc.).However, executables found in
bin/
cannot be referenced by apackage:
URI import in downstream code, so some packages are forced to list dependencies that are never referenced by theirlib/
code, leading to dependency bloat.Proposal
I propose the following addition to the pubspec spec: allow executables to specify their own extra dependencies, like so:
A script which does not have extra dependencies beyond the global
dependencies
list can continue to use the originalexecutables
format (<name-of-executable>: <Dart-script-from-bin>
).Correspondingly, some pub behavior would change:
pub global activate foo --executable bar --executable baz
:This command has always fetched
dependencies
in order to executebar
andbaz
. It would have to also check thebar
andbaz
executables for their owndependencies
, and fetch them as well.pub global activate foo
:This command "installs" each executable listed in
foo
's pubspec. It would have to also check each executable fordependencies
, and fetch those as well.pub get
:This command fetches all of a package's
dependencies
, anddev_dependencies
. It would have to also check each executable fordependencies
, and fetch those as well.Just as
dev_dependencies
cannot conflict withdependencies
, the entire collection of dependencies from a package'sdependencies
,dev_dependencies
, and allexdecutables
'dependencies
must not conflict.Consequences
Broadly, this has the benefit of reducing code bloat, and possibility for version conflicts, just as
dev_dependencies
does. Here are a few examples:dart-sass could move the following
dependencies
to it's executable'sdependencies
:dart_style could move "args" to its executable's
dependencies
.dart2js_info could move the following
dependencies
to it's executable'sdependencies
:dartdoc could move the following
dependencies
to it's executable'sdependencies
:Other packages may benefit as well.
test
,markdown
, flutter packages?The text was updated successfully, but these errors were encountered: