Skip to content

fix: no types declaration in package.json#1674

Merged
danielroe merged 4 commits intonpmx-dev:mainfrom
eryue0220:fix/issue-1669
Feb 26, 2026
Merged

fix: no types declaration in package.json#1674
danielroe merged 4 commits intonpmx-dev:mainfrom
eryue0220:fix/issue-1669

Conversation

@eryue0220
Copy link
Copy Markdown
Contributor

@eryue0220 eryue0220 commented Feb 26, 2026

🔗 Linked issue

Fixed #1669

🧭 Context

npmx currently shows “no types” for packages that ship declaration files via implicit lookup (without types/typings in package.json), even when those files exist in the package.

📚 Description

Check the files that it include some file like *.d.ts, *.d.cts or *.d.mts, then we think the package has types.

Result

image

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 26, 2026

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

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 26, 2026 10:34pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 26, 2026 10:34pm
npmx-lunaria Ignored Ignored Feb 26, 2026 10:34pm

Request Review

@eryue0220 eryue0220 changed the title fix: No types declaration in package.json fix: no types declaration in package.json Feb 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 26, 2026

Codecov Report

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

Files with missing lines Patch % Lines
shared/utils/package-analysis.ts 2.50% 26 Missing and 13 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

Adds file-tree-aware package analysis: the API now optionally fetches and flattens a package file tree and concurrently fetches @types info when a package lacks built-in types. The analysis entry now accepts an optional files?: Set<string> and detectTypesStatus uses this set to infer implicit declarations (e.g. .d.mts/.d.cts/.d.ts) adjacent to runtime entry points. File-tree and types fetches use Promise.allSettled so failures are ignored and analysis proceeds.

Suggested reviewers

  • 43081j
  • wojtekmaj
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description accurately describes the changes and links to the correct issue, though it uses some AI-generated language.
Linked Issues check ✅ Passed All code changes directly address issue #1669: file-tree awareness, implicit types detection via .d.ts/.d.mts/.d.cts patterns, and tests validating the new detection logic.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing implicit TypeScript types detection; no unrelated modifications are present.

✏️ 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
Copy Markdown
Contributor

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

🧹 Nitpick comments (4)
test/unit/shared/utils/package-analysis.spec.ts (1)

181-211: Rename the “path derivation” cases to match what is actually asserted.

These tests currently validate declaration-file presence in files, not explicit derivation from runtime entrypoints. Renaming will avoid misleading future readers.

Suggested naming-only diff
-describe('detectTypesStatus implicit types (path derivation)', () => {
-  it('derives .d.mts from .mjs in exports', () => {
+describe('detectTypesStatus implicit declaration files', () => {
+  it('detects .d.mts in files', () => {
@@
-  it('derives .d.cts from .cjs in exports', () => {
+  it('detects .d.cts in files', () => {
@@
-  it('derives .d.mts from main when type is module', () => {
+  it('detects .d.mts in files when package is module', () => {
server/api/registry/analysis/[...pkg].get.ts (2)

60-67: Run @types lookup and file-tree fetch concurrently to reduce endpoint latency.

Both calls are independent in this branch, so serial awaits add avoidable response time.

Suggested refactor (keeps file-tree failure tolerance)
       if (!hasBuiltInTypes(pkg)) {
         const typesPkgName = getTypesPackageName(packageName)
-        typesPackage = await fetchTypesPackageInfo(typesPkgName)
-
         const resolvedVersion = pkg.version ?? version ?? 'latest'
-        try {
-          const fileTreeResponse = await getPackageFileTree(packageName, resolvedVersion)
-          files = flattenFileTree(fileTreeResponse.tree)
-        } catch {
-          // File tree fetch failed - skip implicit types check
-        }
+        const typesPackagePromise = fetchTypesPackageInfo(typesPkgName)
+        const filesPromise = getPackageFileTree(packageName, resolvedVersion)
+          .then(fileTreeResponse => flattenFileTree(fileTreeResponse.tree))
+          .catch(() => undefined)
+
+        typesPackage = await typesPackagePromise
+        files = await filesPromise
       }

67-69: Consider lightweight telemetry in the file-tree failure path.

The empty catch keeps behaviour resilient, but it also hides recurring upstream issues. A debug log/metric here would help monitor implicit-types coverage.

shared/utils/package-analysis.ts (1)

249-253: Align the inline comment with the implemented behaviour.

The current code checks for any declaration file in files; it does not collect entrypoint-derived paths from exports/main/module. Please update the comment to prevent misinterpretation.


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf4b537 and 8b0d074.

📒 Files selected for processing (3)
  • server/api/registry/analysis/[...pkg].get.ts
  • shared/utils/package-analysis.ts
  • test/unit/shared/utils/package-analysis.spec.ts

Copy link
Copy Markdown
Contributor

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

🧹 Nitpick comments (1)
shared/utils/package-analysis.ts (1)

267-280: Consider handling extensionless or non-JS entry paths.

The function returns an empty array when the entry path doesn't end with a known JS extension (.mjs, .cjs, .js). This is a safe fallback, but packages may occasionally specify entry points with unusual patterns (e.g., extensionless paths or .ts entries in rare cases). The current behaviour is acceptable for the PR's objective, but it's worth noting this limitation.


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b0d074 and a028607.

📒 Files selected for processing (3)
  • server/api/registry/analysis/[...pkg].get.ts
  • shared/utils/package-analysis.ts
  • test/unit/shared/utils/package-analysis.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/shared/utils/package-analysis.spec.ts

@danielroe danielroe enabled auto-merge February 26, 2026 22:35
@danielroe danielroe added this pull request to the merge queue Feb 26, 2026
Merged via the queue into npmx-dev:main with commit d8a01e6 Feb 26, 2026
17 checks passed
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.

"No TypeScript types" shown even if it does have

2 participants