fix: handle peerDependencies and optionalDependencies consistently ac…#392
Conversation
…ross JS providers JavaScript providers (npm, pnpm, yarn classic, yarn berry) produced inconsistent dependency analysis results when package.json contains peerDependencies, optionalDependencies, and devDependencies. - pnpm: lodash (optionalDependency) was missing because pnpm outputs optional deps under a separate "optionalDependencies" key, but addDependenciesToSbom and getRootDependencies only read the "dependencies" key. - Yarn Berry: devDependencies were included in the scan because yarn info has no --prod flag and the processor did not filter at root level. - Yarn Classic: lodash was missing because Manifest.loadDependencies only read the "dependencies" key, causing the filter in addDependenciesToSbom to exclude it. - All yarn providers: minimist (peerDependency) was missing because yarn does not include peer deps in its output, and no backfill mechanism existed. Fixes applied (matching trustify-da-javascript-client approach): - Manifest: loadDependencies now includes optionalDependencies and peerDependencies names. Added peerDependencies and optionalDependencies as Map<String, String> fields. - JavaScriptProvider: addDependenciesToSbom and getRootDependencies now also read the "optionalDependencies" key from dep tree output. Added ensurePeerAndOptionalDeps to backfill missing peer/optional deps using declared versions from package.json. - YarnBerryProcessor: addDependenciesToSbom now filters root node dependencies to only include production deps (those in manifest.dependencies). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Review Summary by QodoFix inconsistent handling of peer and optional dependencies across JavaScript providers
WalkthroughsDescription• Handle peerDependencies and optionalDependencies consistently across all JavaScript providers (npm, pnpm, yarn classic, yarn berry) • Add backfill mechanism to ensure peer and optional dependencies are included in SBOM even when missing from provider output • Filter root-level devDependencies in Yarn Berry to only include production dependencies • Extend Manifest to track peerDependencies and optionalDependencies as separate maps Diagramflowchart LR
A["Manifest"] -->|loads peerDeps & optionalDeps| B["Manifest Maps"]
C["JavaScriptProvider"] -->|reads optionalDependencies key| D["addDependenciesToSbom"]
C -->|backfills missing deps| E["ensurePeerAndOptionalDeps"]
E -->|uses declared versions| B
F["YarnBerryProcessor"] -->|filters root deps| G["Production only"]
D --> H["Consistent SBOM"]
E --> H
G --> H
File Changes1. src/main/java/io/github/guacsec/trustifyda/providers/JavaScriptProvider.java
|
Code Review by Qodo
1.
|
1. CycloneDXSbom.checkIfPackageInsideDependsOnList: the stream result was never assigned back to allDirectDeps, so the check always returned false. Also changed getName() comparison to use full namespace/name to handle scoped packages (e.g. @babel/core). 2. JavaScriptProvider.addDependenciesFromKey: added null check for version node before calling asText(), matching the defensive pattern already used in addDependenciesOf. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/review |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
…S reachability The previous implementation only filtered devDependencies at the root edge, but still processed all non-root nodes unconditionally. This meant transitive dependencies of devDeps (e.g., jest -> some-test-util) would leak into the SBOM. Uses BFS from root production deps to compute the reachable set, then skips unreachable nodes and edges during SBOM emission. Also adds a test fixture with a transitive devDep to expose the issue. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
|
/review |
|
Persistent review updated to latest commit 226279c |
ruromero
left a comment
There was a problem hiding this comment.
I triggered the Qodo review but from the functionality point of view, LGTM
Verification Report for TC-3977 (commit 226279c)
Overall: WARNIssues requiring attention:
Acceptance Criteria Details:
PR has 1 approval from @ruromero ("LGTM from functionality point of view"). This comment was AI-generated by sdlc-workflow/verify-pr v0.5.5. |
…eDependsOnList Match against both leaf name (dep.getName()) and full namespace/name to support Go callers passing only the leaf name while preserving the new scoped-package matching for JavaScript. Update Go golden files where ignore-by-name filtering now correctly removes previously leaked deps. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
…ross JS providers
JavaScript providers (npm, pnpm, yarn classic, yarn berry) produced inconsistent dependency analysis results when package.json contains peerDependencies, optionalDependencies, and devDependencies.
Fixes applied (matching trustify-da-javascript-client approach):
Fixes: #391
Jira issue: https://redhat.atlassian.net/browse/TC-3977