MCPcopy Create free account
hub / github.com/esengine/esengine / getAllDependencies

Function getAllDependencies

packages/runtime-core/src/utils/DependencyUtils.ts:412–442  ·  view source on GitHub ↗
(
    itemId: string,
    items: T[],
    options: { resolveId?: (id: string) => string } = {}
)

Source from the content-addressed store, hash-verified

410 * @returns @zh 所有依赖 ID 的集合 @en Set of all dependency IDs
411 */
412export function getAllDependencies<T extends IDependable>(
413 itemId: string,
414 items: T[],
415 options: { resolveId?: (id: string) => string } = {}
416): Set<string> {
417 const { resolveId = resolveDependencyId } = options;
418 const itemMap = new Map<string, T>();
419 for (const item of items) {
420 itemMap.set(item.id, item);
421 }
422
423 const allDeps = new Set<string>();
424 const visited = new Set<string>();
425
426 const collect = (id: string) => {
427 if (visited.has(id)) return;
428 visited.add(id);
429
430 const item = itemMap.get(id);
431 if (!item) return;
432
433 for (const dep of item.dependencies || []) {
434 const depId = resolveId(dep);
435 allDeps.add(depId);
436 collect(depId);
437 }
438 };
439
440 collect(itemId);
441 return allDeps;
442}
443
444/**
445 * @zh 获取依赖于指定项目的所有项目(反向依赖)

Callers

nothing calls this directly

Calls 2

collectFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected