-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat(kit): add onInstall and onUpgrade module hooks
#32397
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
|
|
3f5c834 to
3fbcbdd
Compare
WalkthroughAdds two optional lifecycle hooks, onInstall and onUpgrade, to module typings and the normalized module object. The module install workflow now reads module metadata and a .nuxtrc file, invokes onInstall for first-time installs and onUpgrade when semver detects a newer version, logs errors, and updates .nuxtrc before module invocation. A test module implementing these hooks and a sequential test suite exercising install, idempotent install, and upgrade scenarios were added. No public function signatures were changed. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (4)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
3fbcbdd to
09d23d5
Compare
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
packages/kit/src/module/install.ts
Outdated
| if (!previousVersion) { | ||
| await nuxtModule?.onInstall?.(nuxt) | ||
| } else if (semver.gt(meta.version, previousVersion)) { | ||
| await nuxtModule?.onUpgrade?.(inlineOptions, nuxt, previousVersion) | ||
| } |
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.
Maybe try catching error here and tell the user what went wrong, then exit later?
CodSpeed Performance ReportMerging #32397 will not alter performanceComparing Summary
|
🔗 Linked issue
Resolves #31070
📚 Description
Adds
onInstallandonUpgrademodule hooks to let modules perform additional setup steps when installed or upgraded. These hooks are defined in the module definition:Note that the
nameandversionfields must be provided in the module's metadata for these hooks to be executed.The implementation uses the
.nuxtrcfile internally to detect when hooks must be executed. It logs the module's version assetups.my-module="1.0.0"after a hook is executed, ensuring that the correct hook is triggered when the module is updated or installed.Possible follow-ups:
onUninstallhook which would be run when a module is removed (if it is still available).rcfiles into@unjs/c12'supdateConfigfunction to make the implementation here a bit more straightforward.nuxi module addcommand could also be updated to run theonInstallhook.