* @zh 加载所有启用的插件 * @en Load all enabled plugins
()
| 154 | * @en Load all enabled plugins |
| 155 | */ |
| 156 | async loadAll(): Promise<Map<string, PluginLoadInfo>> { |
| 157 | if (this._loading) { |
| 158 | throw new Error('Loading already in progress'); |
| 159 | } |
| 160 | |
| 161 | this._loading = true; |
| 162 | const start = Date.now(); |
| 163 | |
| 164 | try { |
| 165 | const enabled = this._config.plugins.filter(p => p.enabled); |
| 166 | |
| 167 | // 验证依赖 |
| 168 | const missing = this._validateDependencies(enabled); |
| 169 | for (const [id, deps] of missing) { |
| 170 | this._loaded.set(id, { |
| 171 | packageId: id, |
| 172 | state: 'missing', |
| 173 | missingDeps: deps, |
| 174 | error: `Missing: ${deps.join(', ')}` |
| 175 | }); |
| 176 | } |
| 177 | |
| 178 | // 过滤有效插件并排序 |
| 179 | const valid = enabled.filter(p => !missing.has(p.packageId)); |
| 180 | const sorted = this._sortByDependencies(valid); |
| 181 | |
| 182 | // 串行加载 |
| 183 | for (const plugin of sorted) { |
| 184 | await this._loadOne(plugin); |
| 185 | } |
| 186 | |
| 187 | const time = Date.now() - start; |
| 188 | const loadedCount = this.getLoaded().length; |
| 189 | logger.info(`Loaded ${loadedCount}/${enabled.length} plugins in ${time}ms`); |
| 190 | |
| 191 | return this._loaded; |
| 192 | } finally { |
| 193 | this._loading = false; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @zh 获取已加载插件 |
no test coverage detected