When generating files/metadata, make output deterministic and cross-platform by normalizing both paths and text line endings, and by keeping shared formatting rules/filters centralized.
Rules
path.sep to /).\n, then convert to os.EOL (or keep \n consistently if the consumer expects it).Example
import os from 'node:os';
import path from 'node:path';
function normalizeForCsv(relativePath) {
return relativePath.split(path.sep).join('/');
}
async function writeTextFileNormalized(fs, filePath, content) {
// Build with explicit \n, then adapt to platform
const platformContent = os.EOL === '\n' ? content : content.replace(/\r?\n/g, os.EOL);
await fs.writeFile(filePath, platformContent, 'utf8');
}