sortier icon indicating copy to clipboard operation
sortier copied to clipboard

Unable to exclude files using glob pattern

Open a1isaeed opened this issue 4 years ago • 3 comments

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

a1isaeed avatar Jul 21 '22 16:07 a1isaeed

Thanks for the heads up, I've got a working reproduction locally. Trying to figure out the fix.

k2snowman69 avatar Jul 22 '22 04:07 k2snowman69

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

k2snowman69 avatar Jul 22 '22 06:07 k2snowman69

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

k2snowman69 avatar Jul 22 '22 07:07 k2snowman69