Skip to content

Create and test package.json verifier#80

Merged
dev-dami merged 6 commits into
dev-dami:mainfrom
KnightOkami:main
Jun 23, 2026
Merged

Create and test package.json verifier#80
dev-dami merged 6 commits into
dev-dami:mainfrom
KnightOkami:main

Conversation

@KnightOkami

@KnightOkami KnightOkami commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Adds a script that validates the structure of package.json and a Jest test file for the validation logic.

This helps catch missing fields, incorrect value types, and invalid export paths before they cause build or publishing problems.

No new dependencies are required. The tests use the project’s existing Jest setup.

Fixes #78

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • [ X] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

  • Valid Package.json: Using the valid and provided Package.json, I ran the script to ensure it returns no errors found.
  • Removed name: Using the valid and provided Package.json, I removed the name and then ran the script to ensure it flagged the name field was missing.
  • Changed name content to boolean: Using the valid and provided Package.json, I changed the content of the name field to a boolean True to ensure the expected data type error returned.
  • I then repeated the above tests removing or editing the content for main, scripts, and exports fields.
  • I also added tests in the test file.

Test Configuration:

  • Node.js version: 24.10.1
  • Operating system: windows 11. Ran on 6.6.87.2-microsoft-standard-WSL2
  • TypeScript version: 5.9.3

Checklist

  • [X ] My code follows the style guidelines of this project
  • [X ] I have performed a self-review of my own code
  • [X ] I have commented my code, particularly in hard-to-understand areas
  • [X ] I have made corresponding changes to the documentation
  • [X ] My changes generate no new warnings
  • [X ] I have added tests that prove my fix is effective or that my feature works
  • [X ] New and existing unit tests pass locally with my changes
  • [X ] Any dependent changes have been merged and published in downstream modules

Additional Notes

Add any other context or screenshots about the pull request here.

This is my first public open-source contribution, so please let me know if any changes are needed. I apologize for the commit message formatting, I didnt realize till too late they needed to be formatted as well, I thought it was only the pull.

I added tests, comments, and updated the testing documentation. AI was used as a supporting tool for coding and documentation, not as a replacement for understanding or reviewing the work.

Summary by CodeRabbit

  • Chores

    • Added automated package schema validation to CI pipeline
    • Implemented validation script for package.json integrity
  • Tests

    • Added comprehensive test suite for package validation helpers

Create validate-package-json.js. Add it to the package.json as a script so we can add it to the workflow ci.yml.

Need to verify with dev about what fields are needed before creating any testing.
Added initial comments for personal use. Will neaten up once done testing.
Changed the js file to cjs to allow testing. Made a testing file for the package check.
Update readme to include the new script folder for testing and rename the test file to maintain style.
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@KnightOkami, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 39 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3ebab006-372e-41f8-85bf-cb5cb9992474

📥 Commits

Reviewing files that changed from the base of the PR and between 1d01503 and c959b05.

📒 Files selected for processing (2)
  • package.json
  • tests/scripts/ValidatePackageJson.test.ts
📝 Walkthrough

Walkthrough

Adds scripts/validate-package-json.cjs, a Node.js script that validates package.json against an internal schema covering required string, array, boolean fields, and exports entry structure. A Jest test suite is added under tests/scripts/. The script is registered as an npm script and wired into the CI quality job.

Changes

package.json Validation Script

Layer / File(s) Summary
Schema definition and validation helpers
scripts/validate-package-json.cjs
Defines packageSchema listing required string/array/boolean fields and expected export keys. Implements getNestedValue for path traversal, validateExportPath for per-condition string/extension checks, and validateExportEntry for full entry object validation including wildcard enforcement.
validate, checkFile, exports, and CLI entry point
scripts/validate-package-json.cjs
validate runs all schema checks and returns an error array. checkFile reads, parses, and logs results. Module exports expose all helpers for Jest. The require.main block resolves ../package.json and sets process.exitCode.
Jest test suite
tests/scripts/ValidatePackageJson.test.ts
Adds createValidPackage() fixture and full test coverage for getNestedValue, validateExportPath, validateExportEntry, and validate, including multi-error aggregation and all documented failure modes.
CI step, npm script, and README docs
.github/workflows/ci.yml, package.json, tests/README.md
Registers check-package-schema npm script, inserts the CI quality step after lint, and updates the test directory listing in the README.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A little rabbit checks each field,
exports, version, main revealed,
With .cjs logic neat and tight,
No malformed package escapes my sight.
CI runs green — hops into night! 🌙

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Create and test package.json verifier' accurately reflects the main changes: a new validation script and its comprehensive test suite.
Linked Issues check ✅ Passed The PR fully satisfies issue #78 requirements: implements validation script with required field checking, validates exports structure, integrates into CI workflow, and includes comprehensive Jest tests.
Out of Scope Changes check ✅ Passed All changes are in-scope: validation script implementation, CI integration, comprehensive tests, and documentation updates directly support the linked issue requirements.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@KnightOkami

Copy link
Copy Markdown
Contributor Author

I see why the ci failed, forgot to change the scripts name in the package.json when I changed for testing. Making the change and will re submit after the code rabbit scan is done as well.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/README.md (1)

43-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor formatting: simplify tree structure whitespace.

The two blank lines (43–44) create unnecessary separation in the tree diagram. Consider removing them to maintain visual continuity, or explicitly group sections if this spacing was intentional.

✨ Suggested cleanup
 ├── Formatter.test.ts          # Output formatting tests  
-
-
-├── scripts                    `#General` script testing
+├── scripts                    # General script testing
 │   ├── ValidatePackageJson.test.ts `#Package.json` check tests
 ├── transports/                # Transport implementation tests
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/README.md` around lines 43 - 46, In the tree diagram structure of the
README.md file, there are two consecutive blank lines appearing before the
scripts section (which contains the ValidatePackageJson.test.ts reference).
Remove these extra blank lines to maintain visual continuity and improve the
readability of the tree structure diagram. Keep only necessary single-line
spacing between logical sections if needed for grouping.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Around line 37-38: The check-package-schema npm script is referencing an
incorrect file path. Update the check-package-schema script value in
package.json from pointing to scripts/check-package-schema.js to the actual
validation script location of scripts/validate-package-json.cjs to ensure the
npm script executes the correct file and resolves the file not found error.

In `@tests/scripts/ValidatePackageJson.test.ts`:
- Around line 1-9: Replace the require() call at the beginning of the test file
with ES import syntax. Convert the destructured require statement that imports
getNestedValue, packageSchema, validate, validateExportEntry, and
validateExportPath from "../../scripts/validate-package-json.cjs" into a
standard ES import statement using the import keyword. This will resolve the
`@typescript-eslint/no-require-imports` ESLint violation.

---

Nitpick comments:
In `@tests/README.md`:
- Around line 43-46: In the tree diagram structure of the README.md file, there
are two consecutive blank lines appearing before the scripts section (which
contains the ValidatePackageJson.test.ts reference). Remove these extra blank
lines to maintain visual continuity and improve the readability of the tree
structure diagram. Keep only necessary single-line spacing between logical
sections if needed for grouping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12e7cb45-d390-4bc1-b111-4c90e614d8d6

📥 Commits

Reviewing files that changed from the base of the PR and between b34b022 and 1d01503.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • package.json
  • scripts/validate-package-json.cjs
  • tests/README.md
  • tests/scripts/ValidatePackageJson.test.ts

Comment thread package.json Outdated
Comment thread tests/scripts/ValidatePackageJson.test.ts Outdated
KnightOkami and others added 2 commits June 23, 2026 16:38
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Tested locally, works.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@dev-dami

Copy link
Copy Markdown
Owner

Merged and issue closed

@dev-dami dev-dami merged commit f1c141b into dev-dami:main Jun 23, 2026
5 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.

Good First Issue: Add package.json structural validation script

2 participants