refactor(plugin): use standard dfs instead of topological for stable sort #262
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
之前插件的按依赖排序使用了拓扑排序算法;
而插件排序场景中对于不能靠
dependencies
声明来实现的,较普遍使用 pluginConfig 中的顺序做依赖顺序保障,而拓扑排序使顺序漂移问题变得不易发现和处理。Example
例如,当我们有这段配置时:
依赖链路为:
期待的顺序为
c, b, a, d
,即对于 a / d 作为无关项保持配置中的顺序;然而,因为拓扑排序不稳定,最终顺序与依赖链长度有关(indegree 出队顺序),所以结果会是
c, b, d, a
,如果 a / d 间有相互影响,将产生不可用现象Solution
综上,有必要对该部分做出改变
该 PR 通过 DFS 重新实现
PluginFactory.createFromConfig
方法,在递归过程中进行optional
和循环依赖检查;同时优化了 Plugin 类的实现代码,移除了无用方法;
调整了 plugin 相关单测,顺序保证增加到 4 个,并使用上述的依赖链 case 做验证