From f26b1da1b5398bcfb9b71a018c68382b64f91bbb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 24 Feb 2013 17:15:46 -0800 Subject: [PATCH] Simplify build/mkdirp-sync.js. Former-commit-id: b49bbea9e565dbf1d23f601af74443b33fe9fc7d --- build/mkdirp-sync.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/build/mkdirp-sync.js b/build/mkdirp-sync.js index ae621743b..19e0f915d 100755 --- a/build/mkdirp-sync.js +++ b/build/mkdirp-sync.js @@ -12,35 +12,27 @@ /*--------------------------------------------------------------------------*/ /** - * Makes the given `path` directory, without throwing errors for existing + * Makes the given `dirname` directory, without throwing errors for existing * directories and making parent directories as needed. * * @param {String} dirname The path of the directory. - * @param {Number|String} mode The permission mode. + * @param {Number|String} [mode='0777'] The permission mode. */ function mkdirpSync(dirname, mode) { - var sep = path.sep, - type = typeof mode; + var sep = path.sep; // ensure relative paths are prefixed with `./` if (!RegExp('^\\.?' + sep).test(dirname)) { dirname = '.' + sep + dirname; } - if (!(type == 'number' || type == 'string')) { - mode = '0777'; - } - dirname.split(sep).reduce(function(currPath, segment, index) { - // skip leading separator of absolute paths - if (index === 0 && currPath === '') { - return sep; - } - segment = currPath + (currPath === sep ? segment : sep + segment); + dirname.split(sep).reduce(function(currPath, segment) { + currPath += sep + segment; try { - segment = fs.realpathSync(segment); + currPath = fs.realpathSync(currPath); } catch(e) { - fs.mkdirSync(segment, mode); + fs.mkdirSync(currPath, mode); } - return segment; + return currPath; }); }