Skip to content

feat(module)!: use moduleDependencies to manipulate options#5384

Merged
benjamincanac merged 12 commits intov4from
refactor/deps
Mar 4, 2026
Merged

feat(module)!: use moduleDependencies to manipulate options#5384
benjamincanac merged 12 commits intov4from
refactor/deps

Conversation

@danielroe
Copy link
Copy Markdown
Member

@danielroe danielroe commented Nov 4, 2025

🔗 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 uses the new module dependencies feature in https://github.com/nuxt/nuxt/releases/tag/v4.1.0 to specify options for other modules (and require them).

remake of #4927, pending a fix in nuxt/content

📝 Checklist

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

@github-actions github-actions bot added the v4 #4488 label Nov 4, 2025
@danielroe danielroe changed the title Refactor/deps feat(module)!: use moduleDependencies to manipulate options Nov 4, 2025
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Nov 4, 2025

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

commit: 05b87e7

@benjamincanac
Copy link
Copy Markdown
Member

@danielroe I'm a bit hesitant to merge this as it will break apps that haven't been updated to https://github.com/nuxt/content/releases/tag/v3.8.1. We would need to update the @nuxt/content peer dependency to 3.8.1 as well right?

@danielroe
Copy link
Copy Markdown
Member Author

once I merge nuxt/nuxt#33689, we should be fine with the latest nuxt patch even if uses don't update content

@benjamincanac
Copy link
Copy Markdown
Member

@danielroe Should I merge this for the next minor?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 4, 2026

📝 Walkthrough

Walkthrough

The module refactoring shifts dependency management from inline registration (addImportsDir and installModule) to a declarative moduleDependencies hook. This hook configures defaults for @nuxt/icon, @nuxt/fonts, @nuxtjs/color-mode, and @nuxtjs/mdc based on user options and detected modules. Component registration logic now relies on option-driven enabling for prose, content, and color-mode components. Nuxt compatibility requirement is raised to version 4.1.0 or higher. Changes are localized to a single file with net modification of +72/-67 lines.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: introducing the moduleDependencies feature to manipulate module options, which aligns with the primary refactoring work shown in the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the use of the new module dependencies feature from Nuxt v4.1.0 and referencing prior work and pending fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/deps

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 (2)
src/module.ts (2)

239-248: Conditional logic may prevent fallback stub from being applied.

Since colorMode defaults to true (per JSDoc at line 31), the condition options.colorMode || hasNuxtModule('@nuxtjs/color-mode') will almost always be truthy, preventing the else branch from adding the stub composable.

If the intent is to add color-mode components only when the module is actually present (and fallback to stub otherwise), consider changing the logic to rely solely on module presence:

-    if (options.colorMode || hasNuxtModule('@nuxtjs/color-mode')) {
+    if (hasNuxtModule('@nuxtjs/color-mode')) {

Otherwise, if moduleDependencies guarantees the module is installed when colorMode !== false, this works correctly, but the options.colorMode check becomes redundant.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/module.ts` around lines 239 - 248, The current conditional uses
"options.colorMode || hasNuxtModule('@nuxtjs/color-mode')" which makes the
truthy default options.colorMode override module detection and skip the fallback
stub; change the logic to base the branch on the actual module presence only
(i.e., use hasNuxtModule('@nuxtjs/color-mode') to decide when to call
addComponentsDir for './runtime/components/color-mode' and otherwise call
addImportsDir('./runtime/composables/color-mode'), or conversely make the check
explicitly test options.colorMode !== false && hasNuxtModule(...)) so that
addComponentsDir and addImportsDir are invoked correctly; update references to
options.colorMode, hasNuxtModule, addComponentsDir, and addImportsDir in
module.ts accordingly.

145-152: Mark @nuxtjs/color-mode as optional: true in moduleDependencies to be more defensive and consistent with the @nuxtjs/mdc pattern.

Currently, @nuxtjs/color-mode is conditionally added to moduleDependencies without the optional flag. Since colorMode defaults to true, this declares the module as required by default. However, the stub composable at line 247 only handles the case where colorMode is explicitly disabled, not when the module is missing from an installation. Adding optional: true would match the defensive pattern used for @nuxtjs/mdc (line 154) and ensure the module gracefully falls back to stubs when unavailable, regardless of the default setting.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/module.ts` around lines 145 - 152, Update the entry for
'@nuxtjs/color-mode' in moduleDependencies to mark it optional (similar to the
'@nuxtjs/mdc' pattern) so the module system won't treat it as required; locate
where moduleDependencies is populated (the conditional using
userUiOptions.colorMode and the object for '@nuxtjs/color-mode') and add
optional: true to that object so the stub composable fallback works whether the
module is disabled or simply not installed.
🤖 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/module.ts`:
- Around line 239-248: The current conditional uses "options.colorMode ||
hasNuxtModule('@nuxtjs/color-mode')" which makes the truthy default
options.colorMode override module detection and skip the fallback stub; change
the logic to base the branch on the actual module presence only (i.e., use
hasNuxtModule('@nuxtjs/color-mode') to decide when to call addComponentsDir for
'./runtime/components/color-mode' and otherwise call
addImportsDir('./runtime/composables/color-mode'), or conversely make the check
explicitly test options.colorMode !== false && hasNuxtModule(...)) so that
addComponentsDir and addImportsDir are invoked correctly; update references to
options.colorMode, hasNuxtModule, addComponentsDir, and addImportsDir in
module.ts accordingly.
- Around line 145-152: Update the entry for '@nuxtjs/color-mode' in
moduleDependencies to mark it optional (similar to the '@nuxtjs/mdc' pattern) so
the module system won't treat it as required; locate where moduleDependencies is
populated (the conditional using userUiOptions.colorMode and the object for
'@nuxtjs/color-mode') and add optional: true to that object so the stub
composable fallback works whether the module is disabled or simply not
installed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1203ee26-2df4-4ad7-a26f-f39654a83680

📥 Commits

Reviewing files that changed from the base of the PR and between 83afd9c and 7aae05f.

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

@danielroe
Copy link
Copy Markdown
Member Author

yes, it should be 🙏

@benjamincanac benjamincanac merged commit dd3f5c5 into v4 Mar 4, 2026
17 checks passed
@benjamincanac benjamincanac deleted the refactor/deps branch March 4, 2026 21:28
@francoism90
Copy link
Copy Markdown

How does this work? Do I need to configure it? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants