Skip to content

fix: don't flag a license change when there is no previous version - #2792

Merged
ghostdevv merged 7 commits into
npmx-dev:mainfrom
jp-knj:fix/2720-license-change-no-previous-version
May 31, 2026
Merged

fix: don't flag a license change when there is no previous version#2792
ghostdevv merged 7 commits into
npmx-dev:mainfrom
jp-knj:fix/2720-license-change-no-previous-version

Conversation

@jp-knj

@jp-knjjp-knj commented May 25, 2026

Copy link
Copy Markdown
Contributor

Fixes#2720.

Summary

Fix false-positive license change warnings for packages that have no previous version.

Added unit tests for the new-package case and normal license-change comparisons.

Test plan

  • New unit tests at test/unit/server/api/registry/license-change/pkg.get.spec.ts
  • pnpm lint clean
  • pnpm test:types passes
  • Manual: /package/vsxtools/v/0.0.1 no longer shows a license-change warning; a multi-version package with an actual license change still does

@vercel

vercelBot commented May 25, 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 2:52pm
2 Skipped Deployments
ProjectDeploymentActionsUpdated (UTC)
docs.npmx.devIgnoredIgnoredPreviewMay 31, 2026 2:52pm
npmx-lunariaIgnoredIgnoredMay 31, 2026 2:52pm

Request Review

@coderabbitai

coderabbitaiBot commented May 25, 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
📝 Walkthrough

Walkthrough

Adds a shared license normaliser, applies it in the license-change handler and usePackage composable, guards comparisons to only run when a real prior version exists, and adds Vitest coverage for the license-change endpoint across multiple scenarios.

Changes

License-change handler fix and validation

Layer / File(s)Summary
Shared normalize helper
shared/utils/npm.ts
Adds `normalizeLicense(license?: PackumentLicense): string
Handler guard for valid prior-version comparison
server/api/registry/license-change/[...pkg].get.ts
Imports normalizeLicense; only computes/compares licences when currentVersionIndex > 0, uses normalizeLicense(...) ?? 'UNKNOWN', and sets change only if normalised values differ.
Composable uses shared normaliser
app/composables/npm/usePackage.ts
Replaces the local normaliser with the shared normalizeLicense import; existing normalisation call sites remain.
Test suite for license-change endpoint
test/unit/server/api/registry/license-change/pkg.get.spec.ts
Adds Vitest tests that stub H3/router helpers, mock fetchNpmPackage, and cover missing package param, single-version (null change), license transitions, unchanged license, object-license extraction, default latest-version comparison, explicit version predecessor comparison, oldest-version handling, and missing-version handling.

Possibly related PRs

  • npmx-dev/npmx.dev#2662: Overlapping changes that introduced normalizeLicense in shared/utils/npm.ts and updated consumers.

Suggested reviewers

  • ghostdevv
  • 43081j
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title accurately summarises the main fix: preventing false-positive license-change warnings when no previous version exists, which is the core objective of the PR.
Description check✅ PassedThe description clearly relates to the changeset, explaining the bug fix, summarising changes, and detailing the test plan for validating the fix.
Linked Issues check✅ PassedThe PR successfully addresses issue #2720 by guarding licence comparisons with currentVersionIndex > 0 to prevent false positives for single-version packages, matching the desired behaviour of not reporting changes without a previous version.
Out of Scope Changes check✅ PassedAll changes are directly scoped to fixing the licence-change comparison issue: the handler fix, unit tests, shared utility extraction, and composable refactoring are all aligned with the stated objective.

✏️ 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, @jp-knj! 🚀

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.

@jp-knj
jp-knj marked this pull request as draft May 25, 2026 13:26
@codecov

codecovBot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
server/api/registry/license-change/[...pkg].get.ts60.00%0 Missing and 2 partials ⚠️
shared/utils/npm.ts50.00%0 Missing and 2 partials ⚠️

📢 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.

Actionable comments posted: 2

🤖 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 `@server/api/registry/license-change/`[...pkg].get.ts:
- Around line 50-51: Normalize license values the same way as the timeline
handler: instead of using String(...) for currentLicense and previousLicense,
detect if versions[currentVersionIndex]?.license or
versions[previousVersionIndex]?.license is an object and, if so, use its .type
property (fallback to 'UNKNOWN' if missing); otherwise use the string value.
Update the assignments that set currentLicense and previousLicense (referencing
versions, currentVersionIndex, previousVersionIndex) to perform this object
check and extraction so change detection reports the actual license.type rather
than "[object Object]".
In `@test/unit/server/api/registry/license-change/pkg.get.spec.ts`:
- Around line 37-190: Add a new test in this spec to exercise object-shaped
licenses: create a case (similar to the suggested snippet) that sets routerParam
= 'my-pkg', mocks fetchNpmPackageMock via makePackument to return versions where
license values are objects (e.g. { type: 'MIT' } and { type: 'Apache-2.0', url:
'...' }), call handler(fakeEvent), and assert the returned change equals { from:
'MIT', to: 'Apache-2.0' }; this ensures the handler's license normalization
logic (used when reading packument versions) correctly extracts the type field
from object licenses.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c0f1dfca-89e7-461a-88fa-6539b5ef9d3d

📥 Commits

Reviewing files that changed from the base of the PR and between 113c2dd and ed87967.

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

Comment threadserver/api/registry/license-change/[...pkg].get.ts Outdated
Comment threadtest/unit/server/api/registry/license-change/pkg.get.spec.ts
jp-knj added a commit to jp-knj/npmx.dev that referenced this pull request May 25, 2026
The license field can be an object ({ type, url }), where String() would
yield "[object Object]". Reuse normalizeLicense (moved from usePackage to
shared/utils/npm) to extract the type, so change detection compares real
license values. Adds an object-license test case.
Addresses review feedback on npmx-dev#2792.
@jp-knj
jp-knjforce-pushed the fix/2720-license-change-no-previous-version branch from 2d1cf32 to 8181098CompareMay 25, 2026 14:19
…rsion
Don't flag a license change when there's no real previous version (new
single-version packages were diffing against a phantom 'UNKNOWN'), and
normalize object-shaped licenses ({ type, url }) so comparisons use the
real value instead of "[object Object]". Adds unit tests.
Closesnpmx-dev#2720

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

Actionable comments posted: 1

🤖 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 `@test/unit/server/api/registry/license-change/pkg.get.spec.ts`:
- Around line 109-110: The fixtures use `as never` to silence types for the
`license` objects; instead, change the test to use the proper `PackumentLicense`
type so the objects stay type-safe—import `PackumentLicense` and either pass it
as the generic/type parameter to `makePackument` (or annotate the
`versions`/`license` field in the `makePackument` call) so the entries like `{
license: { type: 'MIT' } }` and `{ license: { type: 'Apache-2.0', url:
'https://example.com' } }` are typed as `PackumentLicense` and remove the `as
never` casts. Ensure you update the `makePackument` invocation in this spec to
use that type.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 352fe720-f2be-4d5e-accc-af66a3c789b9

📥 Commits

Reviewing files that changed from the base of the PR and between ed87967 and 62bdd11.

📒 Files selected for processing (4)
  • app/composables/npm/usePackage.ts
  • server/api/registry/license-change/[...pkg].get.ts
  • shared/utils/npm.ts
  • test/unit/server/api/registry/license-change/pkg.get.spec.ts

Comment threadtest/unit/server/api/registry/license-change/pkg.get.spec.ts Outdated
@gameromangameroman added the needs review This PR is waiting for a review from a maintainer label May 26, 2026
Co-authored-by: Nicolas Charpentier <7189823+charpeni@users.noreply.github.com>
@ghostdevv
ghostdevv added this pull request to the merge queueMay 31, 2026
@ghostdevv
ghostdevv removed this pull request from the merge queue due to a manual request May 31, 2026
Co-authored-by: ProCode <68168458+ProCode-Software@users.noreply.github.com>
Co-authored-by: Nicolas Charpentier <7189823+charpeni@users.noreply.github.com>
Co-authored-by: WenLong Chen <50607756+stellhub@users.noreply.github.com>
@ghostdevv
ghostdevv enabled auto-merge May 31, 2026 14:50
@ghostdevv
ghostdevv added this pull request to the merge queueMay 31, 2026
Merged via the queue into npmx-dev:main with commit 3958786May 31, 2026
24 checks passed
@github-actions

Copy link
Copy Markdown

Thanks for your first contribution, @jp-knj! 💪

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
…pmx-dev#2792)
Co-authored-by: Roman <dev@rman.dev>
Co-authored-by: Willow (GHOST) <git@willow.sh>
Co-authored-by: Nicolas Charpentier <7189823+charpeni@users.noreply.github.com>
Co-authored-by: ProCode <68168458+ProCode-Software@users.noreply.github.com>
Co-authored-by: WenLong Chen <50607756+stellhub@users.noreply.github.com>
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.

Package page shows license changed warning for new package

3 participants

@jp-knj@ghostdevv@gameroman