feat: resolve exact installed versions from the lockfile#3
Merged
Conversation
Implement NamedRange type and resolveNpmVersions function to parse npm lockfiles (v1 nested dependencies and v2/v3 flat packages map formats), with proper fallback behavior when packages map lacks an entry. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Removes ~13 lines of near-duplicate logic that converted an ApiPackageResponse into a scored PackageScore or 'not-found', which had been copy-pasted between fetchScore and the tail of fetchOrCrawl. Pure refactor; no observable behavior change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This action previously only discovered package names from
package.json, never the actual installed version —score.tscalledGET /packages/:namewith no version parameter, so packagerating.com scored whatever it considered "latest" for each dependency. Two versions of the same package can score very differently (a CVE fixed in a patch release, a maintenance cliff at a specific major version), so an audit that ignores the installed version can both miss real risk and flag risk that doesn't apply to what's actually running.This PR resolves each discovered package's exact installed version from the project's lockfile and threads it into the packagerating API, which already supports version-specific scoring end-to-end (
GET /packages/:name?version=X— shipped separately, earlier today, in thepackage-ratingAPI repo).Supported: npm (
package-lock.json, lockfileVersion 1 and 2/3), yarn Classic (yarn.lockv1), pnpm (pnpm-lock.yaml, both theimporters['.']and legacy root-level structures). Auto-detected next topackage.json, in that priority order.Not supported (falls back to unversioned, never a hard failure): Yarn Berry (v2+) and PnP mode, npm/pnpm workspaces, transitive dependency versions beyond what's explicitly named via the
packagesinput.New
use-lockfileinput (defaulttrue) fully reverts to today's behavior when set tofalse.A necessary refactor along the way
score.ts's old crawl-trigger path calledPOST /packages/crawl— a batch endpoint that has no version parameter and never will. That call is now removed entirely: the single-packageGET /packages/:name?version=Xendpoint already auto-triggers a crawl on a miss and returns ajob_idin its202response, sofetchScoreOnceandcrawlAndWaitcollapsed into onefetchOrCrawlthat triggers, polls, and re-fetches without any redundant round trip.Implementation notes
score.tsrefactor (Task 6) was the highest-risk task — reviewer confirmed zeroPOST /packages/crawlcalls survive,job_idis reused from the initial response rather than re-fetched, and?version=is correctly omitted (not the literal string"null") when unresolved. One Important finding (duplicated response-parsing logic between two functions) was fixed and independently re-verified via a traced before/after comparison.discoverPackages → index.ts → scorePackages → ?version=data-flow chain in the merged code (not just per-task diffs) and confirmed no field/argument drift across the three files it spans.Test plan
npm run buildsucceeds🤖 Generated with Claude Code