@@ -4,12 +4,12 @@ import fs from "node:fs";
44// Import Third-party Dependencies
55import { getScoreColor , getVCSRepositoryPathAndPlatform } from "@nodesecure/utils" ;
66import { getManifest , getFlags } from "@nodesecure/flags/web" ;
7- import * as scorecard from "@nodesecure/ossf-scorecard-sdk" ;
87import { Extractors , type Payload , type Dependency , type DependencyVersion , type DependencyLinks } from "@nodesecure/scanner" ;
98import type { RC } from "@nodesecure/rc" ;
109
1110// Import Internal Dependencies
1211import * as localStorage from "../localStorage.ts" ;
12+ import { fetchScorecardScore } from "./fetch.ts" ;
1313
1414// CONSTANTS
1515const kFlagsList = Object . values ( getManifest ( ) ) ;
@@ -54,10 +54,10 @@ export interface BuildScannerStatsOptions {
5454 reportConfig ?: RC [ "report" ] ;
5555}
5656
57- export async function buildStatsFromScannerDependencies (
57+ export function buildStatsFromScannerDependencies (
5858 payloadFiles : string [ ] | Payload [ "dependencies" ] = [ ] ,
5959 options : BuildScannerStatsOptions = Object . create ( null )
60- ) : Promise < ReportStat > {
60+ ) : ReportStat {
6161 const { reportConfig } = options ;
6262
6363 const config = reportConfig ?? localStorage . getConfig ( ) . report ! ;
@@ -180,22 +180,26 @@ export async function buildStatsFromScannerDependencies(
180180 return acc ;
181181 } , { } ) ;
182182
183- const givenPackages = Object . values ( stats . packages ) . filter ( ( pkg ) => pkg . isGiven ) ;
183+ stats . packages_count . all = Object . keys ( stats . packages ) . length ;
184+ stats . packages_count . internal = stats . packages_count . all - stats . packages_count . external ;
185+ stats . scorecards = { } ;
186+
187+ return stats ;
188+ }
184189
190+ export async function buildGivenPackagesScorecards ( stats : ReportStat ) : Promise < ReportStat [ "scorecards" ] > {
191+ const givenPackages = Object . values ( stats . packages ) . filter ( ( pkg ) => pkg . isGiven ) ;
192+ const scorecards : ReportStat [ "scorecards" ] = { } ;
185193 await Promise . all ( givenPackages . map ( async ( pkg ) => {
186194 const { fullName } = pkg ;
187- const { score } = await scorecard . result ( fullName , { resolveOnVersionControl : false } ) ;
195+ const score = await fetchScorecardScore ( fullName ) ;
188196 const [ repo , platform ] = getVCSRepositoryPathAndPlatform ( pkg . links ?. repository ) ?? [ ] ;
189- stats . scorecards [ fullName ] = {
197+ scorecards [ fullName ] = {
190198 score,
191199 color : getScoreColor ( score ) ,
192200 visualizerUrl : repo ? `${ kScorecardVisualizerUrl } /${ platform } /${ repo } ` : "#"
193201 } ;
194202 } ) ) ;
195203
196- stats . packages_count . all = Object . keys ( stats . packages ) . length ;
197- stats . packages_count . internal = stats . packages_count . all - stats . packages_count . external ;
198-
199- return stats ;
204+ return scorecards ;
200205}
201-
0 commit comments