Skip to content

fix: omit transitive and devOptional dependencies - #1536

Open
kmlyz wants to merge 2 commits into
CycloneDX:mainfrom
kmlyz:fix/omit-transitive-and-devoptional-deps
Open

kmlyz wants to merge 2 commits into
CycloneDX:mainfrom
kmlyz:fix/omit-transitive-and-devoptional-deps

Conversation

@kmlyz

@kmlyz kmlyz commented Nov 11, 2026 •

Copy link
Copy Markdown

Description

npm ls --omit=... only filters direct root/workspace dependency edges (currentDepth === 0) and (without --package-lock-only, see npm/cli#8485) omits dev, optional, and devOptional node flags from JSON output. As a result, transitive optional and peer dependencies as well as devOptional dependencies reachable only through omitted dev and optional paths remained in the generated SBOM.

This change updates BomBuilder.gatherPackages to:

  • classify dependency edges from each package's manifest metadata (devDependencies on root/workspaces, optionalDependencies, _dependencies, peerDependencies, peerDependenciesMeta) while still indexing deduped npm ls nodes before reachability pruning,
  • prune unreachable packages and packages carrying omitted dev, optional, peer, or devOptional (when both dev and optional are omitted) flags starting from rootPath,
  • add unit tests in tests/unit/builders.BomBuilder.spec.js and update the omit-* integration snapshots introduced in tests: omit dev/optional/peer #1329.

Resolves or fixes issue: #1325

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: Google Antigravity
    • LLMs and versions: Gemini 4 Carbon
    • Prompts: Analyze root cause of #1325 across npm-ls and BomBuilder.gatherPackages, implement edge/reachability filtering for omitted dev/optional/peer/devOptional dependencies, add unit tests, and verify snapshots in isolated container.

Affirmation

Filter omitted dev, optional, and peer dependency edges across the full
npm-ls graph and prune unreachable or omitted packages from root. This
ensures transitive optional/peer dependencies and devOptional packages
(when both dev and optional are omitted) are excluded even when npm-ls
only filters root-level edges or omits lockfile flags.

Fixes CycloneDX#1325

Signed-off-by: Kemal Yilmaz <kemalylmz@gmail.com>
@kmlyz
kmlyz requested a review from a team as a code owner November 11, 2026 00:49
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

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.

@jkowalleck
jkowalleck marked this pull request as draft November 11, 2026 11:08
@jkowalleck

This comment was marked as resolved.

@jkowalleck
jkowalleck marked this pull request as ready for review November 11, 2026 11:15
@jkowalleck

Copy link
Copy Markdown
Member

Thank you for tackling this issue.

I need to look into the details; this will take a while - please stay patient :-)

Any peer review is very welcome.

@jkowalleck jkowalleck added the bug Something isn't working label Nov 13, 2026
@jkowalleck

jkowalleck commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

i think this fix needs some in-depth docs added to https://github.com/CycloneDX/cyclonedx-node-npm/blob/main/docs/how.md

COuld you add a separate section for this regard in the document?

Signed-off-by: Kemal Yilmaz <kemalylmz@gmail.com>
@kmlyz

kmlyz commented Nov 13, 2026 •

Copy link
Copy Markdown
Author

Added the Omitting dependencies section to docs/how.md describing the manifest edge classification and reachability pruning for --omit.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] --omit=dev and --omit=optional flags don't exclude devOptional dependencies, causing misleading output

2 participants