( fileList: ReadonlySet<string>, reasons: NodeFileTraceReasons, ignoreFn?: (file: string, parent?: string) => boolean )
| 937 | } |
| 938 | |
| 939 | export function getFilesMapFromReasons( |
| 940 | fileList: ReadonlySet<string>, |
| 941 | reasons: NodeFileTraceReasons, |
| 942 | ignoreFn?: (file: string, parent?: string) => boolean |
| 943 | ): ReadonlyMap<string, Set<string>> { |
| 944 | // this uses the reasons tree to collect files specific to a |
| 945 | // certain parent allowing us to not have to trace each parent |
| 946 | // separately |
| 947 | const parentFilesMap = new Map<string, Set<string>>(); |
| 948 | |
| 949 | function propagateToParents( |
| 950 | parents: Set<string>, |
| 951 | file: string, |
| 952 | seen = new Set<string>() |
| 953 | ) { |
| 954 | for (const parent of parents || []) { |
| 955 | if (!seen.has(parent)) { |
| 956 | seen.add(parent); |
| 957 | let parentFiles = parentFilesMap.get(parent); |
| 958 | |
| 959 | if (!parentFiles) { |
| 960 | parentFiles = new Set(); |
| 961 | parentFilesMap.set(parent, parentFiles); |
| 962 | } |
| 963 | |
| 964 | if (!ignoreFn?.(file, parent)) { |
| 965 | parentFiles.add(file); |
| 966 | } |
| 967 | const parentReason = reasons.get(parent); |
| 968 | |
| 969 | if (parentReason?.parents) { |
| 970 | propagateToParents(parentReason.parents, file, seen); |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | for (const file of fileList!) { |
| 977 | const reason = reasons!.get(file); |
| 978 | const isInitial = |
| 979 | reason?.type.length === 1 && reason.type.includes('initial'); |
| 980 | |
| 981 | if ( |
| 982 | !reason || |
| 983 | !reason.parents || |
| 984 | (isInitial && reason.parents.size === 0) |
| 985 | ) { |
| 986 | continue; |
| 987 | } |
| 988 | propagateToParents(reason.parents, file); |
| 989 | } |
| 990 | return parentFilesMap; |
| 991 | } |
| 992 | |
| 993 | export const collectTracedFiles = |
| 994 | ( |
no test coverage detected