Skip to content

feat(unplugin): add support for prose components#6198

Merged
benjamincanac merged 9 commits intov4from
feat/component-exports
Mar 17, 2026
Merged

feat(unplugin): add support for prose components#6198
benjamincanac merged 9 commits intov4from
feat/component-exports

Conversation

@benjamincanac
Copy link
Member

@benjamincanac benjamincanac commented Mar 16, 2026

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR adds a prose option to enable prose component auto-imports, theme generation, and global component registration in Vite (previously Nuxt-only, gated behind @nuxtjs/mdc or @nuxt/content module detection).

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@github-actions github-actions bot added the v4 #4488 label Mar 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

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

This change introduces a new prose option to the Nuxt UI module configuration while deprecating the existing mdc option. The module's component registration and template generation logic now support the prose option alongside the existing mdc option. Documentation is updated to reflect the terminology shift and provide guidance for the new option. Component sources are refactored to include a dedicated prose component group. Prose Vue components are conditionally collected and registered as global components when the prose option is enabled. The unplugin interface is adjusted to exclude content and experimental options from its exposed interface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly relates to the changeset, explaining the addition of a prose option for component auto-imports and theme generation in Vite.
Title check ✅ Passed The title 'feat(unplugin): add support for prose components' clearly and concisely summarizes the main change—adding prose component support to the unplugin. It directly reflects the primary objective of enabling prose functionality in the Vite plugin.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/component-exports
📝 Coding Plan
  • Generate coding plan for human review comments

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/content/docs/1.getting-started/2.installation/2.vue.md`:
- Around line 807-809: The note currently tells users they can import components
from `@nuxt/ui/components` when auto-import is disabled but omits the manual
import path required for Prose* components; update the prose to mention both
import locations by adding that Prose components must be imported from
`@nuxt/ui/components/prose` (in addition to `@nuxt/ui/components`) so the
manual-import instructions cover `Prose*` components as well.

In `@package.json`:
- Around line 34-41: The build config is missing source entry points for the new
runtime component exports; update the entries array in build.config.ts to
include './src/runtime/components' and './src/runtime/components/prose' so the
build will emit dist/runtime/components/index.js and
dist/runtime/components/prose/index.js; locate the entries array (entries) in
build.config.ts and add those two string paths to it alongside the existing
entries.

In `@src/module.ts`:
- Line 164: The optional flag currently sets optional: !userUiOptions.prose &&
!userUiOptions.mdc && !userUiOptions.content which wrongly makes `@nuxtjs/mdc`
required when prose is true; modify the expression that computes the optional
property so it no longer includes userUiOptions.prose (keep only
userUiOptions.mdc and userUiOptions.content), i.e., change the condition that
assigns optional to exclude prose while leaving prose handling elsewhere intact
(refer to the optional assignment and the userUiOptions.prose /
userUiOptions.mdc / userUiOptions.content symbols).

In `@src/plugins/components.ts`:
- Around line 67-77: The current resolution uses filteredSources in fixed order
so filename-based lookups can pick defaultComponents before prose-specific
sources; update the resolution logic that looks up by filename (the "resolve by
filename" block that iterates filteredSources around where filteredSources is
defined/used) to prioritize a source whose scope matches the importer: detect
the importer's scope (e.g., contains "/components/prose" or matches the
createComponentSource label like 'Prose') and, when resolving overlapping names
(e.g., Accordion.vue, Tabs.vue), prefer sources created by createComponentSource
for that scope (reorder or filter filteredSources per-importer before lookup),
applying the same change to the other similar lookup sites noted (the other
filename-resolution blocks around the 103–107 area).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f60fb38-bc82-4979-9d9f-f8ae21f3a317

📥 Commits

Reviewing files that changed from the base of the PR and between 886f5fb and 0f7f54c.

📒 Files selected for processing (10)
  • docs/content/docs/1.getting-started/2.installation/1.nuxt.md
  • docs/content/docs/1.getting-started/2.installation/2.vue.md
  • package.json
  • src/module.ts
  • src/plugins/components.ts
  • src/runtime/components/index.ts
  • src/runtime/components/prose/index.ts
  • src/templates.ts
  • src/unplugin.ts
  • src/utils/defaults.ts

@sandros94 sandros94 linked an issue Mar 16, 2026 that may be closed by this pull request
@sandros94
Copy link
Member

With this PR we could also mark #6137 as resolved via workaround?

Instead of relying on resolveComponent they can now directly import the components, with full type support

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 17, 2026

npm i https://pkg.pr.new/@nuxt/ui@6198

commit: 0b06c38

Update the CLI to automatically add new components to the barrel
index.ts files and add the step to the contributing guide checklist.
@benjamincanac benjamincanac changed the title feat(module): add prose option and component barrel exports feat(module): add prose option and direct component imports Mar 17, 2026
@benjamincanac benjamincanac changed the title feat(module): add prose option and direct component imports feat(module): add prose option Mar 17, 2026
@benjamincanac benjamincanac changed the title feat(module): add prose option feat(unplugin): add prose option Mar 17, 2026
Copy link
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/commands/make/component.mjs`:
- Around line 80-81: Remove the padded blank line immediately before the closing
block brace in the make component command so the block end is not separated by
an extra empty line; edit the closing '}' in cli/commands/make/component.mjs to
have no blank line above it (i.e., collapse the empty line so the prior
statement is directly followed by the '}') to satisfy `@stylistic/padded-blocks`
and allow pnpm run lint to pass.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14ecf2ff-8136-45a0-8aef-f2f4de267e23

📥 Commits

Reviewing files that changed from the base of the PR and between 60c4f46 and bacb8f4.

📒 Files selected for processing (3)
  • cli/commands/make/component.mjs
  • docs/content/docs/1.getting-started/2.installation/2.vue.md
  • src/module.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/content/docs/1.getting-started/2.installation/2.vue.md

Copy link
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)
src/plugins/plugins.ts (1)

51-54: Use full relative paths and genSafeVariableName for prose component imports to prevent collisions.

Line 52 currently extracts only the basename, which would cause duplicate names if the prose directory structure changes (e.g., adding a root-level Caution.vue when callout/Caution.vue exists). Additionally, it doesn't validate generated names as safe JavaScript identifiers.

Refactor to use the full relative path (similar to how plugins are handled on lines 57 and 62) and apply genSafeVariableName for import identifiers:

Suggested refactor
-      const proseImports = proseComponents.map((p) => {
-        const name = `Prose${p.split('/').pop()?.replace(/\.vue$/, '')}`
-        return { name, path: p }
-      })
+      const proseImports = proseComponents.map((p) => {
+        const rel = p
+          .replace(join(runtimeDir, 'components/prose') + '/', '')
+          .replace(/\.vue$/, '')
+
+        const componentName = `Prose${rel
+          .split('/')
+          .map(part => part.charAt(0).toUpperCase() + part.slice(1))
+          .join('')}`
+
+        const importName = genSafeVariableName(componentName)
+        return { componentName, importName, path: p }
+      })
...
-        ${proseImports.map(c => `import ${c.name} from "${c.path}"`).join('\n')}
+        ${proseImports.map(c => `import ${c.importName} from "${c.path}"`).join('\n')}
...
-${proseImports.map(c => `    app.component('${c.name}', ${c.name})`).join('\n')}
+${proseImports.map(c => `    app.component('${c.componentName}', ${c.importName})`).join('\n')}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugins/plugins.ts` around lines 51 - 54, proseImports currently builds
identifiers from only the basename which risks collisions and may produce
invalid JS identifiers; update the mapping that creates proseImports (where
proseComponents is used) to use the full relative path for path (like how
plugins are handled) and generate the import name via genSafeVariableName
instead of `Prose${...}` so import identifiers are safe and unique; locate the
mapping that returns { name, path } for prose components and replace the
basename logic with a full-path based name created by calling
genSafeVariableName on a unique string (e.g., the relative path) while keeping
path set to the full relative path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/plugins/plugins.ts`:
- Around line 51-54: proseImports currently builds identifiers from only the
basename which risks collisions and may produce invalid JS identifiers; update
the mapping that creates proseImports (where proseComponents is used) to use the
full relative path for path (like how plugins are handled) and generate the
import name via genSafeVariableName instead of `Prose${...}` so import
identifiers are safe and unique; locate the mapping that returns { name, path }
for prose components and replace the basename logic with a full-path based name
created by calling genSafeVariableName on a unique string (e.g., the relative
path) while keeping path set to the full relative path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 917a1d01-87a6-45f4-a291-f1642b4491ff

📥 Commits

Reviewing files that changed from the base of the PR and between bacb8f4 and 76f6b50.

📒 Files selected for processing (1)
  • src/plugins/plugins.ts

@benjamincanac benjamincanac changed the title feat(unplugin): add prose option feat(unplugin): add support for prose components Mar 17, 2026
@benjamincanac benjamincanac merged commit c58b9b2 into v4 Mar 17, 2026
18 checks passed
@benjamincanac benjamincanac deleted the feat/component-exports branch March 17, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing from @nuxt/ui broken on vue vite template

2 participants