Skip to content

refactor: use normalizeLicense util consistently - #2816

Merged
ghostdevv merged 5 commits into
npmx-dev:mainfrom
charpeni:fix/license-change-first-version
May 31, 2026
Merged

refactor: use normalizeLicense util consistently#2816
ghostdevv merged 5 commits into
npmx-dev:mainfrom
charpeni:fix/license-change-first-version

Conversation

@charpeni

@charpenicharpeni commented May 29, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

n/a

🧭 Context

n/a

📚 Description

This refactor uses the normalizeLicense function more consistently.

@vercel

vercelBot commented May 29, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
npmx.devReadyReadyPreview, CommentMay 31, 2026 3:09pm
2 Skipped Deployments
ProjectDeploymentActionsUpdated (UTC)
docs.npmx.devIgnoredIgnoredPreviewMay 31, 2026 3:09pm
npmx-lunariaIgnoredIgnoredMay 31, 2026 3:09pm

Request Review

@coderabbitai

coderabbitaiBot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1d9284d4-7d60-410e-9d73-4235f25a5c78

📥 Commits

Reviewing files that changed from the base of the PR and between f78042b and 3036392.

📒 Files selected for processing (4)
  • app/composables/usePackageComparison.ts
  • server/api/registry/badge/[type]/[...pkg].get.ts
  • server/api/registry/package-meta/[...pkg].get.ts
  • server/api/registry/timeline/[...pkg].get.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/composables/usePackageComparison.ts
  • server/api/registry/badge/[type]/[...pkg].get.ts
  • server/api/registry/timeline/[...pkg].get.ts
  • server/api/registry/package-meta/[...pkg].get.ts

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed license information display across package badges, metadata, and timeline features. License data is now consistently normalised and properly rendered instead of showing placeholder values.
  • Tests

    • Added test coverage for license badge rendering to ensure correct display formatting.

Walkthrough

This PR applies the shared normalizeLicense utility across four locations: three server endpoints (badge, package-meta, timeline), a client composable (usePackageComparison), and adds unit test coverage for the badge endpoint's licence handling with object-shaped licence values.

Changes

License normalisation application

Layer / File(s)Summary
Server endpoints: licence normalisation via normalizeLicense
server/api/registry/badge/[type]/[...pkg].get.ts, server/api/registry/package-meta/[...pkg].get.ts, server/api/registry/timeline/[...pkg].get.ts
Badge, package-meta, and timeline endpoints import and apply normalizeLicense to standardise returned licence values, replacing inline type-extraction logic.
Client composable: usePackageComparison licence normalisation
app/composables/usePackageComparison.ts
usePackageComparison imports and uses normalizeLicense to normalise fetched package licence metadata instead of inline type-checking.
Tests: badge endpoint with normalised licence
test/unit/server/api/registry/badge/pkg.get.spec.ts
Vitest unit test verifies that object-shaped licence (license: { type: 'MIT' }) is correctly normalised in the rendered SVG output, containing the licence token and excluding object-to-string placeholders.

Possibly related PRs

  • npmx-dev/npmx.dev#2662: Both PRs refactor licence handling to use the shared normalizeLicense helper (replacing inline license.type/string conditionals) so the badge/timeline/package metadata show consistent normalised licence values, overlapping directly in the same licence-normalisation code paths.

Suggested reviewers

  • ghostdevv
  • serhalp
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title accurately reflects the main change: refactoring license normalisation across multiple files to use a shared utility consistently.
Description check✅ PassedThe description is related to the changeset, explaining that the refactor uses the normalizeLicense function more consistently across the codebase.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

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

@github-actions

Copy link
Copy Markdown

Hello! Thank you for opening your first PR to npmx, @charpeni! 🚀

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@codecov

codecovBot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitaicoderabbitaiBot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/api/registry/license-change/[...pkg].get.ts (1)

41-49: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate currentVersionIndex before array access.

The currentVersionIndex can be -1 in two scenarios: (1) when version === 'latest' and the versions array is empty, or (2) when findIndex fails to locate the requested version. Accessing versions[currentVersionIndex] on line 49 with a negative index violates type-safety. As per coding guidelines, always check when accessing an array value by index.

🛡️ Proposed fix to validate currentVersionIndex
 const currentVersionIndex =
version === 'latest' ? versions.length - 1 : versions.findIndex(v => v.version === version)
+if (currentVersionIndex < 0) {+ throw createError({+ statusCode: 404,+ statusMessage: 'Version not found',+ })+}+
const previousVersionIndex = currentVersionIndex - 1
if (previousVersionIndex < 0) {
return { change }
}
🤖 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 `@server/api/registry/license-change/`[...pkg].get.ts around lines 41 - 49,
currentVersionIndex can be -1 (empty versions or findIndex miss), so before
accessing versions[currentVersionIndex] in the assignment to currentLicense,
validate currentVersionIndex is within [0, versions.length-1]; if it's -1 or out
of range, set currentLicense to 'UNKNOWN' (or the existing fallback) and
proceed—update the logic around the currentVersionIndex calculation and the
currentLicense assignment to guard against negative indices and avoid unsafe
array access.
🤖 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.
Outside diff comments:
In `@server/api/registry/license-change/`[...pkg].get.ts:
- Around line 41-49: currentVersionIndex can be -1 (empty versions or findIndex
miss), so before accessing versions[currentVersionIndex] in the assignment to
currentLicense, validate currentVersionIndex is within [0, versions.length-1];
if it's -1 or out of range, set currentLicense to 'UNKNOWN' (or the existing
fallback) and proceed—update the logic around the currentVersionIndex
calculation and the currentLicense assignment to guard against negative indices
and avoid unsafe array access.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 250d627f-c1e0-495f-b578-54f044d06a98

📥 Commits

Reviewing files that changed from the base of the PR and between b3ba515 and e2a9cc5.

📒 Files selected for processing (2)
  • server/api/registry/license-change/[...pkg].get.ts
  • test/unit/server/api/registry/license-change/pkg.get.spec.ts

@serhalpserhalp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

Comment threadtest/unit/server/api/registry/license-change/pkg.get.spec.ts Outdated
Comment threadserver/api/registry/license-change/[...pkg].get.ts Outdated
Comment threadshared/utils/npm.ts Outdated
@gameromangameroman added the needs review This PR is waiting for a review from a maintainer label May 30, 2026
@ghostdevv

Copy link
Copy Markdown
Member

We got a few PRs for this fix, so we merged all the changes into #2792 and closed the other ones - in this case though we can turn this PR into a refactor of the use of the normalise util 👀

@ghostdevv
ghostdevv marked this pull request as draft May 31, 2026 14:43
@ghostdevvghostdevv changed the title fix: ignore license change for initial versionrefactor: use normaliseLicense util consistentlyMay 31, 2026
@ghostdevvghostdevv changed the title refactor: use normaliseLicense util consistentlyrefactor: use normalizeLicense util consistentlyMay 31, 2026
@ghostdevv
ghostdevvforce-pushed the fix/license-change-first-version branch from 6eea39b to 3036392CompareMay 31, 2026 15:06
@ghostdevvghostdevv removed the needs review This PR is waiting for a review from a maintainer label May 31, 2026
@ghostdevv
ghostdevv marked this pull request as ready for review May 31, 2026 15:13
@ghostdevv
ghostdevv added this pull request to the merge queueMay 31, 2026
Merged via the queue into npmx-dev:main with commit 10e11f5May 31, 2026
24 checks passed
@github-actions

Copy link
Copy Markdown

Thanks for your first contribution, @charpeni! ✨

We'd love to welcome you to the npmx community. Come and say hi on Discord! And once you've joined, visit npmx.wamellow.com to claim the contributor role.

@github-actionsgithub-actionsBot mentioned this pull request May 31, 2026
ayo-run pushed a commit to ayo-run/npmx.dev that referenced this pull request Aug 5, 2026
Co-authored-by: Willow (GHOST) <git@willow.sh>
Sign up for freeto 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.

4 participants

@charpeni@ghostdevv@serhalp@gameroman