How to use mkdirp

Comprehensive mkdirp code examples:

How to use mkdirp.mkdirp:

359
360
361
362
363
364
365
366
367
368
const dstFilename = path.resolve(dst, filename);
await rimraf(dstFilename);
// Apply index.node/index hack for iOS, if necessary:
if (platform === 'ios' && fs.lstatSync(srcFilename).isFile()) {
  const inside = path.parse(path.basename(dstFilename)).name;
  await mkdirp(dstFilename);
  fs.renameSync(
    path.resolve(srcFilename),
    path.resolve(dstFilename, inside),
  );

How to use mkdirp.sync:

15
16
17
18
19
20
21
22
23
24
// FIXME
process.setMaxListeners(0);

const maybeMkdirp = (dir) => {
  try {
    mkdirp.sync(dir);
  } catch (e) {
    if (e.code !== 'EEXIST') throw e;
  }
}