Skip to content

feat(badges): add npmx.dev as a badge provider#137

Open
sandros94 wants to merge 1 commit intounjs:mainfrom
sandros94:feat/npmx-badges
Open

feat(badges): add npmx.dev as a badge provider#137
sandros94 wants to merge 1 commit intounjs:mainfrom
sandros94:feat/npmx-badges

Conversation

@sandros94
Copy link
Member

@sandros94 sandros94 commented Mar 7, 2026

Adds npmx.dev as a new provider option for the badges generator, sourcing badge images from https://npmx.dev/api/registry/badge/.

Badge type mappings:

  • npmVersion → /badge/version/{name}
  • npmDownloads → /badge/downloads-month/{name} (monthly, consistent with shields' npm/dm)
  • packagephobia → /badge/size/{name} (install/unpacked size)
  • license → /badge/license/{name}

Existing customization args (color, labelColor, styleParams) are forwarded as query directly.

Usage:

  <!-- automd:badges provider=npmx license packagephobia -->

Summary by CodeRabbit

  • New Features
    • Added npmx badge provider for displaying npm package information including version, downloads, license, and packagephobia metrics.

Adds `npmx` as a new provider option for the `badges` generator,
sourcing badge images from https://npmx.dev/api/registry/badge/.

Badge type mappings:
- `npmVersion`   → /badge/version/{name}
- `npmDownloads` → /badge/downloads-month/{name} (monthly, consistent with shields' npm/dm)
- `packagephobia` → /badge/size/{name} (install/unpacked size)
- `license`      → /badge/license/{name}
- `bundlephobia`, `bundlejs`, `codecov` → false (no equivalent on npmx.dev)

Existing customization args (`color`, `labelColor`, `styleParams`) are
forwarded as query params and are natively supported by npmx.dev.

Usage:
  <!-- automd:badges provider=npmx license packagephobia -->

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2026

📝 Walkthrough

Walkthrough

A new "npmx" badge provider was introduced to the badge generator with support for npm version, downloads, packagephobia, and license metadata. Test fixtures were updated to demonstrate the provider's configuration and output generation.

Changes

Cohort / File(s) Summary
Badge Provider Configuration
src/generators/badges.ts
Added custom badge provider "npmx" with endpoints for npmVersion, npmDownloads, packagephobia, and license; disabled bundlephobia, bundlejs, and codecov for this provider.
Test Fixtures
test/fixture/INPUT.md, test/fixture/OUTPUT.md
Added badge block metadata for npmx provider with license and packagephobia badge types; included corresponding test output showing generated badge lines and automd comments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A new provider hops into view,
with npmx badges shiny and true,
packagephobia and license on display,
the badges garden grows today! 📦✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding npmx.dev as a new badge provider to the badges generator.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/fixture/INPUT.md (1)

8-9: Consider adding one fixture that exercises npmx query passthrough.

This block covers the base endpoints, but the PR also relies on color, labelColor, and styleParams being forwarded to npmx. A small fixture with one forwarded param would lock in that behavior and catch regressions in the provider contract.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/fixture/INPUT.md` around lines 8 - 9, Add a new test fixture that
exercises npmx query passthrough by adding an automd badges block that uses
provider=npmx and includes at least one forwarded parameter (e.g., color,
labelColor, or styleParams) so the test ensures those query params are forwarded
to npmx; update the existing fixtures to include this entry (mirroring the
current automd:badges structure) and ensure the test assertion checks that the
npmx request/URL contains the forwarded param to lock in the provider contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/generators/badges.ts`:
- Around line 70-77: The npmx provider entry currently supports a direct license
badge URL (npmx.npmx -> license) but the generator still gates license badges on
ctx.github and maps through badgeTypes.license.to (which expects GitHub
metadata); update the badge generation logic to detect when provider === "npmx"
(or when npmx.license URL exists) and, instead of relying on
badgeTypes.license.to, construct/use the direct npmx license URL template
(replacing {name}) so license badges are emitted for packages without
ctx.github; ensure existing github-based path remains for providers that require
GitHub metadata.

---

Nitpick comments:
In `@test/fixture/INPUT.md`:
- Around line 8-9: Add a new test fixture that exercises npmx query passthrough
by adding an automd badges block that uses provider=npmx and includes at least
one forwarded parameter (e.g., color, labelColor, or styleParams) so the test
ensures those query params are forwarded to npmx; update the existing fixtures
to include this entry (mirroring the current automd:badges structure) and ensure
the test assertion checks that the npmx request/URL contains the forwarded param
to lock in the provider contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c64a27cf-f480-4cda-8606-d3871e2a3b9f

📥 Commits

Reviewing files that changed from the base of the PR and between 011db56 and 78ea06c.

📒 Files selected for processing (3)
  • src/generators/badges.ts
  • test/fixture/INPUT.md
  • test/fixture/OUTPUT.md

Comment on lines +70 to +77
npmx: {
npmVersion: "https://npmx.dev/api/registry/badge/version/{name}",
npmDownloads: "https://npmx.dev/api/registry/badge/downloads-month/{name}",
bundlephobia: false,
bundlejs: false,
packagephobia: "https://npmx.dev/api/registry/badge/size/{name}",
codecov: false,
license: "https://npmx.dev/api/registry/badge/license/{name}",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

npmx license badges are still gated on GitHub metadata.

This provider can render the license badge from {name}, but the generator still enables license only when ctx.github exists and still links it through the GitHub-only badgeTypes.license.to. Packages without repo metadata will silently lose the new badge even though npmx supports it.

💡 Minimal fallback sketch
      license: {
-        enabled: args.license && ctx.github,
+        enabled: args.license && (ctx.github || ctx.name),
         ...badgeTypes.license,
+        to: ctx.github
+          ? badgeTypes.license.to
+          : badgeTypes.npmVersion.to,
      },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/generators/badges.ts` around lines 70 - 77, The npmx provider entry
currently supports a direct license badge URL (npmx.npmx -> license) but the
generator still gates license badges on ctx.github and maps through
badgeTypes.license.to (which expects GitHub metadata); update the badge
generation logic to detect when provider === "npmx" (or when npmx.license URL
exists) and, instead of relying on badgeTypes.license.to, construct/use the
direct npmx license URL template (replacing {name}) so license badges are
emitted for packages without ctx.github; ensure existing github-based path
remains for providers that require GitHub metadata.

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