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

chore(deps): bump packageurl-js from 1.2.1 to 2.0.1 #1142

Merged
merged 9 commits into from
Nov 16, 2024
Merged
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 .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ jobs:
js-type: [ 'cjs', 'mjs' ]
include:
- # lowest reasonable number that works
typescript-version: '^3.8'
typescript-version: '^4.0'
nodeTypes-version: '^14'
js-type: 'cjs'
env:
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file.
* Serializers and `Bom`-Normalizers will take changed `Models.Bom.tools` into account ([#1152] via [#1163])
* Dependencies
* Support `libxmljs2@^0.35` (via [#1173])
* Use `packageurl-js@^2.0.1`, was `@>=0.0.6 <0.0.8 || ^1` (via [#1142])

[#1142]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1142
[#1152]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1152
[#1163]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1163
[#1173]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1173
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"node": ">=14.0.0"
},
"dependencies": {
"packageurl-js": ">=0.0.6 <0.0.8 || ^1",
"packageurl-js": "^2.0.1",
"spdx-expression-parse": "^3.0.1 || ^4"
},
"optionalDependencies": {
Expand Down
32 changes: 0 additions & 32 deletions src/_helpers/packageUrl.ts

This file was deleted.

22 changes: 13 additions & 9 deletions src/factories/fromNodePackageJson.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
*/

import type { PackageURL } from 'packageurl-js'
import { PurlQualifierNames } from 'packageurl-js'

import {tryCanonicalizeGitUrl} from "../_helpers/gitUrl"
import { isNotUndefined } from '../_helpers/notUndefined'
import type { PackageJson } from '../_helpers/packageJson'
import { PackageUrlQualifierNames } from '../_helpers/packageUrl'
import { ExternalReferenceType } from '../enums/externalReferenceType'
import type { Component } from '../models/component'
import { ExternalReference } from '../models/externalReference'
Expand Down Expand Up @@ -137,20 +137,24 @@ export class PackageUrlFactory extends PlainPackageUrlFactory<'npm'> {
#finalizeQualifiers (purl: PackageURL): PackageURL {
const qualifiers = new Map(Object.entries(purl.qualifiers ?? {}))

const downloadUrl = qualifiers.get(PackageUrlQualifierNames.DownloadURL)
const downloadUrl = qualifiers.get(PurlQualifierNames.DownloadUrl)
if (downloadUrl !== undefined) {
qualifiers.delete(PackageUrlQualifierNames.VcsUrl)
qualifiers.delete(PurlQualifierNames.VcsUrl)
if (npmDefaultRepositoryMatcher.test(downloadUrl)) {
qualifiers.delete(PackageUrlQualifierNames.DownloadURL)
qualifiers.delete(PurlQualifierNames.DownloadUrl)
}
}
if (!qualifiers.has(PackageUrlQualifierNames.DownloadURL) && !qualifiers.has(PackageUrlQualifierNames.VcsUrl)) {
if (!qualifiers.has(PurlQualifierNames.DownloadUrl) && !qualifiers.has(PurlQualifierNames.VcsUrl)) {
// nothing to base a checksum on
qualifiers.delete(PackageUrlQualifierNames.Checksum)
qualifiers.delete(PurlQualifierNames.Checksum)
}
if (qualifiers.size > 0) {
purl.qualifiers = Object.fromEntries(qualifiers.entries())
/* @ts-expect-error TS2322 */
purl.qualifiers.__proto__ = null /* eslint-disable-line no-proto -- intended */
} else {
purl.qualifiers = undefined
}
purl.qualifiers = qualifiers.size > 0
? Object.fromEntries(qualifiers.entries())
: undefined

return purl
}
Expand Down
11 changes: 6 additions & 5 deletions src/factories/packageUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/

import { PackageURL } from 'packageurl-js'
import { PackageURL, PurlQualifierNames } from 'packageurl-js'

import { PackageUrlQualifierNames } from '../_helpers/packageUrl'
import { ExternalReferenceType } from '../enums/externalReferenceType'
import type { Component } from '../models/component'

Expand All @@ -37,6 +36,8 @@ export class PackageUrlFactory<PurlType extends PackageURL['type'] = PackageURL[
/* eslint-disable-next-line @typescript-eslint/no-inferrable-types -- docs */
makeFromComponent (component: Component, sort: boolean = false): PackageURL | undefined {
const qualifiers: PackageURL['qualifiers'] = {}
/* @ts-expect-error TS2322 */
qualifiers.__proto__ = null /* eslint-disable-line no-proto -- intended */
let subpath: PackageURL['subpath'] = undefined

// sorting to allow reproducibility: use the last instance for a `extRef.type`, if multiples exist
Expand All @@ -55,17 +56,17 @@ export class PackageUrlFactory<PurlType extends PackageURL['type'] = PackageURL[
/* eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- intended */
switch (extRef.type) {
case ExternalReferenceType.VCS:
[qualifiers[PackageUrlQualifierNames.VcsUrl], subpath] = url.split('#', 2)
[qualifiers[PurlQualifierNames.VcsUrl], subpath] = url.split('#', 2)
break
case ExternalReferenceType.Distribution:
qualifiers[PackageUrlQualifierNames.DownloadURL] = url
qualifiers[PurlQualifierNames.DownloadUrl] = url
break
}
}

const hashes = component.hashes
if (hashes.size > 0) {
qualifiers[PackageUrlQualifierNames.Checksum] = Array.from(
qualifiers[PurlQualifierNames.Checksum] = Array.from(
sort
? hashes.sorted()
: hashes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ suite('integration: Factories.FromNodePackageJson.PackageUrlFactory', () => {
vcs_url: 'git+https://foo.bar/repo.git'
}, undefined)
// expect objet's keys in alphabetical oder, expect sorted hash list
const expectedString = 'pkg:testing/name?checksum=blake3%3Aaa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d%2Csha-256%3Ac3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2&vcs_url=git%2Bhttps%3A//foo.bar/repo.git'
const expectedString = 'pkg:testing/name?checksum=blake3%3Aaa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d%2Csha-256%3Ac3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2&vcs_url=git%2Bhttps%3A%2F%2Ffoo.bar%2Frepo.git'

const actual = sut.makeFromComponent(component, true)

Expand Down Expand Up @@ -287,7 +287,7 @@ suite('integration: Factories.FromNodePackageJson.PackageUrlFactory', () => {
download_url: 'https://foo.bar/download-2'
}, undefined)
// expect objet's keys in alphabetical oder, expect sorted hash list
const expectedString = 'pkg:testing/name?download_url=https%3A//foo.bar/download-2'
const expectedString = 'pkg:testing/name?download_url=https%3A%2F%2Ffoo.bar%2Fdownload-2'

const actual1 = sut.makeFromComponent(component1, true)
const actual2 = sut.makeFromComponent(component2, true)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/Factories.PackageUrlFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ suite('integration: Factories.PackageUrlFactory', () => {
vcs_url: 'git+https://foo.bar/repo.git'
}, undefined)
// expect objet's keys in alphabetical oder, expect sorted hash list
const expectedString = 'pkg:testing/name?checksum=blake3%3Aaa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d%2Csha-256%3Ac3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2&download_url=https%3A//foo.bar/download&vcs_url=git%2Bhttps%3A//foo.bar/repo.git'
const expectedString = 'pkg:testing/name?checksum=blake3%3Aaa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d%2Csha-256%3Ac3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2&download_url=https%3A%2F%2Ffoo.bar%2Fdownload&vcs_url=git%2Bhttps%3A%2F%2Ffoo.bar%2Frepo.git'

const actual = sut.makeFromComponent(component, true)

Expand Down Expand Up @@ -213,7 +213,7 @@ suite('integration: Factories.PackageUrlFactory', () => {
vcs_url: 'git+https://foo.bar/repo.git'
}, undefined)
// expect objet's keys in alphabetical oder, expect sorted hash list
const expectedString = 'pkg:testing/name?download_url=https%3A//foo.bar/download-2&vcs_url=git%2Bhttps%3A//foo.bar/repo.git'
const expectedString = 'pkg:testing/name?download_url=https%3A%2F%2Ffoo.bar%2Fdownload-2&vcs_url=git%2Bhttps%3A%2F%2Ffoo.bar%2Frepo.git'

const actual1 = sut.makeFromComponent(component1, true)
const actual2 = sut.makeFromComponent(component2, true)
Expand Down