Unable to exclude files using glob pattern
Language
Typescript | JavaScript | CSS
Sample input source code
// sample file structure
src/
├── app/
│ ├── app.css
│ ├── app.html
│ └── app.js
└── package.json
// sortier command
sortier '**/!(*.json|*.css)'
Expected output
// result
sortier should have only modified the html and js files
Actual output (or error message)
// result
sortier modifies ALL files and does not exclude the css and json files
Thanks for the heads up, I've got a working reproduction locally. Trying to figure out the fix.
From what I can tell this issue is likely in globby or somewhere lower but I can't tell why. Let me explain, sortier uses globby to perform all glob interpretations and when I debug the code I see the following:
// args = ['**/!(*.json|*.css)']
const files = globbySync(args);
// files = ['package.json', 'app/app.css', 'app/app.html', 'app/app.js']
Testing the glob in
- https://toools.cloud/miscellaneous/glob-tester
- http://pthrasher.github.io/minimatch-test/
Seems to return the correct list of files so I'm not sure why this is happening.
Also, it seems **/*.{json,css} and **/*.(json|css) works perfectly fine
I created https://github.com/k2snowman69/issue-sortier-1763/blob/main/app/globby.test.js just to express the issue with globby a bit better. This reproduces the environment described in this bug. I created a test that shows that
- non-negation globs seem to work fine.
- Negation globs that have the negation at the beginning all result in 0 results - incorrect
- Negation globs that have the negation in the middle similar to the initial bug results in more files (3737) than a globstar
**results in (3699)
Not going to lie, I'm confused. This might be something to follow up on the globby library with.
A work around might be temporarily using the .sortierignore file instead but i haven't tested this yet