fix duplicate dependency analysis for workspace links#201
fix duplicate dependency analysis for workspace links#201tristanmanchester wants to merge 2 commits intoe18e:mainfrom
Conversation
dreyfus92
left a comment
There was a problem hiding this comment.
hey @tristanmanchester thank you for taking the time in working on this 😄, i left a 🤏🏻 nit.
| function hasResolvedVersion( | ||
| pkg: Pick<ParsedLockFile['packages'][number], 'version'> | ||
| ): pkg is Pick<ParsedLockFile['packages'][number], 'version'> & { | ||
| version: string; | ||
| } { | ||
| return typeof pkg.version === 'string' && pkg.version.length > 0; | ||
| } | ||
|
|
There was a problem hiding this comment.
this is logically fine but a bit hard to read, and tying it to Pick<ParsedLockFile['packages'][number], 'version'> is redundant in practice (packages is ParsedDependency[] in lockparse). i’d drop the helper and inline an early continue, e.g.
if (typeof pkg.version !== 'string' || pkg.version.length === 0) continueThere was a problem hiding this comment.
Yep makes sense! i wanted to keep the runtime guard because npm workspace links can show up without a version even though lockparse types it as string, but agreed the helper can be removed. I inlined the early continue instead
commit: |
|
hmm while this does fix it, i think we actually have our types wrong in lockparse and should just check currently, we have: which references this: but that isn't entirely accurate since workspace packages show up like this in the actual JSON: "node_modules/@43081j/sdk": {
"resolved": "packages/sdk",
"link": true
},so i think the better solution here is that lockparse has this type instead: packages: Record<string, NpmLockFilePackage | NpmLockFilePackageLink>;which is a new type: interface NpmLockFilePackageLink {
resolved: string;
link: true;
}there's no real reference for this from npm themselves afaik so we're doing a bit of guesswork here. but then the change in this PR could continue checking |
|
Hmm yes you’re right about the underlying issue being in npm does seem to emit workspace entries like Also I checked for a So I think this PRs guard is still the practical fix here, and the better long-term fix is upstream in |
|
yes i am saying lockparse should change first 👍 |
|
Ah I misunderstood, make sense, I'll close :) |
|
Ah I misunderstood, make sense, I'll close :) |
1 similar comment
|
Ah I misunderstood, make sense, I'll close :) |
Summary
Root cause
npm workspaces can appear in package-lock parsing as linked packages without a version. The duplicate dependency analyzer treated every package entry as a concrete installed version and passed an undefined version string into node:util styleText, which crashed analysis on Node 24.
Validation