When a Yarn Berry workspace package is consumed as a production dependency, its
dev-only tooling (webpack, babel, ...) was reported as production dependencies of
the consumer, because yarn.lock merges a workspace member's dependencies and
devDependencies into one block with no dev marker.
Populate the lockfile parser's `workspacePackages` map (member name -> dep
groups) in processYarnWorkspaces so it can prune the dev-only deps of a consumed
workspace package. The member manifests are collected up front from the
already-discovered target files (a consumer may be processed before the member it
depends on).
Requires snyk-nodejs-lockfile-parser with
`YarnLockV2WorkspaceArgs.workspacePackages` (bump the dependency once released).
Pull Request Submission Checklist
What does this PR do?
Fixes false positives in Yarn Berry (v2/3/4) workspace scans: the dev-only build tooling (
webpack,babel, ...) of a workspace package was being reported as production dependencies of any sibling package that consumed it.Yarn Berry flattens a workspace member's
dependencies+devDependenciesinto a singledependenciesblock inyarn.lockwith no dev marker. When a member is consumed as a prod dependency, the parser walked that whole block and inherited the parent's prod scope, so the consumed member's dev tooling (and its transitive tree) was promoted into the production graph.processYarnWorkspacesnow collects each workspace member'spackage.jsondependency groups (from the already-discovered target files) and passes them to the lockfile parser viaYarnLockV2WorkspaceArgs.workspacePackages, so the parser can prune the dev-only dependencies of a consumed workspace package.Before / after
Scanning
apps/my-app(whose only prod dep is the workspace package@demo/shared-lib, which has only devDependencies):@demo/shared-lib)Where should the reviewer start?
src/lib/plugins/nodejs-plugin/yarn-workspaces-parser.ts— the newcollectYarnWorkspacePackageshelper, the pre-pass that gathers member manifests before the main loop (a consumer may be processed before the member it depends on), and theworkspacePackagesargument added to theparseYarnLockV2Projectcall.How should this be manually tested?
The
processYarnWorkspaces - dev-dependency leaksuite scanstest/fixtures/yarn-workspace-dev-depsand asserts the consumed member's dev tooling is absent by default and present under--dev. (Requires asnyk-nodejs-lockfile-parserbuild that includesworkspacePackages.)What's the product update that needs to be communicated to CLI users?
Yarn Berry workspace scans no longer report a consumed workspace package's dev-only dependencies as production. Existing workspace results will show fewer (correctly scoped) production dependencies.
Risk assessment (Low | Medium | High)?
Low. Behavior is gated on the new
workspacePackagesmap; with no map (or no parser support) behavior is unchanged. Non-workspace scans are unaffected. It is a dep-graph-shape change for Yarn workspaces (fewer prod deps), so worth a release note.What are the relevant tickets?