Skip to content

Commit 9f9fd09

Browse files
committed
feat: 内置插件不允许被自定义覆盖
1 parent 4d4ac86 commit 9f9fd09

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/app.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff 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
};

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
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.",

src/i18n/locales/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
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 模板文件。",

src/plugins/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)