File tree Expand file tree Collapse file tree 4 files changed +14
-5
lines changed
Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,7 @@ const initPluginManager = (context: IPluginContext) => {
1515 const pluginManager = new PluginManager ( ) ;
1616
1717 // 注册插件
18- pluginManager . register ( [
19- ...( context . options . plugins ?? [ ] ) ,
20- ] ) ;
18+ pluginManager . register ( context . options . plugins ?? [ ] ) ;
2119 // 启动所有插件
2220 pluginManager . setupAll ( context ) ;
2321} ;
Original file line number Diff line number Diff line change 5555 "parserActionDone" : " Parsing url data is complete." ,
5656 "no_200_response" : " Missing information for 200 status code." ,
5757 "no_tag" : " {{url}} does not specify a tag, skip parsing. Please use the --tag parameter." ,
58+ "alreadyRegistered" : " Plugin {{names}} is already registered." ,
5859 "template" : {
5960 "enumRequired" : " Missing enum.eta template file." ,
6061 "actionImportRequired" : " Missing actionImport.eta template file." ,
Original file line number Diff line number Diff line change 5555 "parserActionDone" : " 解析接口完成。" ,
5656 "no_200_response" : " 缺少 200 状态码的信息。" ,
5757 "no_tag" : " {{url}} 未指定 tag,跳过解析。请使用 --tag 参数。" ,
58+ "alreadyRegistered" : " 内置插件 {{names}} 不能被重复注册。" ,
5859 "template" : {
5960 "enumRequired" : " 缺失 enum.eta 模板文件。" ,
6061 "actionImportRequired" : " 缺失 actionImport.eta 模板文件。" ,
Original file line number Diff line number Diff line change @@ -15,10 +15,19 @@ export class PluginManager {
1515 // SwiftPlugin,
1616 ] ;
1717
18- register ( plugin : IPlugin | IPlugin [ ] ) {
18+ register ( plugins : IPlugin [ ] ) {
19+ const pluginNames = plugins . map ( ( item ) => item . name ) . join ( ", " ) ;
20+ // 如果插件已经存在,则不重复注册
21+ if ( this . plugins . every ( ( item ) => pluginNames . includes ( item . name ) ) ) {
22+ Logs . warn (
23+ getT ( "$t(plugin.alreadyRegistered)" , { names : pluginNames } ) ,
24+ ) ;
25+ return ;
26+ }
27+
1928 this . plugins = [
2029 ...this . plugins ,
21- ...( Array . isArray ( plugin ) ? plugin : [ plugin ] ) ,
30+ ...( Array . isArray ( plugins ) ? plugins : [ plugins ] ) ,
2231 ] ;
2332 }
2433
You can’t perform that action at this time.
0 commit comments