Conversation
`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`.
8a574ac to
8c3cf28
Compare
PR Reviewer Guide 🔍
|
|
Re: PR Bot's Potential Runtime Crash The However, we are vulnerable to anyone updating the legacy logic and adding a string method. I think it is unlikely anyone decides to change this depreciated part of the code base, but it is a risk. The long-term fix is to update our code to build a graph rather than a tree. |
|
🎉 This PR is included in version 9.6.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What does this PR do?
Resolves TypeScript compilation errors caused by the update of
snyk-nodejs-lockfile-parserto^2.2.3. The lockfile parser update introduced type signature changes that became incompatible with thelegacy.depTreeToGraphfunction in@snyk/dep-graph.Where should the reviewer start?
lib/analyzer/applications/node.ts: Look at the modifications tostripUndefinedLabels,depGraphFromNodeModules, andbuildDepGraphFromDepTree.test/system/application-scans/node.spec.ts: Test file adjustments.How should this be manually tested?
npm run buildand ensure TypeScript compiles without errors.npm run testto verify that the application scans still parse node dependencies and build the graph correctly.Any background context you want to provide?
Justification for casting types as
any:The
snyk-nodejs-lockfile-parserupdate altered theDepTreeDepinterface so that thelabelsobject now supports anAliastype:{ [key: string]: string | Alias | undefined }.However,
@snyk/dep-graph's legacyDepTreetype expects labels to be strictly{ [key: string]: string | undefined }.Because of this mismatch between the two libraries' typings, passing the parsed
PkgTreedirectly intolegacy.depTreeToGraphresults in TS2345 errors.Why it is necessary:
Without updating the upstream
@snyk/dep-graphlegacy types (which is deprecated and ideally shouldn't be touched), we have to bridge the gap locally.stripUndefinedLabelswas updated to handleRecord<string, any>so it can stripundefinedfields without crashing onAliasvalues.Why it will not lead to type issues:
Casting
PkgTreetoanyat the boundary oflegacy.depTreeToGraphis safe because@snyk/dep-graphprocesses the tree at runtime without enforcing strict primitivestringtype checks on the label values. TheAliasinformation flows through successfully to theDepGraphconstruction without causing runtime exceptions. By restricting theanycast strictly to the function call arguments (pkgTree as any), we preserve type safety in the rest of the application while appeasing the compiler at the deprecated legacy API boundary.What are the relevant tickets?
CN-1007
Screenshots
N/A
Additional questions
N/A