-
Notifications
You must be signed in to change notification settings - Fork 213
fix(前端类型错误): 修复前端插件类型定义问题以及usePluginStore部分函数返回值类型错误问题 #382
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
WalkthroughThe changes involve modifications to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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: 2
🧹 Outside diff range and nitpick comments (1)
web/src/store/modules/usePluginStore.ts (1)
Line range hint
66-71
: Align implementation with enabled function for consistency.The disabled function should follow the same patterns as the enabled function for consistency and safety.
Apply these improvements:
- function disabled(pluginName: string) { - if (plugins.value[pluginName]) { - const plg = plugins.value[pluginName] - plg.config.enable = false + function disabled(pluginName: string) { + try { + if (plugins.value[pluginName]) { + const plg = plugins.value[pluginName] as Plugin.PluginConfig + plg.config.enable = false + return true + } + return false + } catch (error) { + console.error(`Failed to disable plugin ${pluginName}:`, error) + return false } }🧰 Tools
🪛 Biome
[error] 57-58: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- web/src/store/modules/usePluginStore.ts (1 hunks)
- web/types/global.d.ts (1 hunks)
🧰 Additional context used
🪛 Biome
web/src/store/modules/usePluginStore.ts
[error] 57-58: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (3)
web/src/store/modules/usePluginStore.ts (1)
53-55
: LGTM! Type changes improve type safety.The removal of the incorrect return type and explicit type assertion for
plg
better reflect the actual implementation.web/types/global.d.ts (2)
67-67
: LGTM! Makingconfig
required improves type safety.The change from optional to required for the
config
property is appropriate since it contains essential plugin information (info
) and the enable flag that are necessary for plugin functionality.
67-67
: Verify existing plugin implementations.Since making
config
required is a breaking change, we should verify that all existing plugin implementations provide the config object.✅ Verification successful
All plugin implementations have been verified to provide the config property
Based on the search results, all existing plugin implementations (
demo
,basic-ui
, andapp-store
plugins) properly implement thePlugin.PluginConfig
interface and provide the requiredconfig
property. For example:
web/src/plugins/mine-admin/app-store/index.ts
:const pluginConfig: Plugin.PluginConfig = { install() { ... }, config: { enable: import.meta.env.DEV, } }The change to make
config
required is safe as all existing implementations already include it.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for plugin implementations to verify they provide the config property ast-grep --pattern 'const $plugin: Plugin.PluginConfig = { $$$ }' # Also search for potential plugin class implementations ast-grep --pattern 'class $_ implements Plugin.PluginConfig { $$$ }'Length of output: 142
Script:
#!/bin/bash # Search for Plugin type/interface definitions to understand the correct type name rg "Plugin" -A 5 "web/types/global.d.ts" # Then search for plugin implementations using ripgrep since ast-grep pattern didn't yield results rg "Plugin" --type typescript -A 5Length of output: 564
Script:
#!/bin/bash # Search for files with .ts or .tsx extension that might contain plugin implementations fd -e ts -e tsx --exec rg -l "PluginConfig|Plugin.PluginConfig" # Then get the content of those files to analyze plugin implementations fd -e ts -e tsx --exec rg "PluginConfig|Plugin.PluginConfig" -B 2 -A 5 {}Length of output: 4885
if (plg?.hooks && plg?.hooks?.start) { | ||
await plg.hooks.start(plg.config) |
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.
Use optional chaining for hooks access.
The static analysis correctly identifies a potential null/undefined access.
Apply this fix:
- if (plg?.hooks && plg?.hooks?.start) {
+ if (plg?.hooks?.start) {
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (plg?.hooks && plg?.hooks?.start) { | |
await plg.hooks.start(plg.config) | |
if (plg?.hooks?.start) { | |
await plg.hooks.start(plg.config) |
🧰 Tools
🪛 Biome
[error] 57-58: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
async function enabled(pluginName: string) { | ||
if (plugins.value[pluginName]) { | ||
const plg = plugins.value[pluginName] | ||
const plg = plugins.value[pluginName] as Plugin.PluginConfig | ||
plg.config.enable = true | ||
if (plg?.hooks && plg?.hooks?.start) { | ||
await plg.hooks.start(plg.config) | ||
} | ||
if (!useList.value[pluginName]) { | ||
useList.value[pluginName] = instance.value.use(plg.install) | ||
useList.value[pluginName] = instance.value?.use(plg.install) | ||
} | ||
} |
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.
🛠️ Refactor suggestion
Consider adding error handling and status indication.
The function should provide feedback about whether the plugin was successfully enabled.
Consider this improvement:
async function enabled(pluginName: string) {
+ try {
if (plugins.value[pluginName]) {
const plg = plugins.value[pluginName] as Plugin.PluginConfig
plg.config.enable = true
if (plg?.hooks && plg?.hooks?.start) {
await plg.hooks.start(plg.config)
}
if (!useList.value[pluginName]) {
useList.value[pluginName] = instance.value?.use(plg.install)
}
+ return true
}
+ return false
+ } catch (error) {
+ console.error(`Failed to enable plugin ${pluginName}:`, error)
+ return false
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function enabled(pluginName: string) { | |
if (plugins.value[pluginName]) { | |
const plg = plugins.value[pluginName] | |
const plg = plugins.value[pluginName] as Plugin.PluginConfig | |
plg.config.enable = true | |
if (plg?.hooks && plg?.hooks?.start) { | |
await plg.hooks.start(plg.config) | |
} | |
if (!useList.value[pluginName]) { | |
useList.value[pluginName] = instance.value.use(plg.install) | |
useList.value[pluginName] = instance.value?.use(plg.install) | |
} | |
} | |
async function enabled(pluginName: string) { | |
try { | |
if (plugins.value[pluginName]) { | |
const plg = plugins.value[pluginName] as Plugin.PluginConfig | |
plg.config.enable = true | |
if (plg?.hooks && plg?.hooks?.start) { | |
await plg.hooks.start(plg.config) | |
} | |
if (!useList.value[pluginName]) { | |
useList.value[pluginName] = instance.value?.use(plg.install) | |
} | |
return true | |
} | |
return false | |
} catch (error) { | |
console.error(`Failed to enable plugin ${pluginName}:`, error) | |
return false | |
} | |
} |
🧰 Tools
🪛 Biome
[error] 57-58: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Summary by CodeRabbit
New Features
PluginConfig
interface to ensure all plugins provide necessary settings.Bug Fixes