import * as fs from 'fs/promises'; import * as p from 'path'; export const mkdirp = (path: string) => { const pathFragments = path.replaceAll('\\', '/').split('/'); const directoriesToCheck = pathFragments.reduce( (theDirectories, fragment, i) => [ ...theDirectories, theDirectories.length > 0 ? p.join(theDirectories[i - 1], fragment) : fragment, ], [] as string[], ) return Promise.allSettled(directoriesToCheck.map((d) => fs.mkdir(d))); }