import fs from 'node:fs/promises'; import path from 'node:path'; /** * Создаёт родительский каталог для файла. * На Windows `mkdir('E:\\')` даёт EPERM — корень диска пропускаем. */ export async function ensureParentDir(filePath: string): Promise { const dir = path.dirname(filePath); if (!dir || dir === '.') return; const root = path.parse(path.resolve(filePath)).root; if (root && path.resolve(dir) === path.resolve(root)) return; await fs.mkdir(dir, { recursive: true }); }