Skip to content

fix: detect implicit types in package timeline - #3102

Open
anilloutombam wants to merge 4 commits into
npmx-dev:mainfrom
anilloutombam:fix/timeline-implicit-types
Open

fix: detect implicit types in package timeline#3102
anilloutombam wants to merge 4 commits into
npmx-dev:mainfrom
anilloutombam:fix/timeline-implicit-types

Conversation

@anilloutombam

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Fixes #2791

🧭 Context

The timeline incorrectly showed removed TypeScript types when declarations still existed as .d.mts files beside .mjs entry points.

📚 Description

I updated the timeline to check the published package files when types appear to be removed. I also added a regression test for declarations stored beside the package entry points.

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview Jul 31, 2026 6:18pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Jul 31, 2026 6:18pm
npmx-lunaria Ignored Ignored Jul 31, 2026 6:18pm

Request Review

@github-actions

Copy link
Copy Markdown

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

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

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
server/api/registry/timeline/[...pkg].get.ts 83.33% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved package timeline results by detecting included declaration files for versions that do not explicitly advertise built-in types.
    • Package versions now more accurately indicate when type definitions are available, including when declarations are removed.
  • Tests

    • Added coverage for detecting declarations across consecutive versions and alongside package entry points.

Walkthrough

The timeline endpoint analyses package contents for eligible versions to detect declaration files. It returns enriched hasTypes values while preserving existing metadata when analysis fails. Tests cover declarations beside package entry points and declaration removal.

Changes

Timeline type detection

Layer / File(s) Summary
Enrich timeline type metadata
server/api/registry/timeline/[...pkg].get.ts, test/unit/server/api/registry/timeline/pkg.get.spec.ts
The endpoint analyses eligible visible versions and updates hasTypes when package contents include types. Fetch and analysis failures retain existing metadata. Tests mock the analysis fetch and cover declarations beside an entry point and declaration removal.

Sequence Diagram(s)

sequenceDiagram
  participant TimelineEndpoint
  participant PackageFetcher
  participant PackageAnalyzer
  TimelineEndpoint->>PackageFetcher: Fetch package files and type-package data
  PackageFetcher-->>TimelineEndpoint: Return package contents
  TimelineEndpoint->>PackageAnalyzer: Analyse package contents
  PackageAnalyzer-->>TimelineEndpoint: Return included-type result
  TimelineEndpoint-->>TimelineEndpoint: Set hasTypes on the visible page
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #2791 by detecting declaration files beside package entry points and preserving correct type status.
Out of Scope Changes check ✅ Passed The changes are limited to timeline type detection and related regression tests, with no unrelated scope identified.
Title check ✅ Passed The title clearly and concisely describes the main change: detecting implicit TypeScript types in the package timeline.
Description check ✅ Passed The description is directly related to the changes and explains the bug, the implementation, and the regression test.
✨ 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.

@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

🤖 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/timeline/`[...pkg].get.ts:
- Around line 87-92: Update possibleTypeRemovals in
server/api/registry/timeline/[...pkg].get.ts (lines 87-92) to include every
consecutive untyped version following the metadata transition, so each affected
version is analyzed and retains hasTypes: true when implicit declaration files
exist. Extend the corresponding test scenario in
test/unit/server/api/registry/timeline/pkg.get.spec.ts (lines 232-266) with a
third version containing an implicit declaration file and assert both
post-transition versions return hasTypes: true.

In `@test/unit/server/api/registry/timeline/pkg.get.spec.ts`:
- Around line 264-265: Update the assertions in the versions test to avoid
non-null assertions on result.versions indices; use optional access or
explicitly validate the indexed version objects before reading hasTypes, while
preserving the expected true assertions.
🪄 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 Plus

Run ID: 1f09bad7-d2db-498f-be6e-6f84c519bedc

📥 Commits

Reviewing files that changed from the base of the PR and between d727566 and 7c02f03.

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

Comment thread server/api/registry/timeline/[...pkg].get.ts Outdated
Comment thread test/unit/server/api/registry/timeline/pkg.get.spec.ts Outdated
const possibleTypeRemovals = visibleVersions
.filter((version, index) => {
if (version.hasTypes) return false
return allVersions.slice(index + 1).some(previousVersion => previousVersion.hasTypes)

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.

Could you explain the thinking here a bit? I guess it's so that you don't need to fetch a bunch of data for every package to check the types? Do you think it may miss packages that add types in weird ways? I wonder if instead we should run the fetch logic in the main allVersions loop if hasBuiltInTypes fails 🤔 I guess that would be less efficient... maybe you could add a comment explaining the rationale?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was the thinking. The file-aware check requires extra package and file-tree requests, so I limited it to metadata-untyped versions that have an older typed release. Those are the versions that could otherwise produce a false “types removed” event.

This could miss a package that has always shipped types implicitly, or adds them without using types or typings. Detecting those would require checking every metadata-untyped version, which is broader than this removal-event fix and would add more requests.

I added a comment explaining the tradeoff. I’m happy to broaden the check if you think the extra requests are acceptable.

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.

Let's see what others think

Comment on lines +91 to +94
.filter(version => {
if (version.hasTypes) return false

const versionIndex = allVersions.indexOf(version)

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.

I changed this to use the index from filter earlier, any reason that was undone?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was intentional. visibleVersions.filter() gives us a page-relative index, but we’re slicing allVersions. That breaks as soon as the offset is non-zero. Using allVersions.indexOf(version) gives us the version’s actual position in the full timeline.

@ghostdevv ghostdevv added the needs review This PR is waiting for a review from a maintainer label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review This PR is waiting for a review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect label in the timeline "Typescript types removed"

2 participants