Skip to content

Commit a0adde9

Browse files
committed
Add socket-url util
1 parent 3ca908e commit a0adde9

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/commands/info.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import meow from 'meow'
22
import colors from 'yoctocolors-cjs'
33

4+
import constants from '@socketsecurity/registry/lib/constants'
45
import { Spinner } from '@socketsecurity/registry/lib/spinner'
56

67
import { commonFlags, outputFlags, validationFlags } from '../flags'
@@ -14,11 +15,17 @@ import { formatSeverityCount, getSeverityCount } from '../utils/format-issues'
1415
import { getFlagListOutput } from '../utils/formatting'
1516
import { objectSome } from '../utils/objects'
1617
import { getPublicToken, setupSdk } from '../utils/sdk'
18+
import {
19+
getSocketDevAlertUrl,
20+
getSocketDevPackageOverviewUrl
21+
} from '../utils/socket-url'
1722

1823
import type { SocketIssue } from '../utils/format-issues'
1924
import type { CliSubcommand } from '../utils/meow-with-subcommands'
2025
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
2126

27+
const { NPM } = constants
28+
2229
export const info: CliSubcommand = {
2330
description: 'Look up info regarding a package',
2431
async run(argv, importMeta, { parentName }) {
@@ -208,7 +215,7 @@ function formatPackageDataOutput(
208215
}
209216

210217
const format = new ColorOrMarkdown(!!outputMarkdown)
211-
const url = `https://socket.dev/npm/package/${pkgName}/overview/${pkgVersion}`
218+
const url = getSocketDevPackageOverviewUrl(NPM, pkgName, pkgVersion)
212219

213220
console.log('\n')
214221
if (pkgVersion === 'latest') {
@@ -267,7 +274,7 @@ function formatPackageIssuesDetails(
267274
for (const issue of Object.keys(uniqueIssues)) {
268275
const issueWithLink = format.hyperlink(
269276
`${uniqueIssues[issue]?.label}`,
270-
`https://socket.dev/npm/issue/${issue}`,
277+
getSocketDevAlertUrl(issue),
271278
{ fallbackToUrl: true }
272279
)
273280
if (uniqueIssues[issue]?.count === 1) {

src/shadow/arborist/lib/arborist/reify.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { kCtorArgs, kRiskyReify } from './index'
1616
import constants from '../../../../constants'
1717
import { uxLookup } from '../../../../utils/alert-rules'
1818
import { ColorOrMarkdown } from '../../../../utils/color-or-markdown'
19+
import { getSocketDevPackageOverviewUrl } from '../../../../utils/socket-url'
1920
import { pacotePath } from '../../../npm-paths'
2021
import { Edge, SafeEdge } from '../edge'
2122

@@ -187,7 +188,7 @@ async function getPackagesAlerts(
187188
}
188189
if (displayWarning && spinner) {
189190
spinner.stop(
190-
`(socket) ${formatter.hyperlink(id, `https://socket.dev/npm/package/${name}/overview/${version}`)} contains risks:`
191+
`(socket) ${formatter.hyperlink(id, getSocketDevPackageOverviewUrl(NPM, name, version))} contains risks:`
191192
)
192193
}
193194
alerts.sort((a, b) => (a.type < b.type ? -1 : 1))

src/utils/socket-url.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function getSocketDevAlertUrl(alertType: string): string {
2+
return `https://socket.dev/alerts/${alertType}`
3+
}
4+
5+
export function getSocketDevPackageOverviewUrl(
6+
eco: string,
7+
name: string,
8+
version?: string
9+
): string {
10+
return `https://socket.dev/${eco}/package/${name}${version ? `/overview/${version}` : ''}`
11+
}

0 commit comments

Comments
 (0)