fix: prune devDependencies of virtualized workspaces under --prod (#256)#563
fix: prune devDependencies of virtualized workspaces under --prod (#256)#563RickTimmer wants to merge 1 commit into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
@RickTimmer please sign off your commits as described in the contribution guidelines: https://github.com/CycloneDX/cyclonedx-node-yarn/blob/main/CONTRIBUTING.md#sign-off-your-commits you may do so after the fact by following these instructions: https://github.com/CycloneDX/cyclonedx-node-yarn/pull/563/checks?check_run_id=88771998480 |
|
before accepting that change, we need the testsbeds running in the unpatched version - to then showcase the effect of the fix. Could you open an additional pullrequest that just adds the testbed and no source changes? |
Signed-off-by: RickTimmer <ricktimmer98@gmail.com>
be307e6 to
f5b20a9
Compare
|
Sounds good thanks for the quick look. I made the new PR here, this one contains just the test beds. That was a good suggestion on your part. |
Description
Under
--prod,devDependenciesof workspaces leak into the SBOM when the workspace is virtualized.A workspace on the resolution path of a peer dependency is resolved by Yarn as virtual packages, each with its own
locatorHashand copy of thedependenciesmap — this happens even when no workspace manifest declarespeerDependencies, since a transitive npm dependency declaring a peer is enough. The SBOM traversal walks those virtual instances, but the previous--prodprune only mutated the scanned workspace'sanchoredPackage, so dev edges on the virtual copies survived and their targets were emitted as production components.This PR prunes across
project.storedPackages, devirtualizing each locator (structUtils.devirtualizeLocator+tryWorkspaceByLocator) so dev edges are removed from every workspace instance including virtual copies. Edges are removed rather than components filtered by identity, so a package that is adevDependencyof one workspace but a genuine transitive prod dependency elsewhere is correctly retained.This also covers the case #456 misses: that PR filters by ident on anchored workspace packages, which never match virtual instances (different
locatorHash,virtual:-prefixed reference).Adds a regression testbed (
workspace-peer-dev-dependencies) where a child workspace is virtualized via a transitive peer (use-sync-external-store→react) with no workspace-levelpeerDependencies, carrying a dev-onlyis-number; snapshots assertis-numberis absent under--prodand present without it. Also verified against a real-world Yarn Berry monorepo.Resolves or fixes issue: #256
AI Tool Disclosure
Claude (claude.ai)Claude Opus 4.8Diagnosing why --prod includes transitive workspace devDependencies,Generate test-suite for this case, andfill in this PR description formAffirmation