@@ -175,7 +175,7 @@ async function fetchPackageData (pkgName, pkgVersion, { includeAllIssues }, spin
175175 const issueSummary = formatSeverityCount ( severityCount )
176176 console . log ( '\n' )
177177 spinner [ strict ? 'fail' : 'succeed' ] ( `Package has these issues: ${ issueSummary } ` )
178- formatPackageIssuesDetails ( data )
178+ formatPackageIssuesDetails ( data , outputMarkdown )
179179 } else {
180180 console . log ( '\n' )
181181 spinner . succeed ( 'Package has no issues' )
@@ -197,26 +197,35 @@ async function fetchPackageData (pkgName, pkgVersion, { includeAllIssues }, spin
197197
198198/**
199199 * @param {import('@socketsecurity/sdk').SocketSdkReturnType<'getIssuesByNPMPackage'>["data"] } packageData
200+ * @param {boolean } outputMarkdown
200201 * @returns {void[] }
201202 */
202- function formatPackageIssuesDetails ( packageData ) {
203+ function formatPackageIssuesDetails ( packageData , outputMarkdown ) {
203204 const issueDetails = packageData . filter ( d => d . value ?. severity === 'high' || d . value ?. severity === 'critical' )
204- const uniqueIssues = issueDetails . reduce ( ( /** @type {{ [key: string]: number } } */ acc , issue ) => {
205+
206+ const uniqueIssues = issueDetails . reduce ( ( /** @type {{ [key: string]: {count: Number, label: string | undefined} } } */ acc , issue ) => {
205207 const { type } = issue
206208 if ( type ) {
207209 if ( ! acc [ type ] ) {
208- acc [ type ] = 1
210+ acc [ type ] = {
211+ label : issue . value ?. label ,
212+ count : 1
213+ }
209214 } else {
210- acc [ type ] ++
215+ // @ts -ignore
216+ acc [ type ] . count += 1
211217 }
212218 }
213219 return acc
214220 } , { } )
221+
222+ const format = new ChalkOrMarkdown ( ! ! outputMarkdown )
215223 return Object . keys ( uniqueIssues ) . map ( issue => {
216- if ( uniqueIssues [ issue ] === 1 ) {
217- return console . log ( `- ${ issue } ` )
224+ const issueWithLink = format . hyperlink ( `${ uniqueIssues [ issue ] ?. label } ` , `https://socket.dev/npm/issue/${ issue } ` , { fallbackToUrl : true } )
225+ if ( uniqueIssues [ issue ] ?. count === 1 ) {
226+ return console . log ( `- ${ issueWithLink } ` )
218227 }
219- return console . log ( `- ${ issue } : ${ uniqueIssues [ issue ] } ` )
228+ return console . log ( `- ${ issueWithLink } : ${ uniqueIssues [ issue ] ?. count } ` )
220229 } )
221230}
222231
0 commit comments