|
9 | 9 | #include <stdcorelib/pimpl.h> |
10 | 10 |
|
11 | 11 | #include <synthrt/Core/Dependency/DependencyGraph.h> |
| 12 | +#include <synthrt/Core/Dependency/DependencyResolver.h> |
12 | 13 | #include <synthrt/Core/Dependency/LevelCompatibilityChecker.h> |
13 | 14 | #include <synthrt/Core/Support/Logging.h> |
14 | 15 | #include <synthrt/G2P/Support/ContextUtils.h> |
@@ -86,6 +87,14 @@ namespace srt::g2p { |
86 | 87 | return compatible; |
87 | 88 | } |
88 | 89 |
|
| 90 | + /// 解析模块间声明的依赖(package.json 的 dependencies), |
| 91 | + /// 填充 resolvedDependencies,使依赖图能按拓扑序初始化包 |
| 92 | + /// (如 chain 包依赖 multig2p 时,multig2p 必须先于 chain 创建)。 |
| 93 | + static bool resolveModuleDependencies(std::vector<srt::dependency::ModuleMetadata> &compatibleModules) { |
| 94 | + srt::dependency::DependencyResolver resolver; |
| 95 | + return resolver.resolveAllDependencies(compatibleModules, {}); |
| 96 | + } |
| 97 | + |
89 | 98 | srt::core::Expected<void> Manager::initialize() { |
90 | 99 | auto &impl = *static_cast<PackageManager::Impl *>(_impl.get()); |
91 | 100 |
|
@@ -156,6 +165,10 @@ namespace srt::g2p { |
156 | 165 | "Ord-1: Default context has no compatible modules after Level check; " |
157 | 166 | "official G2P unavailable"); |
158 | 167 | } else { |
| 168 | + if (!resolveModuleDependencies(compatibleModules)) { |
| 169 | + return Error(ErrorCode::G2pDependencyError, |
| 170 | + "Ord-1: Failed to resolve module dependencies for default context"); |
| 171 | + } |
159 | 172 | auto &depGraph = impl.m_contextDependencyGraphs[srt::core::ContextKey("")]; |
160 | 173 | depGraph.clear(); |
161 | 174 | for (const auto &info : compatibleModules) |
|
0 commit comments