Skip to content

Conversation

@8ctavio
Copy link
Contributor

@8ctavio 8ctavio commented Oct 1, 2025

🔗 Linked issue

Resolves #33372

📚 Description

Update unimport to 5.4.1

This version fixes the typeFrom property being omitted when resolving import presets (import sources).

addDeclarationTemplates support for typeFrom

Inside addDeclarationTemplates autoimported module names/paths are retrieved from the typeFrom property if provided (_import.typeFrom || _import.from) since they are used for .d.ts files.

@8ctavio 8ctavio requested a review from danielroe as a code owner October 1, 2025 22:57
@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 1, 2025

Walkthrough

  • Updated import resolution in packages/nuxt/src/imports/module.ts to prefer i.typeFrom over i.from when mapping and caching import sources.
  • Adjusted resolvedImportPathMap lookups to use i.typeFrom || i.from.
  • Changed the extensions regex from a capturing group to a non-capturing group: from \\.(${exts})$ to \\.(?:${exts})$.
  • cacheImportPaths now derives unique sources using i.typeFrom || i.from.
  • pnpm-workspace.yaml: removed the exclusion pattern '!packages/nuxt/test/package-fixture', making that package part of the workspace.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request includes a removal of an exclusion in pnpm-workspace.yaml that is unrelated to the typeFrom support objective in issue #33372, introducing a configuration change outside the scope of the linked issue’s requirements. Please isolate the pnpm-workspace.yaml modification into a separate pull request or provide justification for its inclusion to keep this fix focused on the linked issue’s objective.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely and accurately summarises the primary change by indicating that support for autoimports’ typeFrom property has been added when generating type templates, and it follows conventional commit style without unnecessary details.
Linked Issues Check ✅ Passed The changes directly address issue #33372 by updating the unimport dependency to v5.4.1 and modifying addDeclarationTemplates to respect _import.typeFrom, thereby ensuring type declarations use the correct source as outlined in the linked issue objectives.
Description Check ✅ Passed The pull request description clearly relates to the changeset by describing the unimport version update and the addition of typeFrom support in the declaration template generation, providing context and rationale for the modifications.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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

@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/src/imports/module.ts (1)

208-208: Regex pattern should escape extension strings to prevent unintended behaviour.

Whilst the change to a non-capturing group is appropriate, the regex is constructed from nuxt.options.extensions without escaping special characters. If an extension contains regex metacharacters (e.g., .c++), the pattern may behave unexpectedly.

Apply this diff to escape extension strings:

-  const SUPPORTED_EXTENSION_RE = new RegExp(`\\.(?:${nuxt.options.extensions.map(i => i.replace('.', '')).join('|')})$`)
+  const SUPPORTED_EXTENSION_RE = new RegExp(`\\.(?:${nuxt.options.extensions.map(i => escapeRE(i.replace('.', ''))).join('|')})$`)

Note: escapeRE is already imported at line 6.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9bebe27 and be9946a.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !package.json, !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (2)
  • packages/nuxt/src/imports/module.ts (1 hunks)
  • pnpm-workspace.yaml (0 hunks)
💤 Files with no reviewable changes (1)
  • pnpm-workspace.yaml
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

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

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/src/imports/module.ts
🧬 Code graph analysis (1)
packages/nuxt/src/imports/module.ts (1)
packages/kit/src/internal/esm.ts (1)
  • directoryToURL (13-15)
🪛 ast-grep (0.39.5)
packages/nuxt/src/imports/module.ts

[warning] 207-207: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(\\.(?:${nuxt.options.extensions.map(i => i.replace('.', '')).join('|')})$)
Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html

(regexp-from-variable)

⏰ 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). (17)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-size
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: test-benchmark
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: typecheck (windows-latest, bundler)
🔇 Additional comments (2)
packages/nuxt/src/imports/module.ts (2)

206-206: LGTM! Correct prioritisation of typeFrom for path resolution.

The resolver function now correctly uses i.typeFrom || i.from, ensuring type declarations reference the appropriate source when typeFrom is provided.


213-213: LGTM! Cache logic correctly aligned with typeFrom support.

The import source derivation now uses i.typeFrom || i.from, ensuring the cache is populated with keys that match the lookup logic at line 206.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 1, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 16ac857

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 1, 2025

CodSpeed Performance Report

Merging #33373 will not alter performance

Comparing 8ctavio:fix-1 (16ac857) with main (9bebe27)

Summary

✅ 10 untouched

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

thank you ❤️

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.

Auto-imports' typeFrom property is ignored for type template generation

2 participants