Skip to content

feat(ls): sort entries by modification time with -t - #1301

Open
Haasini-kudala wants to merge 1 commit into
shelljs:mainfrom
Haasini-kudala:codex/ls-modification-time-sort
Open

Haasini-kudala wants to merge 1 commit into
shelljs:mainfrom
Haasini-kudala:codex/ls-modification-time-sort

Conversation

@Haasini-kudala

Copy link
Copy Markdown

Fixes #1297.

Add ls('-t', ...) to return entries in descending modification-time order, with names breaking ties. This also works with explicit paths, globs, -l, -d, -A, and -L. With -R, the full returned list is sorted, as documented in the source and regenerated README.

Collect timestamps alongside each entry using its actual path, so sorting also works when different directories contain the same relative filename. Use mtimeMs to retain sub-millisecond precision, and keep the existing output types and ordering when -t is absent.

Added 10 regression tests covering these combinations, ties, timestamp precision, and symlinks. The initial nine cases failed before the implementation because -t was unrecognized.

Validation on macOS with Node 24.22.3:

  • npm run test-with-coverage: 667 passed, 6 existing skips.
  • npm run lint: passed.
  • npm run check-node-support: passed.
  • npm run gendocs: regenerated the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: ls -t option

1 participant