The code in question is shown below the fs.readdirSync has recursive set to true which means it will go down through the folder structure, however the files map has code which will call itself if it sees a folder and so also navigating through the filesystem as well and so duplicating the effort and in some circumstances causes undefined errors in the response.
There is a bug in https://github.com/ForgeRock/fr-config-manager/blob/main/packages/fr-config-push/src/scripts/update-raw.js where the code is navigating the folder structure multiple times.
The code in question is shown below the fs.readdirSync has recursive set to true which means it will go down through the folder structure, however the files map has code which will call itself if it sees a folder and so also navigating through the filesystem as well and so duplicating the effort and in some circumstances causes undefined errors in the response.
`async function listFiles(dir) { const files = fs.readdirSync(dir, { withFileTypes: true, recursive: true });
const filesAndDirs = await Promise.all( files.map(async (file) => { const filePath = path.join(dir, file.name); if (file.isDirectory()) { return listFiles(filePath); // Recursively list files } else { return filePath; // Return file path } }) );
return filesAndDirs.flat(); } `
I fixed the issue locally by switching the true to false for recursive, i.e.
`async function listFiles(dir) { const files = fs.readdirSync(dir, { withFileTypes: true, recursive: false });
const filesAndDirs = await Promise.all( files.map(async (file) => { const filePath = path.join(dir, file.name); if (file.isDirectory()) { return listFiles(filePath); // Recursively list files } else { return filePath; // Return file path } }) );
return filesAndDirs.flat(); } `