Skip to content

Commit 5431556

Browse files
aegilopsCopilot
andauthored
Update src/sbomCollector.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ba8ff05 commit 5431556

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

src/sbomCollector.ts

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -591,42 +591,48 @@ export class SbomCollector {
591591
const queries: ParsedQuery[] = purls.map(parseQuery).filter((q): q is ParsedQuery => !!q);
592592
const results = new Map<string, { purl: string; reason: string }[]>();
593593
if (!queries.length) return results;
594-
const applyQueries = (candidatePurls: string[], queries: ParsedQuery[], found: Map<string, string>, branchTag?: string, fallbackVersion?: string) => {
595-
const unique = Array.from(new Set(candidatePurls));
596-
for (const p of unique) {
597-
const pLower = p.toLowerCase();
598-
const outKey = branchTag ? `${p}@${branchTag}` : p;
599-
for (const q of queries) {
600-
if (q.isPrefixWildcard) {
601-
const prefix = q.lower.slice(0, -1);
602-
if (pLower.startsWith(prefix)) { if (!found.has(outKey)) found.set(outKey, q.raw); }
603-
continue;
604-
}
605-
if (q.versionConstraint && q.type && q.name) {
606-
if (!pLower.startsWith("pkg:")) continue;
607-
const body = p.slice(4);
608-
const atIdx = body.indexOf("@");
609-
const main = atIdx >= 0 ? body.slice(0, atIdx) : body;
610-
const ver = atIdx >= 0 ? body.slice(atIdx + 1) : fallbackVersion;
611-
const slashIdx = main.indexOf("/");
612-
if (slashIdx < 0) continue;
613-
const pType = main.slice(0, slashIdx).toLowerCase();
614-
const pName = main.slice(slashIdx + 1);
615-
if (pType === q.type && pName.toLowerCase() === q.name.toLowerCase() && ver) {
616-
try {
617-
const coerced = semver.coerce(ver)?.version || ver;
618-
if (semver.valid(coerced) && semver.satisfies(coerced, q.versionConstraint, { includePrerelease: true })) {
619-
if (!found.has(outKey)) found.set(outKey, q.raw);
620-
}
621-
} catch { /* ignore */ }
594+
// Move applyQueries to module scope
595+
function applyQueries(
596+
candidatePurls: string[],
597+
queries: ParsedQuery[],
598+
found: Map<string, string>,
599+
branchTag?: string,
600+
fallbackVersion?: string
601+
) {
602+
const unique = Array.from(new Set(candidatePurls));
603+
for (const p of unique) {
604+
const pLower = p.toLowerCase();
605+
const outKey = branchTag ? `${p}@${branchTag}` : p;
606+
for (const q of queries) {
607+
if (q.isPrefixWildcard) {
608+
const prefix = q.lower.slice(0, -1);
609+
if (pLower.startsWith(prefix)) { if (!found.has(outKey)) found.set(outKey, q.raw); }
610+
continue;
611+
}
612+
if (q.versionConstraint && q.type && q.name) {
613+
if (!pLower.startsWith("pkg:")) continue;
614+
const body = p.slice(4);
615+
const atIdx = body.indexOf("@");
616+
const main = atIdx >= 0 ? body.slice(0, atIdx) : body;
617+
const ver = atIdx >= 0 ? body.slice(atIdx + 1) : fallbackVersion;
618+
const slashIdx = main.indexOf("/");
619+
if (slashIdx < 0) continue;
620+
const pType = main.slice(0, slashIdx).toLowerCase();
621+
const pName = main.slice(slashIdx + 1);
622+
if (pType === q.type && pName.toLowerCase() === q.name.toLowerCase() && ver) {
623+
try {
624+
const coerced = semver.coerce(ver)?.version || ver;
625+
if (semver.valid(coerced) && semver.satisfies(coerced, q.versionConstraint, { includePrerelease: true })) {
626+
if (!found.has(outKey)) found.set(outKey, q.raw);
622627
}
623-
} else if (q.exact) {
624-
if (pLower === q.exact) { if (!found.has(outKey)) found.set(outKey, q.raw); }
625-
}
628+
} catch { /* ignore */ }
626629
}
630+
} else if (q.exact) {
631+
if (pLower === q.exact) { if (!found.has(outKey)) found.set(outKey, q.raw); }
627632
}
628-
};
629-
633+
}
634+
}
635+
}
630636
for (const repoSbom of this.sboms) {
631637
if (repoSbom.error) continue;
632638
interface ExtRef { referenceType: string; referenceLocator: string }

0 commit comments

Comments
 (0)