FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[ANE-Bot] Tolerate package-lock.json without a dependencies key by fossa-ane-bot · Pull Request #1753 · fossas/fossa-cli · GitHub

[ANE-Bot] Tolerate package-lock.json without a dependencies key - #1753

Merged
tjugdev merged 1 commit into
masterfrom
fossa-cli-fix-2026-08-21
Aug 21, 2026
Merged

[ANE-Bot] Tolerate package-lock.json without a dependencies key#1753
tjugdev merged 1 commit into
masterfrom
fossa-cli-fix-2026-08-21

Conversation

Copy link
Copy Markdown
Contributor

Overview

fossa analyze fails npm analysis on package-lock.json files that have no top-level dependencies key, with:

Error: parsing file: .../package-lock.json
  Error in $: key "dependencies" not found

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:

  1. Build the CLI: make build-cli (or cabal build).
  2. Create a directory containing a package.json ({"name": "empty-project", "version": "1.0.0"}) and a package-lock.json containing only {"name": "empty-project", "version": "1.0.0", "lockfileVersion": 1}.
  3. Run fossa analyze --output in that directory. Before this change the npm target fails with Error in $: key "dependencies" not found; with this change analysis succeeds with an empty dependency graph.

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

  • I added tests for this PR's change (or explained in the PR description why tests don't make sense).
  • If this PR introduced a user-visible change, I added documentation into docs/.
  • If this PR added docs, I added links as appropriate to the user manual's ToC in docs/README.ms and gave consideration to how discoverable or not my documentation is.
  • If this change is externally visible, I updated Changelog.md. If this PR did not mark a release, I added my changes into an ## Unreleased section at the top.
  • If I made changes to .fossa.yml or fossa-deps.{json.yml}, I updated docs/references/files/*.schema.json AND I have updated example files used by fossa init command. You may also need to update these if you have added/removed new dependency type (e.g. pip) or analysis target type (e.g. poetry).
  • If I made changes to a subcommand's options, I updated docs/references/subcommands/<subcommand>.md.

This PR description was generated with Claude Code


Generated by Claude Code

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
fossa-ane-bot marked this pull request as ready for review August 21, 2026 07:43
fossa-ane-bot requested a review from a team as a code owner August 21, 2026 07:43
fossa-ane-bot requested a review from tjugdev August 21, 2026 07:43

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info ⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eedf46db-9483-48df-8da6-5e48ef6e6c15

📥 Commits

Reviewing files that changed from the base of the PR and between 3b42606 and c959bf0.

📒 Files selected for processing (4)
  • Changelog.md
  • src/Strategy/Node/Npm/PackageLock.hs
  • test/Node/PackageLockSpec.hs
  • test/Node/testdata/no-dependencies-package-lock.json

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: tolerating package-lock.json files without a dependencies key.
Description check ✅ Passed The description covers the overview, acceptance criteria, testing, risks, metrics, references, and checklist with concrete details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (4 skipped: 4 unsupported.)
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

tjugdev merged commit ecdad17 into master Aug 21, 2026
38 checks passed
tjugdev deleted the fossa-cli-fix-2026-08-21 branch August 21, 2026 14:50
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL