Comparing version 0.0.3 to 0.1.0
@@ -0,1 +1,8 @@ | ||
0.1.0 / 2016-04-06 | ||
================== | ||
* es6 update | ||
* change to return all created paths | ||
* dependencies update | ||
0.0.1 / 2016-02-20 | ||
@@ -2,0 +9,0 @@ ================== |
@@ -9,3 +9,3 @@ /** | ||
* @createdAt Created at 18-02-2016. | ||
* @version 0.0.1 | ||
* @version 0.0.2 | ||
*/ | ||
@@ -16,9 +16,6 @@ | ||
var nodePath = require("path"), | ||
nodeUtil = require("util"), | ||
mkdirUtil = require("./util"), | ||
isWindows; | ||
const nodePath = require("path"); | ||
const mkdirUtil = require("./util"); | ||
const isWindows = /^win/.test(process.platform); | ||
isWindows = /^win/.test(process.platform); | ||
function noop() { | ||
@@ -41,5 +38,5 @@ } | ||
function mkdirp(path, opt, callback) { | ||
var options, paths, callbackCalled, size, umask, cwd; | ||
let options, paths, callbackCalled, size, umask, cwd, done = []; | ||
if (nodeUtil.isFunction(opt)) { | ||
if (typeof opt === "function") { | ||
callback = opt; | ||
@@ -59,3 +56,3 @@ opt = {}; | ||
paths.some(function(p) { | ||
paths.some((p) => { | ||
p = nodePath.resolve(cwd, p); | ||
@@ -65,3 +62,3 @@ if (callbackCalled) { | ||
} | ||
mkdirp_(p, options, function(err, m) { | ||
mkdirp_(p, options, (err, m) => { | ||
if (err) { | ||
@@ -72,6 +69,7 @@ callbackCalled = true; | ||
} | ||
done.push(m); | ||
if (!--size && !callbackCalled) { | ||
callbackCalled = true; | ||
process.umask(umask); | ||
return callback(null, m); | ||
return callback(null, done.length > 1 ? done : done[0]); | ||
} | ||
@@ -83,11 +81,10 @@ }); | ||
function mkdirp_(path, options, callback) { | ||
options.fs.mkdir(path, options.mode, function(err) { | ||
var parent; | ||
options.fs.mkdir(path, options.mode, (err)=> { | ||
if (err) { | ||
if (err.code !== "ENOENT" && err.code !== "EEXIST") { | ||
return options.fs.stat(path, function(errStat, stat) { | ||
return options.fs.stat(path, (errStat, stat) => { | ||
return callback((errStat || !stat.isDirectory()) ? err : null, errStat ? null : path); | ||
}); | ||
} else if (err.code === "EEXIST") { | ||
return options.fs.stat(path, function(errStat, stat) { | ||
return options.fs.stat(path, (errStat, stat)=> { | ||
return callback((errStat || !stat.isDirectory()) ? err : null, errStat ? null : path); | ||
@@ -101,3 +98,3 @@ }); | ||
//ENOENT | ||
parent = nodePath.dirname(path); | ||
const parent = nodePath.dirname(path); | ||
if (parent === path || /\0/.test(path)) { | ||
@@ -107,3 +104,3 @@ return callback(err); | ||
if ((/"/.test(path) || /\:\\.*\\.*:.*\\/.test(path)) && isWindows) { | ||
var e = new Error("Invalid character found in path."); | ||
let e = new Error("Invalid character found in path."); | ||
e.code = "EINVALID"; | ||
@@ -113,7 +110,7 @@ return callback(e); | ||
mkdirp_(parent, options, function(errParent) { | ||
mkdirp_(parent, options, (errParent) => { | ||
if (errParent) { | ||
return callback(errParent); | ||
} | ||
options.fs.mkdir(path, options.mode, function(errPath) { | ||
options.fs.mkdir(path, options.mode, (errPath) => { | ||
//Ignore EEXIST error in asynchronous calls to mkdirp | ||
@@ -120,0 +117,0 @@ if (errPath && errPath.code !== "EEXIST") { |
@@ -9,3 +9,3 @@ /** | ||
* @createdAt Created at 18-02-2016. | ||
* @version 0.0.1 | ||
* @version 0.0.2 | ||
*/ | ||
@@ -15,9 +15,6 @@ | ||
var nodePath = require("path"), | ||
mkdirUtil = require("./util"), | ||
isWindows; | ||
const nodePath = require("path"); | ||
const mkdirUtil = require("./util"); | ||
const isWindows = /^win/.test(process.platform); | ||
isWindows = /^win/.test(process.platform); | ||
/** | ||
@@ -35,3 +32,3 @@ * Automatically create directories and sub-directories (mkdir -p) | ||
function mkdirpSync(path, opt) { | ||
var options, paths, umask, p; | ||
let options, paths, done=[]; | ||
@@ -41,8 +38,8 @@ options = mkdirUtil.getOptions(opt); | ||
umask = process.umask(); | ||
const umask = process.umask(); | ||
process.umask(0); | ||
try { | ||
for (var i = 0; i < paths.length; i++) { | ||
p = mkdirpSync_(paths[i], options); | ||
while (paths.length) { | ||
done.push(mkdirpSync_(paths.shift(), options)); | ||
} | ||
@@ -52,8 +49,8 @@ } finally { | ||
} | ||
return p || null; | ||
done = done.filter(d=>!!d); | ||
return done.length > 1 ? done : done[0]; | ||
} | ||
function mkdirpSync_(path, options) { | ||
var stat, stack = [], p, parent; | ||
let stack = []; | ||
@@ -63,3 +60,3 @@ stack.push(path); | ||
do { | ||
p = stack.pop(); | ||
const p = stack.pop(); | ||
try { | ||
@@ -71,3 +68,3 @@ options.fs.mkdirSync(p, options.mode); | ||
} else if (err.code === "ENOENT") { | ||
parent = nodePath.dirname(p); | ||
const parent = nodePath.dirname(p); | ||
if (parent === p || /\0/.test(p)) { | ||
@@ -77,3 +74,3 @@ throw err; | ||
if ((/"/.test(p) || /\:\\.*\\.*:.*\\/.test(p)) && isWindows) { | ||
var e = new Error("Invalid character found in path."); | ||
let e = new Error("Invalid character found in path."); | ||
e.code = "EINVALID"; | ||
@@ -85,2 +82,3 @@ throw e; | ||
} else if (err.code === "EEXIST") { | ||
let stat; | ||
try { | ||
@@ -95,3 +93,3 @@ stat = options.fs.statSync(p); | ||
} else { | ||
return null; | ||
return p; | ||
} | ||
@@ -98,0 +96,0 @@ } |
@@ -9,11 +9,12 @@ /** | ||
* @createdAt Created at 18-02-2016. | ||
* @version 0.0.1 | ||
* @version 0.0.2 | ||
*/ | ||
var nodePath = require("path"), | ||
nodeUtil = require("util"), | ||
enFs = require("enfspatch"), | ||
braceExpansion = require("brace-expansion"); | ||
"use strict"; | ||
const nodePath = require("path"); | ||
const enFs = require("enfspatch"); | ||
const braceExpansion = require("brace-expansion"); | ||
function inspectCurlyBraces(path) { | ||
@@ -25,6 +26,6 @@ return braceExpansion(path); | ||
function getOptions(opt) { | ||
var options = {}; | ||
let options = {}; | ||
if (opt) { | ||
if (!nodeUtil.isObject(opt)) { | ||
if (!isObject(opt)) { | ||
options = {mode: opt}; | ||
@@ -36,3 +37,3 @@ } else { | ||
options.fs = options.fs || enFs; | ||
options.mode = options.mode ? nodeUtil.isString(options.mode) ? parseInt(options.mode, 8) : options.mode : parseInt("0777", 8); | ||
options.mode = options.mode ? isString(options.mode) ? parseInt(options.mode, 8) : options.mode : parseInt("0777", 8); | ||
@@ -43,5 +44,5 @@ return options; | ||
function getPaths(originalPath) { | ||
var path, paths = []; | ||
let paths = []; | ||
path = nodeUtil.isArray(originalPath) ? originalPath : [originalPath]; | ||
const path = isArray(originalPath) ? originalPath : [originalPath]; | ||
@@ -70,1 +71,15 @@ path.forEach(function(p) { | ||
}; | ||
function kindOf(arg) { | ||
return arg === null ? "null" : arg === undefined ? "undefined" : /^\[object (.*)\]$/.exec(Object.prototype.toString.call(arg))[1].toLowerCase(); | ||
} | ||
function isObject(arg) { | ||
return arg !== null && arg !== undefined && "object" === kindOf(arg); | ||
} | ||
function isString(arg) { | ||
return "string" === kindOf(arg); | ||
} | ||
function isArray(arg) { | ||
return Array.isArray(arg); | ||
} |
{ | ||
"name": "enfsmkdirp", | ||
"version": "0.0.3", | ||
"description": "mkdir -p for node", | ||
"version": "0.1.0", | ||
"description": "mkdir -p for node fs module", | ||
"license": "CC-BY-4.0", | ||
@@ -31,11 +31,11 @@ "author": { | ||
"brace-expansion": "1.1.3", | ||
"enfspatch": "0.0" | ||
"enfspatch": "0.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "2.2.0", | ||
"eslint-plugin-mocha": "2.0.0", | ||
"eslint": "2.7.0", | ||
"eslint-plugin-mocha": "2.1.0", | ||
"mocha": "2.4.5", | ||
"should": "8.2.2", | ||
"should": "8.3.0", | ||
"rimraf": "2.5.2", | ||
"mock-fs": "3.7.0" | ||
"mock-fs": "3.8.0" | ||
}, | ||
@@ -42,0 +42,0 @@ "keywords": [ |
14305
274
+ Addedenfsaddins@0.1.0(transitive)
+ Addedenfspatch@0.1.0(transitive)
- Removedenfsaddins@0.0.2(transitive)
- Removedenfspatch@0.0.8(transitive)
Updatedenfspatch@0.1