@comyata/fe
Version:
Execute YAML and JSON files like programs and get clean data to work with as result.
25 lines • 927 B
JavaScript
import jsonpointer from 'json-pointer';
export const usagesToObject = fileComputeStats => {
if (!fileComputeStats.usages?.size) return null;
const usages = {};
for (const [file, nodes] of fileComputeStats.usages.entries()) {
usages[file.fileId] = Array.from(nodes).map(node => jsonpointer.compile(node.path));
}
return usages;
};
export const usagesToDependencies = (fileComputeStats, collectedUsages = {}) => {
const fileUsages = usagesToObject(fileComputeStats);
if (fileUsages) {
collectedUsages[fileComputeStats.file] = fileUsages;
}
const statsList = fileComputeStats.stats.slice(0);
while (statsList.length) {
const statsEntry = statsList.shift();
if (statsEntry.step === 'computeFile') {
collectedUsages = usagesToDependencies(statsEntry, collectedUsages);
} else if ('stats' in statsEntry) {
statsList.push(...statsEntry.stats);
}
}
return collectedUsages;
};