Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude devDependencies from package-lock.json parsing #3371

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/syft/internal/test/integration/node_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestNpmPackageLockDirectory(t *testing.T) {
}

// ensure that integration test commonTestCases stay in sync with the available catalogers
const expectedPackageCount = 6
const expectedPackageCount = 2
if foundPackages.Size() != expectedPackageCount {
t.Errorf("found the wrong set of npm package-lock.json packages (expected: %d, actual: %d)", expectedPackageCount, foundPackages.Size())
}
Expand Down
12 changes: 12 additions & 0 deletions syft/pkg/cataloger/javascript/parse_package_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type lockDependency struct {
Version string `json:"version"`
Resolved string `json:"resolved"`
Integrity string `json:"integrity"`
Dev bool `json:"dev"`
}

type lockPackage struct {
Expand All @@ -37,6 +38,7 @@ type lockPackage struct {
Resolved string `json:"resolved"`
Integrity string `json:"integrity"`
License packageLockLicense `json:"license"`
Dev bool `json:"dev"`
}

// packageLockLicense
Expand Down Expand Up @@ -74,6 +76,11 @@ func (a genericPackageLockAdapter) parsePackageLock(_ context.Context, resolver

if lock.LockfileVersion == 1 {
for name, pkgMeta := range lock.Dependencies {
// skip packages that are only present as a dev dependency
if pkgMeta.Dev {
continue
}

pkgs = append(pkgs, newPackageLockV1Package(a.cfg, resolver, reader.Location, name, pkgMeta))
}
}
Expand All @@ -87,6 +94,11 @@ func (a genericPackageLockAdapter) parsePackageLock(_ context.Context, resolver
name = pkgMeta.Name
}

// skip packages that are only present as a dev dependency
if pkgMeta.Dev {
continue
}

// handles alias names
if pkgMeta.Name != "" {
name = pkgMeta.Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"version": "6.14.6",
"dependencies": {
"@types/react": "^18.0.9"
},
"devDependencies": {
"async": "^3.2.4"
}
},
"node_modules/@types/prop-types": {
Expand Down Expand Up @@ -39,6 +42,12 @@
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.0.tgz",
"integrity": "sha1-TdysNxjXh8+d8NG30VAzklyPKfI=",
"license": "MIT"
},
"node_modules/async": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==",
"dev": true
}
},
"dependencies": {
Expand Down Expand Up @@ -66,6 +75,12 @@
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.0.tgz",
"integrity": "sha1-TdysNxjXh8+d8NG30VAzklyPKfI="
},
"async": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==",
"dev": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"version": "1.0.0",
"dependencies": {
"@types/react": "^18.0.9"
},
"devDependencies": {
"async": "^3.2.4"
}
},
"node_modules/@types/prop-types": {
Expand All @@ -35,6 +38,12 @@
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
},
"node_modules/async": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==",
"dev": true
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading