Skip to content

Commit 3f7c4df

Browse files
authored
Make the purl object returned by getPurlObject have a PURL_Type (#647)
1 parent 30375ec commit 3f7c4df

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/commands/fix/npm-fix.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import type {
6464
NodeClass,
6565
} from '../../shadow/npm/arborist/types.mts'
6666
import type { CResult } from '../../types.mts'
67-
import type { PURL_Type } from '../../utils/alert/artifact.mts'
6867
import type { EnvDetails } from '../../utils/package-environment.mts'
6968
import type { RangeStyle } from '../../utils/semver.mts'
7069
import type { PackageJson } from '@socketsecurity/registry/lib/packages'
@@ -252,7 +251,7 @@ export async function npmFix(
252251
logger.indent()
253252
spinner?.indent()
254253

255-
if (getManifestData(partialPurlObj.type as PURL_Type, name)) {
254+
if (getManifestData(partialPurlObj.type, name)) {
256255
debugFn(`found: Socket Optimize variant for ${name}`)
257256
}
258257
// eslint-disable-next-line no-await-in-loop

src/commands/fix/pnpm-fix.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import { idToPurl } from '../../utils/spec.mts'
7070
import type { SocketBranchParseResult } from './git.mts'
7171
import type { NodeClass } from '../../shadow/npm/arborist/types.mts'
7272
import type { CResult, StringKeyValueObject } from '../../types.mts'
73-
import type { PURL_Type } from '../../utils/alert/artifact.mts'
7473
import type { EnvDetails } from '../../utils/package-environment.mts'
7574
import type { RangeStyle } from '../../utils/semver.mts'
7675
import type { PackageJson } from '@socketsecurity/registry/lib/packages'
@@ -327,7 +326,7 @@ export async function pnpmFix(
327326
logger.indent()
328327
spinner?.indent()
329328

330-
if (getManifestData(partialPurlObj.type as PURL_Type, name)) {
329+
if (getManifestData(partialPurlObj.type, name)) {
331330
debugFn(`found: Socket Optimize variant for ${name}`)
332331
}
333332
// eslint-disable-next-line no-await-in-loop

src/utils/purl.mts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import { PackageURL } from '@socketregistry/packageurl-js'
22

3-
import type { SocketArtifact } from './alert/artifact.mts'
3+
import type { PURL_Type, SocketArtifact } from './alert/artifact.mts'
44

5-
export function getPurlObject(purl: string | PackageURL | SocketArtifact) {
6-
return typeof purl === 'string' ? PackageURL.fromString(purl) : purl
5+
export function getPurlObject(purl: string): PackageURL & { type: PURL_Type }
6+
export function getPurlObject(
7+
purl: PackageURL,
8+
): PackageURL & { type: PURL_Type }
9+
export function getPurlObject(
10+
purl: SocketArtifact,
11+
): SocketArtifact & { type: PURL_Type }
12+
export function getPurlObject(
13+
purl: string | PackageURL | SocketArtifact,
14+
): (PackageURL | SocketArtifact) & { type: PURL_Type }
15+
export function getPurlObject(
16+
purl: string | PackageURL | SocketArtifact,
17+
): (PackageURL | SocketArtifact) & { type: PURL_Type } {
18+
return typeof purl === 'string'
19+
? (PackageURL.fromString(purl) as PackageURL & { type: PURL_Type })
20+
: (purl as (PackageURL | SocketArtifact) & { type: PURL_Type })
721
}

src/utils/socket-package-alert.mts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,7 @@ export function logAlertsMap(
555555
const pkgName = resolvePackageName(purlObj)
556556
const hyperlink = format.hyperlink(
557557
pkgName,
558-
getSocketDevPackageOverviewUrl(
559-
purlObj.type as PURL_Type,
560-
pkgName,
561-
purlObj.version,
562-
),
558+
getSocketDevPackageOverviewUrl(purlObj.type, pkgName, purlObj.version),
563559
)
564560
const isAboveTheFold = aboveTheFoldPurls.has(purl)
565561
if (isAboveTheFold) {

src/utils/socket-url.mts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ export function getSocketDevPackageOverviewUrlFromPurl(
2525
): string {
2626
const purlObj = getPurlObject(purl)
2727
const fullName = getPkgFullNameFromPurl(purlObj)
28-
return getSocketDevPackageOverviewUrl(
29-
purlObj.type as PURL_Type,
30-
fullName,
31-
purlObj.version,
32-
)
28+
return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version)
3329
}
3430

3531
export function getSocketDevPackageOverviewUrl(

0 commit comments

Comments
 (0)