Skip to content

Pub Proposal: allow executables to specify their own dependencies #34837

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

Open
srawlins opened this issue Oct 17, 2018 · 1 comment
Open

Pub Proposal: allow executables to specify their own dependencies #34837

srawlins opened this issue Oct 17, 2018 · 1 comment
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

Comments

@srawlins
Copy link
Member

Currently dependencies in a pubspec are split into dependencies and dev_dependencies. This allows packages to specify what is needed in order to use the package (what packages are necessary to resolve imports in lib/ and bin/), vs what is needed in order to develop the package (what packages are needed to resolve imports in test/ and tool/, etc.).

However, executables found in bin/ cannot be referenced by a package: URI import in downstream code, so some packages are forced to list dependencies that are never referenced by their lib/ 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:

executables:
  simple-tool: simple_tool
  tool-with-deps:
    script: tool-with-deps
    dependencies:
      args: ">=1.4.0 <2.0.0"

A script which does not have extra dependencies beyond the global dependencies list can continue to use the original executables 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 execute bar and baz. It would have to also check the bar and baz executables for their own dependencies, 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 for dependencies, and fetch those as well.

  • pub get:

    This command fetches all of a package's dependencies, and dev_dependencies. It would have to also check each executable for dependencies, and fetch those as well.

Just as dev_dependencies cannot conflict with dependencies, the entire collection of dependencies from a package's dependencies, dev_dependencies, and all exdecutables' 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's dependencies:

    • args: ">=1.4.0 <2.0.0"
    • cli_repl: ">=0.1.3 <0.3.0"
    • stream_transform: "^0.0.1"
  • dart_style could move "args" to its executable's dependencies.

  • dart2js_info could move the following dependencies to it's executable's dependencies:

    • args: '>=0.13.0 <2.0.0'
    • charcode: ^1.1.0
    • path: ^1.3.6
    • shelf: '>=0.6.1+2 <0.8.0'
    • shelf_static: ^0.2.4
    • yaml: ^2.1.0
  • dartdoc could move the following dependencies to it's executable's dependencies:

    • process: ^3.0.5
    • pub_semver: ^1.3.7
    • stack_trace: ^1.4.2

Other packages may benefit as well. test, markdown, flutter packages?

@zoechi
Copy link
Contributor

zoechi commented Oct 18, 2018

See also dart-lang/pub#1231

@a-siva a-siva added 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 labels Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants