-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add getLayerModuleOptions
#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA new utility function, Changes
Sequence Diagram(s)sequenceDiagram
participant ModuleSetup as Nuxt Module Setup
participant Layer as NuxtConfigLayer
participant Utility as getLayerModuleOptions
ModuleSetup->>Layer: Iterate over config layers
ModuleSetup->>Utility: Call getLayerModuleOptions(layer, configKey, name)
Utility->>Layer: Retrieve inline and key-based options
Utility-->>ModuleSetup: Return merged module options
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (4)
src/layers.ts (3)
32-33: Improve type safety of the module type guard.The
anytype reduces type safety and could be replaced with a more specific type.- const matchInlineOptions = (mod: any): mod is [string, Options] => + const matchInlineOptions = (mod: unknown): mod is [string, Options] =>
35-39: Consider safer type assertion for modules array.The current type assertion assumes all modules follow the
[string, unknown]pattern, but Nuxt modules can also be simple strings.- const modules = (layer.config.modules || []) as [ - string, - unknown | undefined, - ][]; - const inlineOptions = modules.find(matchInlineOptions)?.[1]; + const modules = layer.config.modules || []; + const inlineOptions = modules.find(matchInlineOptions)?.[1];The type guard
matchInlineOptionswill safely filter for the correct format.
46-46: Clarify merge precedence in documentation.The current implementation gives precedence to inline options over key-based options (
defu(keyOptions || {}, inlineOptions || {})), but this behavior isn't explicitly documented.Consider updating the JSDoc to clarify that inline options take precedence:
- * Returns the merged options if both are provided, or the first available option. + * Returns the merged options if both are provided (inline options take precedence), or the first available option.README.md (1)
41-41: Consider simplifying the wording.The phrase "takes into account" could be more concise.
-This takes into account both inline module options specified in the `modules` array and options specified in the layer's config under a specific key. +This considers both inline module options specified in the `modules` array and options specified in the layer's config under a specific key.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md(1 hunks)src/index.ts(1 hunks)src/layers.ts(1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md
[style] ~41-~41: ‘takes into account’ might be wordy. Consider a shorter alternative.
Context: ... options from a given Nuxt layer. This takes into account both inline module options specified in...
(EN_WORDINESS_PREMIUM_TAKES_INTO_ACCOUNT)
🔇 Additional comments (3)
src/layers.ts (1)
4-7: LGTM: Well-designed conditional type.The
GetModuleOptionstype correctly handles the case where no explicit type is provided (T = never) by falling back to the config layer type, while preserving the explicit type when provided.src/index.ts (1)
2-2: LGTM: Clean export addition.The export follows the established pattern and correctly exposes the new utility function.
README.md (1)
43-68: Excellent documentation with comprehensive example.The usage example clearly demonstrates the function's purpose and provides practical TypeScript code that developers can follow. The example correctly shows the function signature and usage pattern.
There was a problem hiding this 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)
README.md (2)
41-41: Streamline wording for clarityThe phrase “This takes into account” is a bit verbose for tech docs. Consider “It considers” or simply drop the filler altogether.
-This takes into account both inline module options specified in the `modules` array ... +It considers both inline module options specified in the `modules` array ...
57-63: Show generic usage to preserve strong typingThe example omits the type argument for
getLayerModuleOptions, so the returned value is inferred asany. Supplying the generic makes the snippet production-ready and demonstrates intent.- const layerModuleOptions = getLayerModuleOptions( - layer, - 'myModule', // key in nuxt.config - 'my-module' // name in modules array - ) + const layerModuleOptions = getLayerModuleOptions<ModuleOptions>( + layer, + 'myModule', // key in nuxt.config + 'my-module' // name in modules array + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
README.md(1 hunks)src/layers.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/layers.ts
🧰 Additional context used
🪛 LanguageTool
README.md
[style] ~41-~41: ‘takes into account’ might be wordy. Consider a shorter alternative.
Context: ... options from a given Nuxt layer. This takes into account both inline module options specified in...
(EN_WORDINESS_PREMIUM_TAKES_INTO_ACCOUNT)
Adds a utility function to get the configured module options (inline + key config) of a given layer.
Summary by CodeRabbit
New Features
Documentation