Skip to content

Commit 6ad7dec

Browse files
committed
fixes
1 parent c9a93a2 commit 6ad7dec

4 files changed

Lines changed: 81 additions & 44 deletions

File tree

CHANGELOG.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# path-reader - Change Log
22
All notable changes to this project will be documented here.
33

4+
## [1.0.6] - 2017-10-13
5+
- empty folders containing empty items reads are now empty array instead of undefined
6+
47
## [1.0.5] - 2017-10-13
58
### Fixed
69
- empty folder reads are now empty array instead of undefined

lib/paths.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ exports.files = function files(dir, type, callback, options) {
4747

4848
options = options || {}
4949

50-
var pending,
51-
results = {
52-
files: [],
53-
dirs: []
54-
};
50+
var pending
51+
var results = {
52+
files: [],
53+
dirs: []
54+
};
5555

5656
var done = function() {
5757
if(type==='combine'){
@@ -64,7 +64,6 @@ exports.files = function files(dir, type, callback, options) {
6464

6565
if(options.sync)return;
6666

67-
6867
callback(null, results);
6968
};
7069

@@ -108,10 +107,14 @@ exports.files = function files(dir, type, callback, options) {
108107
if(type === 'combine'){
109108
results.files = results.files.concat(res);
110109
}else if (type === 'all') {
111-
results.files = results.files.concat(res.files);
110+
if( res.files ){//dont add things that are not there
111+
results.files = results.files.concat(res.files);
112+
}
112113
results.dirs = results.dirs.concat(res.dirs);
113114
} else if (type === 'file') {
114-
results.files = results.files.concat(res.files);
115+
if( res.files ){//dont add things that are not there
116+
results.files = results.files.concat(res.files);
117+
}
115118
} else {
116119
results.dirs = results.dirs.concat(res.dirs);
117120
}
@@ -236,7 +239,6 @@ exports.files = function files(dir, type, callback, options) {
236239
* });
237240
*/
238241
exports.paths = function paths(dir, combine, callback) {
239-
240242
var type;
241243

242244
if (typeof combine === 'function') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "path-reader",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "asynchronous file and directory operations for Node.js",
55
"main": "index",
66
"homepage": "https://github.com/ackerapple",

test/test.js

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
1-
var path = require('path'),
2-
should = require('should'),
3-
dir = require('..'),
4-
fixturesDir = path.join(__dirname, 'fixtures'),
5-
tdir = path.join(fixturesDir, 'testdir'),
6-
tdir2 = path.join(fixturesDir, 'testdir2'),
7-
tdir3 = path.join(fixturesDir, 'testdir3'),
8-
tdir4 = path.join(fixturesDir, 'testdir4'),
9-
tdir5 = path.join(fixturesDir, 'testdir5'),
10-
tdir6 = path.join(fixturesDir, 'testdir6'),
11-
assert = require('assert'),
12-
isWin = require('os').type()=='Windows_NT',
13-
winIt = isWin ? it.skip : it//skip all symlink based testing
14-
15-
//create empty folder
16-
require('fs').mkdirSync( tdir6 )
1+
var fs = require('fs')
2+
var path = require('path')
3+
var should = require('should')
4+
var dir = require('..')
5+
var fixturesDir = path.join(__dirname, 'fixtures')
6+
7+
var tdir = path.join(fixturesDir, 'testdir')
8+
var tdir2 = path.join(fixturesDir, 'testdir2')
9+
var tdir3 = path.join(fixturesDir, 'testdir3')
10+
var tdir4 = path.join(fixturesDir, 'testdir4')
11+
var tdir5 = path.join(fixturesDir, 'testdir5')
12+
//empty dirs that may not exist
13+
var tdir6 = path.join(fixturesDir, 'testdir6')
14+
var tdir7 = path.join(fixturesDir, 'testdir7')
15+
var tdir8 = path.join(fixturesDir, 'testdir7', 'testdir8')
16+
17+
var assert = require('assert')
18+
var isWin = require('os').type()=='Windows_NT'
19+
var winIt = isWin ? it.skip : it//skip all symlink based testing
20+
21+
//param empty folder
22+
function paramDir(pathTo){
23+
try{
24+
fs.mkdirSync( pathTo )
25+
}catch(e){
26+
if( !e.code || e.code!='EEXIST' ){
27+
throw e
28+
}
29+
}
30+
}
31+
32+
paramDir( tdir6 )
33+
paramDir( tdir7 )
34+
paramDir( tdir8 )
1735

1836
describe('readfiles method', function() {
1937

@@ -1266,28 +1284,42 @@ describe("files method", function() {
12661284
relFile.should.eql(cmp)//This test does not pass on all Systems
12671285
});
12681286

1269-
it("empty-folder", function() {
1270-
var files = dir.files(tdir6,'file', function(){}, {sync:true, excludeHidden:true});
1271-
assert.equal(files.length, 0)
1272-
});
1273-
1274-
it("empty-folder-promise", function(done) {
1275-
dir.promiseFiles(tdir6,'file', {excludeHidden:true})
1276-
.then(function(files){
1277-
assert.equal(files.length, 0)
1287+
describe('empty-folders',function(){
1288+
it("empty-folder", function() {
1289+
var files = dir.files(tdir6,'file', function(){}, {sync:true, excludeHidden:true});
1290+
assert.equal(files.length, 0)
12781291
})
1279-
.then(done).catch(done)
1280-
});
12811292

1282-
it("empty-folder-callback", function(done) {
1283-
dir.files(tdir6,'file', function(err,files){
1284-
if(err)return done(err)
1293+
it("folder-with-folder-only", function() {
1294+
var files = dir.files(tdir7,'file', function(){}, {sync:true, excludeHidden:true});
12851295
assert.equal(files.length, 0)
1286-
done()
1287-
}, {excludeHidden:true})
1288-
});
1289-
});
1296+
})
1297+
1298+
it("folder-with-folder-only-promise", function(done) {
1299+
dir.promiseFiles(tdir7,'file', {excludeHidden:true})
1300+
.then(function(files){
1301+
assert.equal(files.length, 0)
1302+
})
1303+
.then(done).catch(done)
1304+
})
1305+
1306+
it("empty-folder-promise", function(done) {
1307+
dir.promiseFiles(tdir6,'file', {excludeHidden:true})
1308+
.then(function(files){
1309+
assert.equal(files.length, 0)
1310+
})
1311+
.then(done).catch(done)
1312+
})
12901313

1314+
it("empty-folder-callback", function(done) {
1315+
dir.files(tdir6,'file', function(err,files){
1316+
if(err)return done(err)
1317+
assert.equal(files.length, 0)
1318+
done()
1319+
}, {excludeHidden:true})
1320+
})
1321+
})
1322+
})
12911323

12921324
describe('subdirs method', function() {
12931325
it('should pass an array of the subdir paths of every subdir in a directory (recursive) to a callback', function(done) {

0 commit comments

Comments
 (0)