Skip to content

fix(lockfiles) detect v1 lockfiles and shrinkwraps without lockfileVersion#27

Merged
indexzero merged 1 commit intomainfrom
fix/lockfile-v1-no-version
Apr 15, 2026
Merged

fix(lockfiles) detect v1 lockfiles and shrinkwraps without lockfileVersion#27
indexzero merged 1 commit intomainfrom
fix/lockfile-v1-no-version

Conversation

@indexzero
Copy link
Copy Markdown
Owner

What

tryParseNpm in src/detect.js now recognizes v1 lockfiles and shrinkwrap files that omit the lockfileVersion field. When lockfileVersion is absent, a fallback heuristic checks for a dependencies tree with object values — distinguishing lockfiles from package.json where dependency values are version-range strings.

Why

tryParseNpm required typeof parsed.lockfileVersion === 'number', so v1 files without lockfileVersion failed content-based detection and threw "Unable to detect lockfile type." The fromPackageLock parser already handled these files correctly via the fromDependenciesTree fallback — only routing in detectType was broken.

Risk Assessment

Low risk: The new heuristic only activates when lockfileVersion is absent. All existing detection paths (v1 with lockfileVersion, v2, v3) are unchanged. A guard test confirms package.json files are not misidentified. 469 tests pass.

References

…rsion

v1 lockfiles and npm-shrinkwrap.json files often omit the lockfileVersion
field entirely. tryParseNpm required typeof lockfileVersion === 'number',
so these files failed content-based detection. The parser (fromPackageLock)
already handled them via the fromDependenciesTree fallback — only routing
in detectType was broken.

The new heuristic checks for a dependencies tree with object values (which
distinguishes lockfiles from package.json where values are version-range
strings).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@indexzero indexzero merged commit 234e878 into main Apr 15, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant