@@ -175,7 +175,7 @@ async function fetchPackageData (pkgName, pkgVersion, { includeAllIssues }, spin
175
175
const issueSummary = formatSeverityCount ( severityCount )
176
176
console . log ( '\n' )
177
177
spinner [ strict ? 'fail' : 'succeed' ] ( `Package has these issues: ${ issueSummary } ` )
178
- formatPackageIssuesDetails ( data )
178
+ formatPackageIssuesDetails ( data , outputMarkdown )
179
179
} else {
180
180
console . log ( '\n' )
181
181
spinner . succeed ( 'Package has no issues' )
@@ -197,26 +197,35 @@ async function fetchPackageData (pkgName, pkgVersion, { includeAllIssues }, spin
197
197
198
198
/**
199
199
* @param {import('@socketsecurity/sdk').SocketSdkReturnType<'getIssuesByNPMPackage'>["data"] } packageData
200
+ * @param {boolean } outputMarkdown
200
201
* @returns {void[] }
201
202
*/
202
- function formatPackageIssuesDetails ( packageData ) {
203
+ function formatPackageIssuesDetails ( packageData , outputMarkdown ) {
203
204
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 ) => {
205
207
const { type } = issue
206
208
if ( type ) {
207
209
if ( ! acc [ type ] ) {
208
- acc [ type ] = 1
210
+ acc [ type ] = {
211
+ label : issue . value ?. label ,
212
+ count : 1
213
+ }
209
214
} else {
210
- acc [ type ] ++
215
+ // @ts -ignore
216
+ acc [ type ] . count += 1
211
217
}
212
218
}
213
219
return acc
214
220
} , { } )
221
+
222
+ const format = new ChalkOrMarkdown ( ! ! outputMarkdown )
215
223
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 } ` )
218
227
}
219
- return console . log ( `- ${ issue } : ${ uniqueIssues [ issue ] } ` )
228
+ return console . log ( `- ${ issueWithLink } : ${ uniqueIssues [ issue ] ?. count } ` )
220
229
} )
221
230
}
222
231
0 commit comments