Skip to content

Commit b814413

Browse files
authored
fix(deps): update node lockfile parser (#785)
`snyk-nodejs-lockfile-parser` v2.2.3 introduced type signature changes that became incompatible with the `legacy.depTreeToGraph` function in `@snyk/dep-graph`. This commit bridges the gap between `@snyk/dep-graph` and `snyk-nodejs-lockfile-parser` by casting the `DepTreeDep.labels` object as `any`.
1 parent cfe7050 commit b814413

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

lib/analyzer/applications/node.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function depGraphFromNodeModules(
136136
}
137137

138138
const depGraph = await legacy.depTreeToGraph(
139-
pkgTree,
139+
pkgTree as any,
140140
pkgTree.type || "npm",
141141
);
142142

@@ -417,7 +417,7 @@ function stripUndefinedLabels(
417417
parserResult: lockFileParser.PkgTree,
418418
): lockFileParser.PkgTree {
419419
const optionalLabels = parserResult.labels;
420-
const mandatoryLabels: Record<string, string> = {};
420+
const mandatoryLabels: Record<string, any> = {};
421421
if (optionalLabels) {
422422
for (const currentLabelName of Object.keys(optionalLabels)) {
423423
if (optionalLabels[currentLabelName] !== undefined) {
@@ -428,7 +428,7 @@ function stripUndefinedLabels(
428428
const parserResultWithProperLabels = Object.assign({}, parserResult, {
429429
labels: mandatoryLabels,
430430
});
431-
return parserResultWithProperLabels;
431+
return parserResultWithProperLabels as lockFileParser.PkgTree;
432432
}
433433

434434
async function buildDepGraph(
@@ -513,7 +513,10 @@ async function buildDepGraphFromDepTree(
513513
// Don't provide a default manifest file name, prefer the parser to infer it.
514514
);
515515
const strippedLabelsParserResult = stripUndefinedLabels(parserResult);
516-
return await legacy.depTreeToGraph(strippedLabelsParserResult, lockfileType);
516+
return await legacy.depTreeToGraph(
517+
strippedLabelsParserResult as any,
518+
lockfileType,
519+
);
517520
}
518521

519522
export function getLockFileVersion(

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"packageurl-js": "1.2.0",
5151
"semver": "^7.7.3",
5252
"shescape": "^2.1.7",
53-
"snyk-nodejs-lockfile-parser": "^2.2.2",
53+
"snyk-nodejs-lockfile-parser": "^2.7.0",
5454
"snyk-poetry-lockfile-parser": "1.9.1",
5555
"snyk-resolve-deps": "^4.9.1",
5656
"tar-stream": "^2.2.0",

test/system/application-scans/node.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ describe("node application scans", () => {
403403
noFromArrays: true,
404404
});
405405

406-
const depGraph = await legacy.depTreeToGraph(depRes, "npm");
406+
const depGraph = await legacy.depTreeToGraph(depRes as any, "npm");
407407

408408
expect(depGraph.rootPkg.name).toEqual("app");
409409
expect(depGraph.rootPkg.version).toBe(undefined);

0 commit comments

Comments
 (0)