Skip to content

Commit

Permalink
Add scanning of filenames in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
eoftedal committed Mar 12, 2024
1 parent f08c5af commit 453c40a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.1

Add file name scanning

## 1.1.0

Add AST scanning
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Erlend Oftedal <[email protected]>",
"name": "retire-site-scanner",
"version": "1.1.0",
"version": "1.1.1",
"license": "Apache-2.0",
"description": "A scanner for checking a web site using retire.js",
"main": "dist/index.js",
Expand Down
26 changes: 13 additions & 13 deletions src/retireWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ async function loadRetireJSRepo() {

function scanUri(repo: Repository, uri: string): Array<Component> {
const uriResults = retire.scanUri(uri, repo);
return convertResults(uriResults || [], "scanning the URL");
const fileName = uri.split("/").slice(-1)[0].split("?")[0];
const fileNameResults = retire.scanFileName(fileName, repo);
return convertResults(uriResults.concat(fileNameResults), "scanning the URL");
}

function scanContent(repo: Repository, contents: string): Array<Component> {
const contentResults = retire.scanFileContent(contents, repo, hasher);
const deepScanResults = deepScan(contents, repo);
const combined = contentResults.concat(deepScanResults).reduce((acc, c) => {
const combined = contentResults.concat(deepScanResults);
return convertResults(combined || [], "scanning content");
}

function convertResults(
data: Component[],
detectedBy: string,
): Array<Component> {
const res = data.reduce((acc, c) => {
if (
!acc.some((a) => a.component === c.component && a.version === c.version)
) {
c.detection = c.detection ?? detectedBy;
acc.push(c);
}
return acc;
}, [] as Component[]);

return convertResults(combined || [], "scanning content");
}

function convertResults(
res: Component[],
detectedBy: string,
): Array<Component> {
res.forEach((r) => {
r.detection = r.detection ?? detectedBy;
});
return res;
}

Expand Down

0 comments on commit 453c40a

Please sign in to comment.