Skip to content

Commit

Permalink
Support lockFileVersion 3
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen committed Feb 17, 2023
1 parent b320fff commit 6fded38
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 40 deletions.
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

133 changes: 100 additions & 33 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
Expand Up @@ -21,7 +21,7 @@
"js-base64": "^3.7.2",
"markdown-table": "^3.0.2",
"semver": "^7.3.7",
"snyk-nodejs-lockfile-parser": "^1.38.0"
"snyk-nodejs-lockfile-parser": "^1.47.3"
},
"devDependencies": {
"@babel/core": "^7.17.9",
Expand Down
9 changes: 5 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const formatForVersionCompare = (key) => {

const formatLockEntry = (obj) =>
Object.fromEntries(
Object.entries(obj.dependencies)
.map(([key, { version }]) => `${key}@${version}`)
Object.entries(obj.dependencies || obj.packages)
.map(([key, { version }]) => `${key.replace(/\bnode_modules\//g, '')}@${version}`)
.filter((a) => a.split('/').length === (a[0] === '@' ? 2 : 1))
.sort((a, b) => {
const nameCompare = formatForNameCompare(a).localeCompare(formatForNameCompare(b))
if (nameCompare === 0) {
Expand All @@ -32,8 +33,8 @@ const formatLockEntry = (obj) =>
})
.map((key) => {
const nameParts = key.split('@')
const name = nameParts[0] === '' ? '@' + nameParts[1] : nameParts[0]
const version = nameParts[0] === '' ? nameParts[2] : nameParts[1]
const version = nameParts.pop()
const name = nameParts.join('@')
return [name, { name, version }]
})
)
Expand Down

0 comments on commit 6fded38

Please sign in to comment.