Comparing version 0.4.2 to 0.5.0
45
index.js
@@ -6,13 +6,23 @@ var path = require('path'); | ||
function mkdirP (p, mode, f, made) { | ||
if (typeof mode === 'function' || mode === undefined) { | ||
f = mode; | ||
function mkdirP (p, opts, f, made) { | ||
if (typeof opts === 'function') { | ||
f = opts; | ||
opts = {}; | ||
} | ||
else if (!opts || typeof opts !== 'object') { | ||
opts = { mode: opts }; | ||
} | ||
var mode = opts.mode; | ||
var xfs = opts.fs || fs; | ||
if (mode === undefined) { | ||
mode = 0777 & (~process.umask()); | ||
} | ||
if (!made) made = null; | ||
var cb = f || function () {}; | ||
p = path.resolve(p); | ||
fs.mkdir(p, mode, function (er) { | ||
xfs.mkdir(p, mode, function (er) { | ||
if (!er) { | ||
@@ -24,5 +34,5 @@ made = made || p; | ||
case 'ENOENT': | ||
mkdirP(path.dirname(p), mode, function (er, made) { | ||
mkdirP(path.dirname(p), opts, function (er, made) { | ||
if (er) cb(er, made); | ||
else mkdirP(p, mode, cb, made); | ||
else mkdirP(p, opts, cb, made); | ||
}); | ||
@@ -35,3 +45,3 @@ break; | ||
default: | ||
fs.stat(p, function (er2, stat) { | ||
xfs.stat(p, function (er2, stat) { | ||
// if the stat fails, then that's super weird. | ||
@@ -47,3 +57,10 @@ // let the original error be the failure reason. | ||
mkdirP.sync = function sync (p, mode, made) { | ||
mkdirP.sync = function sync (p, opts, made) { | ||
if (!opts || typeof opts !== 'object') { | ||
opts = { mode: opts }; | ||
} | ||
var mode = opts.mode; | ||
var xfs = opts.fs || fs; | ||
if (mode === undefined) { | ||
@@ -57,3 +74,3 @@ mode = 0777 & (~process.umask()); | ||
try { | ||
fs.mkdirSync(p, mode); | ||
xfs.mkdirSync(p, mode); | ||
made = made || p; | ||
@@ -64,4 +81,4 @@ } | ||
case 'ENOENT' : | ||
made = sync(path.dirname(p), mode, made); | ||
sync(p, mode, made); | ||
made = sync(path.dirname(p), opts, made); | ||
sync(p, opts, made); | ||
break; | ||
@@ -75,3 +92,3 @@ | ||
try { | ||
stat = fs.statSync(p); | ||
stat = xfs.statSync(p); | ||
} | ||
@@ -78,0 +95,0 @@ catch (err1) { |
{ | ||
"name" : "mkdirp", | ||
"description" : "Recursively mkdir, like `mkdir -p`", | ||
"version" : "0.4.2", | ||
"author" : "James Halliday <mail@substack.net> (http://substack.net)", | ||
"main" : "./index", | ||
"keywords" : [ | ||
"mkdir", | ||
"directory" | ||
], | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "https://github.com/substack/node-mkdirp.git" | ||
}, | ||
"scripts" : { | ||
"test" : "tap test/*.js" | ||
}, | ||
"dependencies": { | ||
"minimist": "0.0.8" | ||
}, | ||
"devDependencies" : { | ||
"tap" : "~0.4.0" | ||
}, | ||
"bin": "bin/cmd.js", | ||
"license" : "MIT" | ||
"name": "mkdirp", | ||
"description": "Recursively mkdir, like `mkdir -p`", | ||
"version": "0.5.0", | ||
"author": "James Halliday <mail@substack.net> (http://substack.net)", | ||
"main": "./index", | ||
"keywords": [ | ||
"mkdir", | ||
"directory" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/substack/node-mkdirp.git" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
}, | ||
"dependencies": { | ||
"minimist": "0.0.8" | ||
}, | ||
"devDependencies": { | ||
"tap": "~0.4.0", | ||
"mock-fs": "~2.2.0" | ||
}, | ||
"bin": "bin/cmd.js", | ||
"license": "MIT" | ||
} |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('woo', function (t) { | ||
t.plan(2); | ||
t.plan(5); | ||
var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
@@ -15,12 +16,9 @@ var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
mkdirp(file, 0755, function (err) { | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
t.ifError(err); | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}) | ||
@@ -27,0 +25,0 @@ }) |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('sync perm', function (t) { | ||
t.plan(2); | ||
t.plan(4); | ||
var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json'; | ||
mkdirp.sync(file, 0755); | ||
path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
}) | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}); | ||
}); | ||
@@ -25,16 +23,13 @@ }); | ||
test('sync root perm', function (t) { | ||
t.plan(1); | ||
t.plan(3); | ||
var file = '/tmp'; | ||
mkdirp.sync(file, 0755); | ||
path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}) | ||
}); | ||
}); |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('async perm', function (t) { | ||
t.plan(2); | ||
t.plan(5); | ||
var file = '/tmp/' + (Math.random() * (1<<30)).toString(16); | ||
mkdirp(file, 0755, function (err) { | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
t.ifError(err); | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}) | ||
@@ -22,0 +20,0 @@ }) |
var mkdirp = require('../').mkdirp; | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('race', function (t) { | ||
t.plan(4); | ||
t.plan(6); | ||
var ps = [ '', 'tmp' ]; | ||
@@ -27,13 +28,11 @@ | ||
mkdirp(file, 0755, function (err) { | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
if (cb) cb(); | ||
} | ||
}) | ||
t.ifError(err); | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
if (cb) cb(); | ||
}); | ||
}) | ||
@@ -40,0 +39,0 @@ }); |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('rel', function (t) { | ||
t.plan(2); | ||
t.plan(5); | ||
var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
@@ -18,13 +19,10 @@ var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
mkdirp(file, 0755, function (err) { | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
process.chdir(cwd); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
t.ifError(err); | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
process.chdir(cwd); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}) | ||
@@ -31,0 +29,0 @@ }) |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('sync', function (t) { | ||
t.plan(2); | ||
t.plan(4); | ||
var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
@@ -21,13 +22,10 @@ var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, 0755); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}); | ||
}); | ||
}); |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('umask sync modes', function (t) { | ||
t.plan(2); | ||
t.plan(4); | ||
var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
@@ -21,13 +22,10 @@ var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, (0777 & (~process.umask()))); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, (0777 & (~process.umask()))); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}); | ||
}); | ||
}); |
var mkdirp = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exists = fs.exists || path.exists; | ||
var test = require('tap').test; | ||
test('implicit mode from umask', function (t) { | ||
t.plan(2); | ||
t.plan(5); | ||
var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
@@ -15,15 +16,12 @@ var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); | ||
mkdirp(file, function (err) { | ||
if (err) t.fail(err); | ||
else path.exists(file, function (ex) { | ||
if (!ex) t.fail('file not created') | ||
else fs.stat(file, function (err, stat) { | ||
if (err) t.fail(err) | ||
else { | ||
t.equal(stat.mode & 0777, 0777 & (~process.umask())); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
t.end(); | ||
} | ||
}) | ||
t.ifError(err); | ||
exists(file, function (ex) { | ||
t.ok(ex, 'file created'); | ||
fs.stat(file, function (err, stat) { | ||
t.ifError(err); | ||
t.equal(stat.mode & 0777, 0777 & (~process.umask())); | ||
t.ok(stat.isDirectory(), 'target not a directory'); | ||
}); | ||
}) | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20426
24
495
101
2