Skip to content

Enhancement: apply pubspec.yaml dependency_overrides in Dart scans #678

Open

Description

@vibgrate-team

Context

In Dart and Flutter projects, dependency_overrides: in pubspec.yaml forces the version that actually gets resolved, whatever dependencies: or dev_dependencies: ask for:

dependencies:
  http: ^0.13.0

dependency_overrides:
  http: 1.2.1

parsePubspecYaml in src/core-open/scanners/dart-scanner.ts (around lines 203–300) only enters a section for dependencies: and dev_dependencies:. Any other top-level key, including dependency_overrides:, resets the section, so overrides are ignored. As a result, a project scanned without a pubspec.lock reports the ^0.13.0 constraint for http, even though the project builds with 1.2.1. A package that appears only in dependency_overrides is not reported at all.

What to do

  • Read dependency_overrides: entries in the same forms already supported for the other sections (one-line version, { version: … } maps, path: and git: entries).
  • When a package is both declared and overridden, use the override's spec for that package's row and keep it as a production or development dependency according to where it was declared.
  • Decide what to do with override-only packages (for example, report them as production rows) and write the choice down in the function's doc comment.
  • Add a test next to test/dart-pubspec-map.test.ts.

Acceptance

  • With the example above, vg scan reports http at 1.2.1, not ^0.13.0.
  • An overridden dev_dependencies package keeps its development flag.
  • Projects with no dependency_overrides: section produce exactly the same output as before.
  • New test passes with npm test.

Activity

  1. added
    enhancement
    on Nov 13, 2026
  2. vibgrate-team commented on Nov 13, 2026

    @vibgrate-team
    ContributorAuthor

    Thanks, this is a real accuracy gap for Flutter projects scanned without a lockfile. Some notes from the code to help whoever takes it:

    • parsePubspecYaml in src/core-open/scanners/dart-scanner.ts tracks currentSection as 'dependencies' | 'dev_dependencies' | null, and the indent === 0 && /^\w+:/ branch resets it for every other top-level key. That is where dependency_overrides: is currently thrown away. Adding it as a third section that goes through the same one-line, { version: … } flow-map and nested version: / path: / git: handling means you get all the existing forms for free.
    • The tricky part is the merge, because overrides can appear before or after the declarations in the file. It's simplest to collect overrides into their own Map<name, spec> while parsing and apply them once at the end: replace the spec on an existing row but keep its isDev flag, and add any override-only names as new rows (production is a reasonable default, as the issue suggests). Please write whichever rule you choose into the doc comment above the function, which already explains how duplicates across the two sections are handled.
    • Watch the SDK skip logic: an override such as flutter_test: { sdk: flutter } should still be skipped, and the sdk: line at the top of the loop must not be treated as a Dart version when it sits inside the overrides section.
    • test/dart-pubspec-map.test.ts and test/sbom-dart-dev-dependencies.test.ts show the fixture style. Covering the example in the issue, an overridden dev dependency, an override-only package, and a pubspec with no overrides (output unchanged) would pin all four acceptance points.

    If a pubspec.lock is present it still wins, so this change only affects lockfile-less scans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions