UNPKG

apex-code-coverage-transformer

Version:

Transform Salesforce Apex code coverage JSONs into other formats accepted by SonarQube, GitHub, GitLab, Azure, Bitbucket, etc.

44 lines 1.56 kB
'use strict'; /* eslint-disable no-await-in-loop */ import { readdir, stat } from 'node:fs/promises'; import { join, relative } from 'node:path'; import { normalizePathToUnix } from './normalizePathToUnix.js'; export async function findFilePath(fileName, packageDirectories, repoRoot) { for (const directory of packageDirectories) { const result = await resolveFilePath(fileName, directory, repoRoot); if (result) { return normalizePathToUnix(result); } } return undefined; } async function resolveFilePath(fileName, dxDirectory, repoRoot) { const extensionsToTry = getExtensionsToTry(fileName); for (const name of extensionsToTry) { const absolutePath = await searchRecursively(name, dxDirectory); if (absolutePath) { return relative(repoRoot, absolutePath); } } return undefined; } function getExtensionsToTry(fileName) { return ['cls', 'trigger'].map((ext) => `${fileName}.${ext}`); } async function searchRecursively(fileName, directory) { const entries = await readdir(directory); for (const entry of entries) { const fullPath = join(directory, entry); const stats = await stat(fullPath); if (stats.isDirectory()) { const nestedResult = await searchRecursively(fileName, fullPath); if (nestedResult) return nestedResult; } else if (entry === fileName) { return fullPath; } } return undefined; } //# sourceMappingURL=findFilePath.js.map