Skip to content

fix(flutter): recover path dependency locations from pubspec.yaml - #4

Draft
pawelchcki wants to merge 1 commit into
SpencerC:mainfrom
pawelchcki:fix/pub-deps-path-location
Draft

fix(flutter): recover path dependency locations from pubspec.yaml#4
pawelchcki wants to merge 1 commit into
SpencerC:mainfrom
pawelchcki:fix/pub-deps-path-location

Conversation

@pawelchcki

Copy link
Copy Markdown

Problem

flutter pub deps --json reports path dependencies as source: "path" but omits the description that carries their location:

{"name": "my_local_pkg", "source": "path", "kind": "direct", ...}

The package_config generator resolves path_value to "" for these, and the if path_value: guard then skips add_package entirely — so the package is silently dropped. Any workspace using a path dependency (a vendored package, a monorepo with several local packages, generated API clients kept in-tree) builds without it and fails later on unresolved imports, with nothing pointing at the cause.

Fix

Recover the location from the pubspec that declares the dependency, and use it only as a fallback when the JSON has no path of its own — so nothing changes for the cases that already work.

Applied at all three sites that resolve a path dependency: both copies of the package_config generator and the pubspec.lock synthesis.

Note on the parsing

The lookup is a small indentation-aware scan rather than a YAML parse. These scripts run with whatever bare python3 is on the host and cannot assume PyYAML is available. It only has to handle the shape pub itself requires:

dependencies:
  my_local_pkg:
    path: ../my_local_pkg

Happy to swap it for something stricter if you would rather take a dependency here.

Testing

Exercised against a real app with three path dependencies (two generated API clients and a vendored package). Before: all three missing from package_config.json and the build fails on unresolved imports. After: all three resolve, and a full web build, test suite and analyze run pass.

Marked draft — tell me how you would like the parsing handled and I will adjust before marking ready.

`flutter pub deps --json` reports path dependencies as source: "path" but
omits the description carrying their location. The generated package_config
therefore resolved an empty path for them, and the packages were silently
dropped -- any workspace using a path dependency (vendored packages, a repo
with several local packages, generated API clients) built without them and
failed later on unresolved imports.

Recover the location from the pubspec that declares the dependency, and use
it only as a fallback when the JSON has no path of its own, so nothing
changes for the cases that already worked.

The lookup is a small indentation-aware scan rather than a YAML parse, since
these scripts run with whatever bare python3 is on the host and cannot
assume PyYAML.

Applied at all three sites that resolve a path dependency: both copies of
the package_config generator and the pubspec.lock synthesis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant