You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add --du flag, fix -s to match Linux tree behavior, and clean up codebase
- Add --du flag for recursive directory size accumulation (like du -c)
- Fix -s/sizes to use stat.size directly instead of recursive sums,
matching Linux tree -s behavior
- Remove dirsOnly check from isExcluded (already handled by
filterAndOrderContents)
- Add JSDoc comments documenting assumptions to all functions
- Fix terminology inconsistencies across CLI, README, and source
- Extract resolveOptions() to deduplicate option merging logic
- Unify callback parameter names in filterAndOrderContents to 'entry'
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|`allFiles`|`false`|`boolean`| All filesare printed. By default, tree does not print hidden files (those beginning with a dot).|
149
+
|`allFiles`|`false`|`boolean`| All files, including hidden files, are printed. |
148
150
|`date`|`false`|`boolean`| Show last modification time for each entry. |
149
151
|`dirsFirst`|`false`|`boolean`| List directories before files. |
150
152
|`fullPath`|`false`|`boolean`| Print the full path prefix for each file. |
@@ -153,11 +155,12 @@ console.log(result);
153
155
|`quote`|`false`|`boolean`| Quote filenames in double quotes. |
154
156
|`prune`|`false`|`boolean`| Remove empty directories from output. |
155
157
|`dirsOnly`|`false`|`boolean`| List directories only. |
156
-
|`sizes`|`false`|`boolean`| Show filesizes as well. |
158
+
|`sizes`|`false`|`boolean`| Print the size of each file in bytes along with the name. |
159
+
|`du`|`false`|`boolean`| For each directory, report its size as the accumulation of sizes of all its files and sub-directories. Implies `sizes`. |
157
160
|`exclude`|`[]`|`RegExp[]`| An array of regex to test each filename against. Matching files will be excluded and matching directories will not be traversed into. To exclude a directory's contents while still showing the directory itself, use a regex that matches the path with a trailing slash (e.g., `/node_modules\//`). |
158
161
|`maxDepth`|`Number.POSITIVE_INFINITY`|`number`| Max display depth of the directory tree. |
159
162
|`reverse`|`false`|`boolean`| Sort the output in reverse alphabetic order. |
160
-
|`trailingSlash`|`false`|`boolean`|Appends a trailing slash behind directories. |
163
+
|`trailingSlash`|`false`|`boolean`|Append a `/` for directories.|
161
164
|`lineAscii`|`false`|`boolean`| Turn on ASCII line graphics. |
162
165
|`filesFirst`|`false`|`boolean`| List files before directories. |
Copy file name to clipboardExpand all lines: TODO.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ Track progress of implementing Linux `tree` options in tree-node-cli.
59
59
## Code Improvements
60
60
61
61
-[x]**Filter before stat** — `statEntries` stats all entries including hidden files that will be filtered out when `allFiles: false`. Filter hidden files before stat'ing to avoid unnecessary syscalls.
62
-
-[]**Match Linux `tree -s` size behavior** — `computeSizes` recursively sums file sizes into parent directories, but Linux `tree -s` shows each entry's own `stat.size` (inode size for directories, not recursive sum). Remove `computeSizes` and use`stat.size` directly.
62
+
-[x]**Match Linux `tree -s` size behavior** — `computeSizes` recursively sums file sizes into parent directories, but Linux `tree -s` shows each entry's own `stat.size` (inode size for directories, not recursive sum). `-s` now uses`stat.size` directly; recursive sums moved to new `--du` flag.
63
63
-[x]**Merge `EXCLUDED_PATTERNS` into exclude** — The hardcoded `.DS_Store` pattern is checked in a separate loop for every entry. Merge it into the user's `exclude` array at initialization to simplify `isExcluded`.
64
64
-[x]**Clarify `dirsOnly` filtering** — `dirsOnly` is checked in both `isExcluded` (skips files early) and `filterAndOrderContents` (filters file entries). The `isExcluded` check is a performance optimization that avoids stat'ing files, but the dual responsibility could be clearer.
65
65
-[x]**Avoid mutating input arrays** — `sortContents` calls `contents.sort()` which mutates the caller's array in place. Using `[...contents].sort(...)` would be safer, though not currently a bug since callers don't reuse the array.
0 commit comments