Skip to content

Conversation

@DipakHalkude
Copy link
Contributor

…le paths

🔗 Linked issue

📚 Description

…le paths

- Add declarationPath to Component and ScanDir/ComponentsDir interfaces
- Update scanComponents to handle declarationPath from directory config
- Update type template generation to use declarationPath when available
- Maintain backward compatibility with filePath fallback
- Resolves nuxt#33374
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

Walkthrough

Adds an optional declarationPath property to Component and ScanDir interfaces in packages/schema/src/types/components.ts (documented). packages/nuxt/src/components/scan.ts is changed to populate Component.declarationPath from dir.declarationPath, defaulting to the component filePath. packages/nuxt/src/components/templates.ts now prefers declarationPath when choosing the source path for generated component type imports (falls back to filePath). Tests in packages/nuxt/test/scan-components.test.ts updated to include declarationPath in expected component entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The changes fully implement the linked issue’s coding objectives by adding declarationPath to Component and ScanDir interfaces, updating scanComponents to propagate it, and modifying resolveComponentTypes to prefer declarationPath over filePath, thus satisfying issue #33374.
Out of Scope Changes Check ✅ Passed All modifications are confined to adding and propagating the declarationPath property across component scanning, type generation, and tests, with no unrelated code touched.
Description Check ✅ Passed The pull request description accurately outlines the added declarationPath property, updated scanComponents logic, and the type template generation fallback, clearly mapping to the implemented changes.
Title Check ✅ Passed The title succinctly describes the primary change by indicating the addition of a declarationPath option for components in Nuxt, aligning with the changeset’s objective to support explicit declaration file paths.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 7, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33419

nuxt

npm i https://pkg.pr.new/nuxt@33419

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33419

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33419

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33419

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33419

commit: 24db336

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 7, 2025

CodSpeed Performance Report

Merging #33419 will not alter performance

Comparing DipakHalkude:feature/component-declaration-path (24db336) with main (5589a44)

Summary

✅ 10 untouched

Copy link

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/nuxt/test/scan-components.test.ts (2)

89-241: Test expectations correctly updated to include declarationPath field.

The additions properly reflect the new Component interface shape. Each declarationPath matches the component file path, which correctly validates the default fallback behavior when no custom declarationPath is configured.

However, consider adding test coverage for the primary use case where declarationPath differs from filePath. This would validate the feature's intended functionality per issue #33374.

Add a test directory configuration with a custom declarationPath to validate the feature:

{
  path: rFixture('components'),
  extensions: ['vue'],
  pattern: '**/*.{vue,}',
  ignore: ['**/*.stories.{js,ts,jsx,tsx}', '**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', '**/*.d.ts'],
  transpile: false,
  declarationPath: rFixture('types/custom-declarations.d.ts'), // Custom declaration path
}

Then verify that scanned components from this directory use the custom declarationPath rather than their filePath.


247-253: Consider verifying both filePath and declarationPath together.

The test deletes filePath before comparison, which prevents verifying the relationship between filePath and declarationPath. Since the PR introduces logic to fall back to filePath when declarationPath is not provided, consider asserting both properties to ensure the fallback behaviour works correctly.

Alternatively, add a separate assertion to verify the relationship:

// Verify declarationPath defaults to filePath when not explicitly set
for (const c of scannedComponents) {
  if (!dirs.find(d => d.declarationPath)) {
    expect(c.declarationPath).toBe(c.filePath)
  }
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2483eac and b467482.

📒 Files selected for processing (1)
  • packages/nuxt/test/scan-components.test.ts (12 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/test/scan-components.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • packages/nuxt/test/scan-components.test.ts

Copy link

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/nuxt/test/scan-components.test.ts (1)

86-241: Test data correctly updated for default behaviour.

The declarationPath field has been properly added to all component entries, demonstrating the default fallback behaviour where declarationPath equals filePath. The test coverage spans various component scenarios including islands, globals, and client/server modes.

Consider adding a test case where declarationPath differs from filePath to verify the core feature—using an explicit declaration path separate from the source file. This would ensure the feature works as intended when consumers actually specify a different declaration path.

Example test configuration:

{
  path: rFixture('components'),
  declarationPath: rFixture('types/components'),
  // ... other config
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b467482 and 24db336.

📒 Files selected for processing (4)
  • packages/nuxt/src/components/scan.ts (1 hunks)
  • packages/nuxt/src/components/templates.ts (1 hunks)
  • packages/nuxt/test/scan-components.test.ts (11 hunks)
  • packages/schema/src/types/components.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nuxt/src/components/scan.ts
  • packages/nuxt/src/components/templates.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/test/scan-components.test.ts
  • packages/schema/src/types/components.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • packages/nuxt/test/scan-components.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: code
🔇 Additional comments (3)
packages/schema/src/types/components.ts (2)

24-29: LGTM! Well-documented addition.

The declarationPath property is properly defined as optional with clear documentation. The @default filePath notation effectively communicates the fallback behaviour.


75-79: Consistent and well-integrated addition.

The declarationPath property mirrors the Component interface addition, ensuring consistency across the type system. Since ComponentsDir extends ScanDir, it correctly inherits this property.

packages/nuxt/test/scan-components.test.ts (1)

245-254: Testing approach correctly isolates the new property.

The test appropriately removes filePath from assertions whilst retaining declarationPath, allowing focused verification of the new property. The @ts-expect-error suppressions are justified with clear comments.

@DipakHalkude
Copy link
Contributor Author

@danielroe Just a friendly reminder about this PR when you have a moment! All checks are passing and it's ready for your review. 😊

@danielroe
Copy link
Member

don't worry! I was waiting until we were ready for a minor/feature release.

@DipakHalkude
Copy link
Contributor Author

DipakHalkude commented Oct 7, 2025

I really appreciate your review and guidance on this PR. I was wondering — since the repo participates in Hacktoberfest,would it be possible to add the hacktoberfest-accepted label now, even if the merge will happen with the next minor/feature release?

If that’s not possible at this stage, no worries at all — I completely understand and am happy to wait until the PR is merged. Thank you so much! 🙏

@danielroe danielroe changed the title feat(nuxt): add declarationPath property for component type declarations feat(nuxt): allow specifying component declarationPath Oct 7, 2025
@danielroe danielroe merged commit 23aa59d into nuxt:main Oct 7, 2025
48 checks passed
@github-actions github-actions bot mentioned this pull request Oct 7, 2025
@github-actions github-actions bot mentioned this pull request Oct 23, 2025
@github-actions github-actions bot mentioned this pull request Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Component property to support alternative path for components' declaration files

2 participants