readdir
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -107,3 +107,3 @@ | ||
fs.readdir(dir, function (err, contents) { | ||
if (err) deferred.reject(err); | ||
if (err) deferred_error(deferred, err, options); | ||
else if (!contents.length) { | ||
@@ -120,3 +120,3 @@ deferred.resolve(); | ||
if (err) deferred.reject(err); | ||
if (err) deferred_error(deferred, err, options); | ||
else if (isDirectory) { | ||
@@ -146,2 +146,11 @@ if(exports.INCLUDE_DIRECTORIES & options) { | ||
function deferred_error(deferred, error, options) { | ||
if (exports.IGNORE_ERRORS & options) { | ||
deferred.resolve(); | ||
} | ||
else { | ||
deferred.reject(error); | ||
} | ||
} | ||
/** | ||
@@ -212,3 +221,8 @@ * Changes the values in the supplied paths array to be absolute URIs | ||
var rootDir = basePath.replace(/\/$/, '') + '/'; | ||
return apply_filters(basePath, read_dir_sync(rootDir, [], rootDir.length, options), includeFilters, options); | ||
if (!fs.existsSync(rootDir)) { | ||
return []; | ||
} | ||
else { | ||
return apply_filters(basePath, read_dir_sync(rootDir, [], rootDir.length, options), includeFilters, options); | ||
} | ||
}; | ||
@@ -298,2 +312,9 @@ | ||
/** | ||
* Bitwise option for preventing errors reading directories from aborting the scan whenever possible - includes | ||
* incorrectly rooted relative symlinks and missing root directory. | ||
* @type {number} | ||
*/ | ||
exports.IGNORE_ERRORS = 64; | ||
}(typeof module == 'undefined' ? (window.ReadDir = {}) : module.exports)); |
{ | ||
"name": "readdir", | ||
"description": "Reads a directory and return results with the ability to use Ant style file match patterns ", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"author": "Steve King <steve@mydev.co>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -170,1 +170,24 @@ | ||
}()); | ||
(function() { | ||
var readdir = require('../lib/readdir.js'), | ||
read = readdir.read; | ||
read('./example_dir/missing', readdir.IGNORE_ERRORS, function (error, everyFile) { | ||
process.nextTick(function () { | ||
Assert.equal(error, null, 'Should not have thrown an error while scanning non-existent directory'); | ||
Assert.deepEqual(everyFile, [], 'No files given that the directory does not exist'); | ||
}); | ||
}); | ||
}()); | ||
(function() { | ||
var readdir = require('../lib/readdir.js'), | ||
read = readdir.readSync; | ||
Assert.deepEqual( | ||
read('./example_dir/missing', null, readdir.IGNORE_ERRORS), [], | ||
'No files given that the directory does not exist'); | ||
}()); |
19808
434