Skip to content

Publish CLI apps with pubspec.lock, and use it when global activateing. #3668

@bsutton

Description

@bsutton

I wrote a blog on this one if you want a bit more detail but here is the summary.

https://onepub.dev/Blog?id=fvvuhnofly

The dart guidelines for pubspec dependencies recommend using a version range

dependencies:
  dcli: ^1.0.0

This works great if you are compiling a flutter app.

The version range lets pub find a version that meets all the requirements of various overlapping dependencies and then
the process of compiling your flutter app locks those dependencies to a particular version (i.e. you ship code that will be installed with a know version that you have tested against).

The problem with CLI apps is that when they are installed from pub.dev the version of any particular package is decided at the point of installation.

This means that your CLI app can be installed against versions of dependencies that you haven't tested against.

I've experienced this in the real world on numerous occasions so it's not a theoretical concern.

My suggestion is to make the following changes:

If the package is a CLI app (contains one or more keys under the 'executable' section in pubspec.yaml)

Then publish the pubspec.lock file along with the package.

When installing the CLI app use the lock file to determine what versions to link against the CLI app.

If the package also contains a public api (both dcli and fvm) then use the normal version ranges present in the pubspec.yaml (i.e. ignore the pubspec.lock as we do now) when the package is linked into third party app.

I don't believe this change will break the existing environment and will allow us to create stable CLI apps with dart.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions