This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from snyk/decorate-package.json
feat: display vulns on dependencies in package.json
- Loading branch information
Showing
7 changed files
with
1,816 additions
and
1,945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export function getPackages(fileName, source) { | ||
const packages = []; | ||
|
||
const lines = []; | ||
source.split(/\r?\n/).forEach(function(line) { | ||
lines.push(line); | ||
}); | ||
|
||
const pjson = JSON.parse(source); | ||
|
||
for (var dep in pjson.dependencies) { | ||
var p = {}; | ||
p.fileName = fileName; | ||
p.name = dep; | ||
p.loc = findLoc(dep, lines); | ||
p.line = p.loc.start.line; | ||
packages.push(p); | ||
} | ||
|
||
return packages; | ||
} | ||
|
||
function findLoc(dep, lines) { | ||
const line = lines.find(x => x.includes('"' + dep + '"')); | ||
const index = lines.indexOf(line) + 1; | ||
|
||
var loc = { | ||
start: {}, | ||
end: {}, | ||
}; | ||
|
||
loc.start.line = index; | ||
loc.start.column = line.indexOf('"'); | ||
loc.end.line = index; | ||
loc.end.column = line.length - 1; | ||
return loc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters