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

Ignore pattern not working proprerly #329

Closed
Njaah-0 opened this issue Jul 28, 2021 · 8 comments
Closed

Ignore pattern not working proprerly #329

Njaah-0 opened this issue Jul 28, 2021 · 8 comments

Comments

@Njaah-0
Copy link

Njaah-0 commented Jul 28, 2021

Environment

  • OS Version: MacOS Big Sur 11.4
  • Node.js Version: q2.22
  • Fast-glob: 3.2.7

Actual behavior

Applying pattern that has ! doesn't seem to ignore correctly. When same, reversed pattern is used in ignore option, it works properly
Screenshot 2021-07-28 at 12 15 14

Expected behavior

Screenshot 2021-07-28 at 12 15 06

Steps to reproduce

  1. See the image.

Code sample

const fg = require('fast-glob');

const entries = fg.sync(['./insertyourtestfolderhere/!(*.d).{ts,tsx}'], {
  dot: true,
  // ignore: ['./insertyourtestfolderhere/(*.d).{ts,tsx}'],
});

console.log(entries);
@leethree
Copy link

i'm having the same issue with pattern src/**/!(*.test).{ts,tsx}

@jrunning
Copy link

I'm seeing the same behavior with the pattern components/**/*!(.stories).js and every variation I've tried. Is there any update on this?

@jrunning
Copy link

Here's a super-simple repro:

$ ls
my-component.js
my-component.stories.js
MyComponent.js

$ node -e "let fg = require('fast-glob'); console.log(fg.sync('*!(.stories).js'))"
[ 'MyComponent.js', 'my-component.js', 'my-component.stories.js' ]

@mrmlnc mrmlnc self-assigned this Oct 31, 2021
@mrmlnc
Copy link
Owner

mrmlnc commented Oct 31, 2021

About !(*.d).{ts,tsx} → 🐛

const re = micromatch.makeRe('!(*.d).{ts,tsx}')
/^(?:(?=.)(?:(?!(?:[^/]*?\.d).{ts,tsx})[^/]*?)\.(ts|tsx))$/

re.test('file.d.ts')  true

Looks like a bug in the micromatch package.

Just a few similar cases:

About *!(.stories).js → ✔

The glob package also match component.js and component.stories.js for *!(.stories).js. But works correctly for !(*.stories).js.

According to Bash, it looks like this is valid behavior.

$ ls *!(.stories).js
component.js  component.stories.js

$ ls !(*.stories).js
component.js

@timtim17
Copy link

timtim17 commented Nov 25, 2021

I was encountering some quirkiness earlier, and I wasn't sure if it was similar to this issue.

aus@Austins-MBP src % tree -a
.
├── foo
│   ├── bar.txt
│   └── ignore.txt
├── index.js
└── test
    ├── baz
    │   ├── .not_this_either.txt
    │   └── also_no.txt
    └── no.txt

3 directories, 6 files
const fg = require('fast-glob');

const resultsA = fg.sync('**/*.txt', {
    ignore: ['**/test/**/*']
});
console.log(resultsA);

const resultsB = fg.sync('**/!(ignore)*.txt', {
    ignore: ['**/test/**/*']
});
console.log(resultsB);

const resultsC = fg.sync('**/!(ignore)*.txt', {
    ignore: ['**/test/**']
});
console.log(resultsC);
aus@Austins-MBP src % node index.js
[ 'foo/bar.txt', 'foo/ignore.txt' ]
[ 'foo/bar.txt', 'test/baz/.not_this_either.txt' ]
[ 'foo/bar.txt' ]

Results A: Works as expected. Gets all txt files, ignoring any in the test directory.
Results B: Does not work as expected. It does correctly give me all text files in the foo folder, except for the ignored ignore.txt, but it also gives me one of (but notably not all) files in the test directory.
Results C: Works as expected, after making a slight change to the ignore option.

I only encounter this when an ignore pattern is added to my pattern. If this is working as intended, or not related to this issue, please let me know. Thanks!

@mrmlnc
Copy link
Owner

mrmlnc commented Jan 2, 2022

Awaiting micromatch/picomatch#102.

@mrmlnc
Copy link
Owner

mrmlnc commented Jan 2, 2022

@timtim17, looks like a separate problem. Please fill another issue.

@mrmlnc
Copy link
Owner

mrmlnc commented Jan 2, 2022

Fixed by micromatch/picomatch#102 and released in 2.3.1. Since this is a transitive dependency on micromatch, it is enough to reinstall this package by npm i fast-glob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants