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

fix: Switch refs for dev and opt dependencies in SPDX sboms #6871

Closed
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
11 changes: 9 additions & 2 deletions lib/utils/sbom-spdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,16 @@ const toSpdxRelationship = (node, edge) => {
type = REL_DEP
}

let from, to
if ([REL_OPTIONAL, REL_DEV].includes(type)) {
[from, to] = [edge.to, node]
} else {
[from, to] = [node, edge.to]
}

return {
spdxElementId: toSpdxID(node),
relatedSpdxElement: toSpdxID(edge.to),
spdxElementId: toSpdxID(from),
relatedSpdxElement: toSpdxID(to),
relationshipType: type,
}
}
Expand Down
12 changes: 6 additions & 6 deletions tap-snapshots/test/lib/commands/sbom.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ exports[`test/lib/commands/sbom.js TAP sbom extraneous dep > must match snapshot
"relationshipType": "DEPENDS_ON"
},
{
"spdxElementId": "SPDXRef-Package-test-npm-ls-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-chai-1.0.0",
"spdxElementId": "SPDXRef-Package-chai-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-test-npm-ls-1.0.0",
"relationshipType": "OPTIONAL_DEPENDENCY_OF"
}
]
Expand Down Expand Up @@ -730,8 +730,8 @@ exports[`test/lib/commands/sbom.js TAP sbom loading a tree containing workspaces
"relationshipType": "DEPENDS_ON"
},
{
"spdxElementId": "SPDXRef-Package-a-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-baz-1.0.0",
"spdxElementId": "SPDXRef-Package-baz-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-a-1.0.0",
"relationshipType": "DEV_DEPENDENCY_OF"
},
{
Expand Down Expand Up @@ -1091,8 +1091,8 @@ exports[`test/lib/commands/sbom.js TAP sbom loading a tree containing workspaces
"relationshipType": "DEPENDS_ON"
},
{
"spdxElementId": "SPDXRef-Package-a-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-baz-1.0.0",
"spdxElementId": "SPDXRef-Package-baz-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-a-1.0.0",
"relationshipType": "DEV_DEPENDENCY_OF"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ SBOM format to use when generating SBOMs.
* Type: "library", "application", or "framework"

The type of package described by the generated SBOM. For SPDX, this is the
value for the \`primaryPackagePurpose\` fieled. For CycloneDX, this is the
value for the \`primaryPackagePurpose\` field. For CycloneDX, this is the
value for the \`type\` field.


Expand Down
12 changes: 6 additions & 6 deletions tap-snapshots/test/lib/utils/sbom-spdx.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ exports[`test/lib/utils/sbom-spdx.js TAP node - with deps > must match snapshot
"relationshipType": "HAS_PREREQUISITE"
},
{
"spdxElementId": "SPDXRef-Package-root-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-dep2-0.0.2",
"spdxElementId": "SPDXRef-Package-dep2-0.0.2",
"relatedSpdxElement": "SPDXRef-Package-root-1.0.0",
"relationshipType": "OPTIONAL_DEPENDENCY_OF"
},
{
"spdxElementId": "SPDXRef-Package-root-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-dep3-0.0.3",
"spdxElementId": "SPDXRef-Package-dep3-0.0.3",
"relatedSpdxElement": "SPDXRef-Package-root-1.0.0",
"relationshipType": "DEV_DEPENDENCY_OF"
},
{
Expand All @@ -174,8 +174,8 @@ exports[`test/lib/utils/sbom-spdx.js TAP node - with deps > must match snapshot
"relationshipType": "DEPENDS_ON"
},
{
"spdxElementId": "SPDXRef-Package-root-1.0.0",
"relatedSpdxElement": "SPDXRef-Package-dep6-0.0.6",
"spdxElementId": "SPDXRef-Package-dep6-0.0.6",
"relatedSpdxElement": "SPDXRef-Package-root-1.0.0",
"relationshipType": "OPTIONAL_DEPENDENCY_OF"
}
]
Expand Down
2 changes: 1 addition & 1 deletion workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ define('sbom-type', {
],
description: `
The type of package described by the generated SBOM. For SPDX, this is the
value for the \`primaryPackagePurpose\` fieled. For CycloneDX, this is the
value for the \`primaryPackagePurpose\` field. For CycloneDX, this is the
value for the \`type\` field.
`,
flatten,
Expand Down