| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
npm omits the dependencies key from lockfileVersion 1 lockfiles when a project has no dependencies, but the legacy package-lock parser required it, failing the whole npm analysis with: Error in $: key "dependencies" not found Make the key optional with an empty-map default (matching the adjacent packages key) so zero-dependency projects analyze to an empty graph. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UApS6wgijxhbJUQYKb1nRj
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info ⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: eedf46db-9483-48df-8da6-5e48ef6e6c15 📥 CommitsReviewing files that changed from the base of the PR and between 3b42606 and c959bf0. 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. WalkthroughThe npm PkgLockJson parser now treats the top-level dependencies key as optional and uses an empty map when it is absent. A test fixture and parsing test cover a dependency-free npm lockfile. The changelog records this behavior. Merge Risk: ⚪ Minimal · up to c959b This localized parser change allows valid dependency-free npm lockfiles to analyze successfully without changing documented behavior; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5 ✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. ❤️ ShareComment @coderabbitai help to get the list of available commands. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Overview
fossa analyze fails npm analysis on package-lock.json files that have no top-level dependencies key, with:
npm legitimately omits the dependencies key when a project has zero dependencies (lockfileVersion 1 lockfiles for dependency-less packages are just {"name": ..., "version": ..., "lockfileVersion": 1}). Such a file also has no packages key, so detectNpmLockVersion routes it to the legacy (v1) parser, whose PkgLockJson FromJSON instance hard-required dependencies — failing the whole NpmProjectType analysis on a valid, npm-generated lockfile. This is the package-lock.json counterpart of the project.json fix in #1747.
This PR makes the key optional, defaulting to an empty map (exactly how the adjacent packages key is already handled), so a zero-dependency project analyzes successfully with an empty dependency graph.
Internal parser fix: no user-visible schema, CLI flag, or documented behavior change, so the docs/schema checklist items don't apply.
Acceptance criteria
Running fossa analyze on a project whose package-lock.json lacks a top-level dependencies key no longer fails with Error in $: key "dependencies" not found; the npm target analyzes successfully and reports no dependencies.
Testing plan
Added a regression test (test/Node/PackageLockSpec.hs) parsing a zero-dependency lockfile fixture (test/Node/testdata/no-dependencies-package-lock.json), which fails against the previous parser and passes with this change. Ran make fmt (fourmolu clean), hlint (no hints), and the Node-matched unit tests (86 examples, 0 failures).
To verify manually:
Risks
A lockfile with neither dependencies nor packages that is malformed for some other reason now yields an empty graph instead of a fatal parse error. Since discovery only feeds real package-lock.json files here and an empty graph is the honest result for a lockfile that lists nothing, this seems strictly better than failing the analysis.
Metrics
This error pattern is visible on the fossa-cli-dashboard error patterns widget (14 occurrences of the package-lock.json variant in the 2026-08-20T22:54Z–2026-08-21T07:20Z scan window, ~279/week extrapolated).
References
Checklist
This PR description was generated with Claude Code
Generated by Claude Code