Skip to content

Commit b98a984

Browse files
committed
art: 去除重复注册的插件,从设计的角度上,不该有重复的插件出现
1 parent d2f41ce commit b98a984

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"release": "node bin/index.js release",
1515
"release:alpha": "npm run release -- --preRelease=alpha",
1616
"release:next": "npm run release -- --preRelease=next",
17-
"release:minor": "npm run release minor",
18-
"release:patch": "npm run release patch"
17+
"release:minor": "npm run release -- minor",
18+
"release:patch": "npm run release -- patch"
1919
},
2020
"homepage": "https://github.com/MicroAppJS/core",
2121
"repository": {

src/core/Service/Service.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class Service extends PluginService {
154154
}
155155
}
156156

157+
// 清楚多余的命令
158+
delete args.preRegisterPlugin;
159+
157160
const { fn, opts } = command;
158161

159162
// TODO 分发引用,待优化

src/core/Service/libs/PluginService.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,25 @@ class PluginService extends MethodService {
316316
this.plugins.push(...this._getPlugins());
317317
const BUILT_IN = Symbol.for('built-in');
318318

319+
// 去除重复注册的插件,从设计的角度上,不该有重复的插件出现
320+
const alreadyPlugins = {};
321+
const duplicatePlugins = [];
322+
this.plugins = this.plugins.filter(plugin => {
323+
const id = plugin.id;
324+
const alias = plugin.alias;
325+
const link = plugin.link;
326+
const key = `${id}+${alias}+${link}`;
327+
if (alreadyPlugins[key]) {
328+
duplicatePlugins.push(plugin);
329+
return false;
330+
}
331+
alreadyPlugins[key] = true;
332+
return true;
333+
});
334+
if (duplicatePlugins.length) {
335+
logger.debug('[Plugin]', '_sortPlugins() duplicatePlugins:', duplicatePlugins);
336+
}
337+
319338
const builtInPlugins = [];
320339
const prePlugins = [];
321340
const normalPlugins = [];

0 commit comments

Comments
 (0)