Skip to content
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
3 changes: 1 addition & 2 deletions src/commands/fix/npm-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import type {
NodeClass,
} from '../../shadow/npm/arborist/types.mts'
import type { CResult } from '../../types.mts'
import type { PURL_Type } from '../../utils/alert/artifact.mts'
import type { EnvDetails } from '../../utils/package-environment.mts'
import type { RangeStyle } from '../../utils/semver.mts'
import type { PackageJson } from '@socketsecurity/registry/lib/packages'
Expand Down Expand Up @@ -252,7 +251,7 @@ export async function npmFix(
logger.indent()
spinner?.indent()

if (getManifestData(partialPurlObj.type as PURL_Type, name)) {
if (getManifestData(partialPurlObj.type, name)) {
debugFn(`found: Socket Optimize variant for ${name}`)
}
// eslint-disable-next-line no-await-in-loop
Expand Down
3 changes: 1 addition & 2 deletions src/commands/fix/pnpm-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import { idToPurl } from '../../utils/spec.mts'
import type { SocketBranchParseResult } from './git.mts'
import type { NodeClass } from '../../shadow/npm/arborist/types.mts'
import type { CResult, StringKeyValueObject } from '../../types.mts'
import type { PURL_Type } from '../../utils/alert/artifact.mts'
import type { EnvDetails } from '../../utils/package-environment.mts'
import type { RangeStyle } from '../../utils/semver.mts'
import type { PackageJson } from '@socketsecurity/registry/lib/packages'
Expand Down Expand Up @@ -327,7 +326,7 @@ export async function pnpmFix(
logger.indent()
spinner?.indent()

if (getManifestData(partialPurlObj.type as PURL_Type, name)) {
if (getManifestData(partialPurlObj.type, name)) {
debugFn(`found: Socket Optimize variant for ${name}`)
}
// eslint-disable-next-line no-await-in-loop
Expand Down
20 changes: 17 additions & 3 deletions src/utils/purl.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { PackageURL } from '@socketregistry/packageurl-js'

import type { SocketArtifact } from './alert/artifact.mts'
import type { PURL_Type, SocketArtifact } from './alert/artifact.mts'

export function getPurlObject(purl: string | PackageURL | SocketArtifact) {
return typeof purl === 'string' ? PackageURL.fromString(purl) : purl
export function getPurlObject(purl: string): PackageURL & { type: PURL_Type }
export function getPurlObject(
purl: PackageURL,
): PackageURL & { type: PURL_Type }
export function getPurlObject(
purl: SocketArtifact,
): SocketArtifact & { type: PURL_Type }
export function getPurlObject(
purl: string | PackageURL | SocketArtifact,
): (PackageURL | SocketArtifact) & { type: PURL_Type }
export function getPurlObject(
purl: string | PackageURL | SocketArtifact,
): (PackageURL | SocketArtifact) & { type: PURL_Type } {
return typeof purl === 'string'
? (PackageURL.fromString(purl) as PackageURL & { type: PURL_Type })
: (purl as (PackageURL | SocketArtifact) & { type: PURL_Type })
}
6 changes: 1 addition & 5 deletions src/utils/socket-package-alert.mts
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,7 @@ export function logAlertsMap(
const pkgName = resolvePackageName(purlObj)
const hyperlink = format.hyperlink(
pkgName,
getSocketDevPackageOverviewUrl(
purlObj.type as PURL_Type,
pkgName,
purlObj.version,
),
getSocketDevPackageOverviewUrl(purlObj.type, pkgName, purlObj.version),
)
const isAboveTheFold = aboveTheFoldPurls.has(purl)
if (isAboveTheFold) {
Expand Down
6 changes: 1 addition & 5 deletions src/utils/socket-url.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export function getSocketDevPackageOverviewUrlFromPurl(
): string {
const purlObj = getPurlObject(purl)
const fullName = getPkgFullNameFromPurl(purlObj)
return getSocketDevPackageOverviewUrl(
purlObj.type as PURL_Type,
fullName,
purlObj.version,
)
return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version)
}

export function getSocketDevPackageOverviewUrl(
Expand Down