feat(badges): add npmx.dev as a badge provider#137
feat(badges): add npmx.dev as a badge provider#137
Conversation
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>
📝 WalkthroughWalkthroughA 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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, andstyleParamsbeing forwarded tonpmx. 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
📒 Files selected for processing (3)
src/generators/badges.tstest/fixture/INPUT.mdtest/fixture/OUTPUT.md
| 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}", |
There was a problem hiding this comment.
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.
Adds
npmx.devas a new provider option for thebadgesgenerator, 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