Read optionalDependencies from pnpm lockfiles - #1766
Conversation
The parser never read optionalDependencies at any level, so an importer's optional dependencies were not direct and a package's optional dependencies produced no edges. The packages still appeared, because every `packages` entry becomes a graph node whether or not anything points at it, so the only symptom was shape: a project's own `sharp` reported as transitive, `fsevents` with no edge from chokidar. Importers' optionalDependencies are now direct production dependencies, and packages' (v5 to v8) and snapshots' (v9) optionalDependencies are edges like any other. This is a prerequisite for #1763, whose scoped results prune whatever the selection cannot reach. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0122XfZKg7Yidpc1HEEvBSJD
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Essentials Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. WalkthroughPnpm lockfile parsing now includes optional dependencies from snapshots, project maps, package data, and non-workspace roots. Project-level optional dependencies are stored as direct dependencies and processed as production dependencies. Package-level optional dependencies are merged into package dependency edges. New pnpm v6 and v9 fixtures verify direct Merge Risk: ⚪ Minimal · up to The PR extends pnpm graph parsing to include optional dependencies, with no actionable merge-blocking risk identified; it is merge-ready after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (5 skipped: 5 unsupported.) Comment |
Overview
The pnpm lockfile parser never read
optionalDependencies, at any level. An importer's optional dependencies were not direct, and a package's optional dependencies produced no edges. The packages still appeared in the result, because every entry in the lockfile'spackagessection is added to the graph whether or not anything points at it, so the only visible symptom was shape:sharpdeclared by the project showed up as a transitive dependency, andfseventshad no edge fromchokidar. The pnpm docs already say optional dependencies are included; this makes the graph match that.The parser now reads
optionalDependenciesin importers as direct production dependencies, and inpackagesentries (v5 to v8) andsnapshots(v9) as edges.buildGraphCoretreats an importer's optional dependencies exactly like itsdependencies.This is a prerequisite for #1763, which scopes a pnpm result to selected workspace members by pruning what the selection cannot reach. Without these edges, pruning would silently drop every optional package and anything only reachable through one. Unscoped analysis is unaffected by that pruning, which is why the gap was harmless until now.
Acceptance criteria
For a pnpm project whose
package.jsonlistssharpunderoptionalDependenciesand depends onchokidar,fossa analyzereportssharpas a direct dependency andfseventsas a dependency ofchokidar, in both v6 and v9 lockfiles. Nothing that was reported before disappears.Testing plan
cabal test unit-tests --test-options=--match=Pnpmruns the two new fixtures, one v6 and one v9, alongside every existing pnpm fixture, none of which declare optional dependencies, so their expectations are unchanged.fossa analyze --outputbefore and after: the vertex set is the same,sharpmoves from transitive to direct, andchokidargains an edge tofsevents.Risks
Optional dependencies are labeled production. The npm v3 lockfile strategy already reads a package's
optionalDependenciesas ordinary edges, so this matches it, but the label is a choice.Metrics
None.
References
Checklist
docs/.docs/README.msand gave consideration to how discoverable or not my documentation is.Changelog.md. If this PR did not mark a release, I added my changes into an## Unreleasedsection at the top..fossa.ymlorfossa-deps.{json.yml}, I updateddocs/references/files/*.schema.jsonAND I have updated example files used byfossa initcommand. You may also need to update these if you have added/removed new dependency type (e.g.pip) or analysis target type (e.g.poetry).docs/references/subcommands/<subcommand>.md.🤖 Generated with Claude Code
https://claude.ai/code/session_0122XfZKg7Yidpc1HEEvBSJD