Skip to content

exclude npm devOptional dependencies by default - #5065

Open
Kunalbehbud wants to merge 1 commit into
anchore:mainfrom
Kunalbehbud:npm-exclude-dev-optional
Open

Kunalbehbud wants to merge 1 commit into
anchore:mainfrom
Kunalbehbud:npm-exclude-dev-optional

Conversation

@Kunalbehbud

Copy link
Copy Markdown

Description

npm records packages that are only reachable through dev dependencies (or that are simultaneously dev and optional) with "devOptional": true in package-lock.json. Syft already skips "dev": true packages when dev dependencies are excluded, but devOptional ones slipped through and ended up in the catalog.

This treats devOptional the same as dev: such packages are skipped unless IncludeDevDependencies is enabled, for both the v1 (dependencies) and v2/v3 (packages) lockfile layouts.

Per @kzantow's request on the issue, the change is exercised by a small package-lock.json fixture (testdata/pkg-lock/package-lock-dev-optional.json) that contains a devOptional entry, with tests asserting it is excluded by default and included when IncludeDevDependencies is set.

Closes #4982

npm marks packages that are only needed by dev dependencies (or that are
both dev and optional) with "devOptional": true in package-lock.json.
Treat those the same as dev dependencies so they are excluded from the
catalog unless IncludeDevDependencies is set.

Closes anchore#4982

Signed-off-by: Kunalbehbud <b.kunal2002@gmail.com>
@Kunalbehbud
Kunalbehbud force-pushed the npm-exclude-dev-optional branch from 7bfe0ee to a53f04a Compare November 13, 2026 21:12
@Kunalbehbud

Copy link
Copy Markdown
Author

rebased onto main. the v1 lockfile walk got refactored upstream, so the devOptional check now lives in the recursive walk next to the dev one. javascript cataloger tests pass

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPM devOptional dependencies should be excluded

1 participant