Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

results are in reverse alphabetical order #576

Closed
mmkal opened this issue Jan 31, 2024 · 6 comments
Closed

results are in reverse alphabetical order #576

mmkal opened this issue Jan 31, 2024 · 6 comments

Comments

@mmkal
Copy link
Contributor

mmkal commented Jan 31, 2024

Hi! It seems in v10, results are in reverse alphabetical order.

Repro: go to https://npm.runkit.com/glob and paste in:

var glob = require("glob")
var path = require('path')

console.log(glob.globSync('*/*.*', { cwd: path.join(__dirname, '..') }))

This was not the case in glob v8. Not sure about 9.

@isaacs
Copy link
Owner

isaacs commented Jan 31, 2024

They're not sorted at all, and the order is non deterministic, set by os latency. Do not depend on it.

@mmkal
Copy link
Contributor Author

mmkal commented Jan 31, 2024

That's good to know! They do seem to consistently be in reverse order though, for the cases I've tried. Do you think there's something that got changed recently that caused that? I'll make sure to add a .sort() wherever I'm accidentally depending on it, but I imagine there are others who will find the reverse order unexpected and might hit issues.

Failing that, would you accept a docs update pull request?

@1j01
Copy link

1j01 commented Mar 1, 2024

Version 9 removed sorting. To sort results just as version 8 did, use:

glob.sync(...).sort((a, b)=> a.localeCompare(b, 'en'))

@isaacs
Copy link
Owner

isaacs commented Mar 1, 2024

They do seem to consistently be in reverse order though, for the cases I've tried.

That is 100% a result of how your computer's file system chooses to return results. On a different operating system, file system, disk controller, ..., it could easily be returned in alphabetical order, in order of last access, entirely random, or any other arbitrary order.

Sort if you depend on it, don't depend on it if you're not sorting it yourself.

@isaacs
Copy link
Owner

isaacs commented Mar 1, 2024

And yes, doc patch welcome 🤗

@75lb
Copy link

75lb commented Aug 26, 2024

Version 9 removed sorting. To sort results just as version 8 did, use:

thanks for pointing this out.. IMO, it's better we do our own sorting - v8 assumed all users require American English sorting (as you highlighted) which results in incorrectly sorted output for non-Americans.. Russian speakers, for example..

$ node
> 'Р'.localeCompare('С', 'ru')
-1
> 'P'.localeCompare('C', 'en')
1

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

No branches or pull requests

4 participants