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

Sort Files with 'glob.sync' #372

Closed
devalbm opened this issue Jul 3, 2018 · 4 comments
Closed

Sort Files with 'glob.sync' #372

devalbm opened this issue Jul 3, 2018 · 4 comments

Comments

@devalbm
Copy link

devalbm commented Jul 3, 2018

I have some problems to sort the files. Glob.sync order the files alphabetically. Is there any solution to order my way?

   /app
     |__ app.js
     |__ main.js

I have:
glob.sync("./app/*(main|app).js")

I want to include 'main.js' first and later 'app.js', but actually, sync does the opposite. The first file that "match" is app.js due to the alphabetical order.
Any Solution?
Thanks in advance.

@tarwich
Copy link

tarwich commented Jun 3, 2019

If at all possible, I would expect glob to return files in the order specified in patterns. This is the way that *nix glob works, and I use it for precedence.

Edit: It doesn't work this way. I'm not trying to answer OP, but rather agreeing. I'm currently working on a precedence filter for the results in my project -- I'm not sure how to fix it in this library.

@romellem
Copy link

FYI, just to add some more detail here, the docs show that the matches are sorted unless the nosort flag is set.

The code for this is in common.js, in the finish function.

@tarwich
Copy link

tarwich commented Feb 12, 2020

I could try adding nosort to see if it resolves the problem. To be clear, the problem is that in bash, for example, specifying ls {b,a}* implies precedence and we can expect bar to precede ant. This is powerful for setting the order of configuration files.

@isaacs
Copy link
Owner

isaacs commented Feb 28, 2023

@tarwich The reason bash does it that way is that bash is doing an iterative pattern replacement through the pattern string, rather than a recursive directory walk limited by the pattern. While that's very intuitive in a lot of cases, and easy to tie the results back to the pattern that they expanded into, it's also a bit challenging to do in an optimally performant way in JavaScript.

As it happens, glob v9 takes it even further from doing bash pattern expansion, in order to maximize parallelism in the file system walk for performance, and avoid ever testing the same path whenever possible. So, you'll probably have to use some other mechanism for path precedence in the match results, I'm afraid. There's fundamentally no way to get the performance gains in v9 without ditching the string-expansion approach in favor of a recursive fs walk style approach.

@isaacs isaacs closed this as completed Feb 28, 2023
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 13, 2024
…he to third_party/

This is a 'Flip' CL from go/nodemodulesingoogle3.
(The Flip CL does not need LGTM from third_party)

LOCAL MODIFICATIONS: Sorting is no longer supported by glob.sync (isaacs/node-glob#372).

GREEN TCP: OCL:605031371:BASE:606082614:1707691953923:1250eb85

PiperOrigin-RevId: 605031371
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 13, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 20, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 22, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 22, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 22, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 23, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 27, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Feb 27, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Mar 27, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Mar 27, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Mar 28, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Mar 29, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Mar 29, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Apr 1, 2024
copybara-service bot pushed a commit to angular/tsickle that referenced this issue Apr 2, 2024
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