pub icon indicating copy to clipboard operation
pub copied to clipboard

Add information to the `package_config.json` to specify whether a package dependency is from hosted pub

Open kenzieschmoll opened this issue 2 years ago • 3 comments

In https://github.com/flutter/devtools/pull/6651, we needed to check whether a package dependency was from a local source location (which could be a non-public package) or if it was from hosted pub (public package).

In the meantime we used this check:

final isPublic = extension.rootUri.path.contains(path.join('.pub-cache', 'hosted'));

But it would be more robust if we didn't have to guess based on the package's root uri. Is there any way we can add a bit 'hosted': 'true' or similar to the package_config.json entry for a package?

kenzieschmoll avatar Nov 03 '23 16:11 kenzieschmoll

After talking with @sigurdm, we can get this information from the pubspec.lock file, though that still may not be enough since the pubspec.lock file is not always guaranteed to be present like the package_config.json file.

Example:

# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  async:
    dependency: transitive
    description:
      name: async
      sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
      url: "https://pub.dev"
    source: hosted
    version: "2.11.0"

kenzieschmoll avatar Nov 03 '23 19:11 kenzieschmoll

cc @jonasfj

sigurdm avatar Nov 09 '23 09:11 sigurdm

@kenzieschmoll, I'm curious: What are the use-cases for this?


I think that in general, we should probably consider putting some information into package_config.json such that tools that do debugging or report stack traces, etc can be aware of the package concept.

I could easily imagine that each entry in package_config.json should have a origin property specifying where it comes from. Things like:

  • package name
  • package version (if applicable)
  • source kind: hosted, path, git, sdk
  • git revision
  • hosted repository URL (and the likes).

jonasfj avatar Nov 27 '23 12:11 jonasfj