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

improve and completely rework exclude optimizer #76

Merged
merged 5 commits into from
Feb 14, 2025

Conversation

SuperchupuDev
Copy link
Owner

@SuperchupuDev SuperchupuDev commented Dec 1, 2024

shorter and probably faster implementation 🎉 also improves optimization for patterns that end with **

needs some work, this implementation (and the previous one) don't work well with patterns that wrap / in things like *(src/index.ts). see #76 (comment) disabled optimizations in those cases for now

also closes #79 once the above is solved, and makes tests from #80 work :-)

EDIT: REWRITTEN FROM THE GROUND UP with a different approach to avoid the many edge cases it used to have

Copy link

pkg-pr-new bot commented Dec 1, 2024

Open in Stackblitz

npm i https://pkg.pr.new/tinyglobby@76

commit: 6d5b0bb

Co-authored-by: Joachim Viide <[email protected]>
@SuperchupuDev
Copy link
Owner Author

SuperchupuDev commented Jan 17, 2025

while the tests do pass now thanks to the new fdir version fixing excluding symlinks, this implementation doesn't handle patterns that have / inside glob symbols well, for example this test that i haven't pushed:

test('dynamic patterns that include slashes inside parts', async () => {
  const files = await glob({ patterns: ['{.a/a,a}/a.txt'], cwd });
  // files ends up being []
  assert.deepEqual(files.sort(), ['a/a.txt', '.a/a/a.txt']);
});

it's easy to see why it fails but hard to properly fix. other than splitting the parts with picomatch which is easy to do (now done), i'm not sure how to modify the code to properly account for it. there's an option to just replace parts that have / with ** but it should be the last choice as that would just skip optimizations

@benmccann
Copy link
Contributor

Would it help to have tinyglobby expand ['{.a/a,a}/a.txt'] to ['.a/a/a.txt', 'a/a.txt'] as a first step?

@SuperchupuDev
Copy link
Owner Author

maybe but i'm not sure if it's optimal

didn't want to do this, but this pr is important and a release is being delayed too much. thankfully, it seems like almost no one uses patterns like that. any optimizations here are welcome
@SuperchupuDev SuperchupuDev marked this pull request as ready for review January 29, 2025 21:12
@SuperchupuDev
Copy link
Owner Author

globbing update: this PR breaks some use cases of broken parentheses, because for some weird reason globbing unescaped parentheses also matches literal parentheses. i really wish we could get a partial option on picomatch

@SuperchupuDev
Copy link
Owner Author

the optimizer was completely rewritten again! the above comment no longer applies. should be ready to go :-) will test some more

also add more partial tests
@SuperchupuDev SuperchupuDev changed the title improve exclude optimizer improve and completely rework exclude optimizer Feb 14, 2025
@SuperchupuDev SuperchupuDev merged commit 1ff61e9 into main Feb 14, 2025
6 checks passed
@SuperchupuDev SuperchupuDev deleted the refactor/better-exclude branch February 14, 2025 23:18
Copy link

@Fuzzyma Fuzzyma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a little nitpick :D.

Also a "question" regarding your use of regexes. I learned, that regexes need to be compiled. So creating them via /regex/ on the fly might double up work. If the regexes are likely to be used anyway (and more than once), define them on the module level so the compile step is only done once

SuperchupuDev added a commit that referenced this pull request Feb 16, 2025
@SuperchupuDev
Copy link
Owner Author

@Fuzzyma @pralkarz suggestions have been applied in 8872e68, let me know if y'all want me to change anything else 👍

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.

common path algorithm calculates parts wrong with / inside part
4 participants