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

Ordering of results #10

Open
arshaw opened this issue Aug 1, 2019 · 1 comment
Open

Ordering of results #10

arshaw opened this issue Aug 1, 2019 · 1 comment

Comments

@arshaw
Copy link

arshaw commented Aug 1, 2019

Hello! It seems as though the ordering of results is non-deterministic, right? This seems true to me, for two reasons:

It this the intended behavior? If so, would you mind mentioning something about it in the docs? Thanks for this lib!

@jonschlinkert
Copy link
Owner

jonschlinkert commented Jan 15, 2020

Hello! It seems as though the ordering of results is non-deterministic, right?

Directories are looped over by node-glob asynchronously, thus files may be returned in any order, depending on which directories finish first.

  • the nosort flag is set to true when asking glob to return results

That's only a default that may be overridden on options. We do this because node-glob sorts results by default, and we don't want glob to perform extra unnecessary operations.

the aggregate result of glob calls seems to be constructed in the order they are returned, which is unpredictable

files.sort()

Edit: I hope that last line didn't seem snarky without a comment, I was in a rush and should have taken more time. I just wanted to make the point that .sort() is all you need to do to sort the results. There will never be a time when files are deterministic in a realistic scenario -- even when directories are looped over synchronously, since files and folders change. However, if you're just looking for determinism for unit tests or something, you should be able to simulate that by sorting the returned array. I had considered adding this feature, but honestly all we'd do is files.sort(). If consensus is that we should do it anyway, for parity, I'm totally fine with that and would accept a PR.

Thanks for the issue.

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

2 participants