From e232d4627a91db604bbb67a6bd04afb71bbfb2e4 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 27 Apr 2021 11:31:26 +0100 Subject: [PATCH] Fix for Node Path instance not being sent to onEachFile and onEachDirectory callbacks The README says: "The callback function takes the directory item (has path, name, size, and extension) and an instance of [node path](https://nodejs.org/api/path.html) and an instance of [node FS.stats](https://nodejs.org/api/fs.html#fs_class_fs_stats)." However, the callbacks are not sent the Node Path instance but instead are sent the `path` variable. Changing from `path` to `PATH` fixes it to work as described in the README. --- lib/directory-tree.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/directory-tree.js b/lib/directory-tree.js index ae95d12..2e12beb 100644 --- a/lib/directory-tree.js +++ b/lib/directory-tree.js @@ -84,7 +84,7 @@ function directoryTree (path, options, onEachFile, onEachDirectory) { } if (onEachFile) { - onEachFile(item, path, stats); + onEachFile(item, PATH, stats); } } else if (stats.isDirectory()) { @@ -102,7 +102,7 @@ function directoryTree (path, options, onEachFile, onEachDirectory) { item.size = item.children.reduce((prev, cur) => prev + cur.size, 0); item.type = constants.DIRECTORY; if (onEachDirectory) { - onEachDirectory(item, path, stats); + onEachDirectory(item, PATH, stats); } } else { return null; // Or set item.size = 0 for devices, FIFO and sockets ?