From 01190602dac64924fca2dae11912ffb560e636a0 Mon Sep 17 00:00:00 2001 From: domenic Date: Mon, 14 May 2012 19:27:13 -0400 Subject: [PATCH 1/2] Use `path.relative` instead of manual string replacement. Fixes Windows inconsistency (#26). --- lib/wrench.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wrench.js b/lib/wrench.js index 07386f8..00f4166 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -49,7 +49,7 @@ exports.readdirSyncRecursive = function(baseDir) { // convert absolute paths to relative var fileList = readdirSyncRecursive(baseDir).map(function(val){ - return val.replace(baseDir + '/', ''); + return _path.relative(baseDir, val); }); return fileList; @@ -106,7 +106,7 @@ exports.readdirRecursive = function(baseDir, fn) { fn(null, curFiles.map(function(val) { // convert absolute paths to relative - return val.replace(baseDir + '/', ''); + return _path.relative(baseDir, val); })); if (waitCount == 0) { From 5d1d96379b503a5600798b2a311eb89c1ab54a70 Mon Sep 17 00:00:00 2001 From: domenic Date: Mon, 14 May 2012 19:30:39 -0400 Subject: [PATCH 2/2] Fixing tests to use `path.join` for Windows compat. Now they pass on Windows. --- tests/readdir.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/readdir.js b/tests/readdir.js index b2d14f0..773e717 100644 --- a/tests/readdir.js +++ b/tests/readdir.js @@ -9,10 +9,10 @@ function checkResult(test, files) { var check = [ 'bar.txt', 'foo', - 'foo/bar', - 'foo/dolor.md', - 'foo/lorem.txt', - 'foo/bar/ipsum.js' + path.join('foo', 'bar'), + path.join('foo', 'dolor.md'), + path.join('foo', 'lorem.txt'), + path.join('foo', 'bar', 'ipsum.js') ]; test.equals(files.length, check.length, 'number of paths is correct'); @@ -26,7 +26,7 @@ function checkResult(test, files) { module.exports = testCase({ test_readdirSyncRecursive: function(test) { - var dir = __dirname + '/readdir'; + var dir = path.join(__dirname, 'readdir'); test.ok(path.existsSync(dir), 'Folders should exist'); @@ -36,7 +36,7 @@ module.exports = testCase({ }, test_readdirRecursive: function(test) { - var dir = __dirname + '/readdir'; + var dir = path.join(__dirname, 'readdir'); test.ok(path.existsSync(dir), 'Folders should exist');