Skip to content

Add a typed package.json reader - #16179

Open
JamieMagee wants to merge 1 commit into
mainfrom
jamiemagee/sorbet-package-json-reader
Open

Add a typed package.json reader#16179
JamieMagee wants to merge 1 commit into
mainfrom
jamiemagee/sorbet-package-json-reader

Conversation

@JamieMagee

@JamieMagee JamieMagee commented Sep 5, 2026

Copy link
Copy Markdown
Member

What are you trying to accomplish?

Add a shared NpmPackageJson reader for the fields used by npm/Yarn and Bun file parsing and workspace filtering. It is typed: strong, yields string dependency requirements, and reuses NpmPackageManagerConfig for package-manager metadata.

This is the bottom layer of the stack. #16180 and #16181 migrate the consumers.

Anything you want to highlight for special attention from reviewers?

The contract follows the existing parser code and fixtures, not a complete npm schema. Fields are read lazily, requirement strings stay unchanged, and non-string requirements are skipped. Missing/null/false dependency sections remain empty; other non-object sections raise TypeError with file and field context.

flat and workspaces retain their existing Ruby truthiness, including empty arrays and objects. JSON syntax errors propagate for callers to handle. The reader never rewrites the source file.

How will you know you've accomplished your goal?

The reader and existing package-manager config specs pass all 48 examples. Repository-wide Sorbet and targeted RuboCop also pass. These checks ran in containers; I did not run the complete repository suite.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@JamieMagee
JamieMagee requested a review from a team as a code owner September 5, 2026 02:54
Copilot AI balanced review requested due to automatic review settings September 5, 2026 02:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

馃煝 Approval recommended

The focused implementation follows existing parsing conventions and has thorough behavioral coverage.

Review tier: Balanced
Findings: None

What changed in this PR

Adds a shared, strongly typed package.json reader to Dependabot Common.

Changes:

  • Parses dependency sections and package metadata safely.
  • Validates malformed JSON structures with contextual errors.
  • Adds comprehensive tests for valid, invalid, and optional fields.
File Description
common/鈥媗ib/鈥媎ependabot/鈥媝ackage/鈥媙pm_package_json.rb Implements the typed reader.
common/鈥媠pec/鈥媎ependabot/鈥媝ackage/鈥媙pm_package_json_spec.rb Covers parsing, validation, and defaults.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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