react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / mkdirp / index.js
80681 viewsvar path = require('path');1var fs = require('fs');2var _0777 = parseInt('0777', 8);34module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;56function mkdirP (p, opts, f, made) {7if (typeof opts === 'function') {8f = opts;9opts = {};10}11else if (!opts || typeof opts !== 'object') {12opts = { mode: opts };13}1415var mode = opts.mode;16var xfs = opts.fs || fs;1718if (mode === undefined) {19mode = _0777 & (~process.umask());20}21if (!made) made = null;2223var cb = f || function () {};24p = path.resolve(p);2526xfs.mkdir(p, mode, function (er) {27if (!er) {28made = made || p;29return cb(null, made);30}31switch (er.code) {32case 'ENOENT':33mkdirP(path.dirname(p), opts, function (er, made) {34if (er) cb(er, made);35else mkdirP(p, opts, cb, made);36});37break;3839// In the case of any other error, just see if there's a dir40// there already. If so, then hooray! If not, then something41// is borked.42default:43xfs.stat(p, function (er2, stat) {44// if the stat fails, then that's super weird.45// let the original error be the failure reason.46if (er2 || !stat.isDirectory()) cb(er, made)47else cb(null, made);48});49break;50}51});52}5354mkdirP.sync = function sync (p, opts, made) {55if (!opts || typeof opts !== 'object') {56opts = { mode: opts };57}5859var mode = opts.mode;60var xfs = opts.fs || fs;6162if (mode === undefined) {63mode = _0777 & (~process.umask());64}65if (!made) made = null;6667p = path.resolve(p);6869try {70xfs.mkdirSync(p, mode);71made = made || p;72}73catch (err0) {74switch (err0.code) {75case 'ENOENT' :76made = sync(path.dirname(p), opts, made);77sync(p, opts, made);78break;7980// In the case of any other error, just see if there's a dir81// there already. If so, then hooray! If not, then something82// is borked.83default:84var stat;85try {86stat = xfs.statSync(p);87}88catch (err1) {89throw err0;90}91if (!stat.isDirectory()) throw err0;92break;93}94}9596return made;97};9899100