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

Difference behavior for dot files on windows and linux #159

Closed
alexander-akait opened this issue Feb 18, 2019 · 11 comments
Closed

Difference behavior for dot files on windows and linux #159

alexander-akait opened this issue Feb 18, 2019 · 11 comments

Comments

@alexander-akait
Copy link

Environment

  • OS Version: windows/linux
  • Node.js Version: 8.15.0

Actual behavior

We have file directory/.dottedfile

pattern - {file.txt,noextension,directory/**/*}

On linux - file founded
On windows - no

https://ci.appveyor.com/project/webpack-contrib/copy-webpack-plugin/builds/22457587/job/y5320ckr1fvs6r67

Expected behavior

Founded on linux and windows, or provide documentation why it is doesn't work and/or how can be fixed

Steps to reproduce

Below

Code sample

fg(['{file.txt,noextension,directory/**/*}'], { dot: true }).then((entries) => console.log(entries));
@mrmlnc mrmlnc self-assigned this Feb 18, 2019
@mrmlnc mrmlnc pinned this issue Feb 18, 2019
@mrmlnc
Copy link
Owner

mrmlnc commented Feb 19, 2019

It looks weird. Does not work on Windows 10 and WSL (Ubuntu). Also does not work with the minimatch, picomatch and globrex package.

This a RegExp for Entry filter:

/^(?:(?:\.[\\\/](?=.))?(?:bench\.js|directory[\\\/](?:(?!(?:[\\\/]|^)(?:\.{1,2})($|[\\\/]))(?!\.{2}).)*?[\\\/](?!(?:^|[\\\/])\.{1,2}(?:$|[\\\/]))(?!(\.{2}|\.[\\\/]))(?=.)[^\\\/]*?)(?:[\\\/]|$))$/

The entries in my directory:

bench.js
directory/.dotted

And…

const re = /^(?:(?:\.[\\\/](?=.))?(?:bench\.js|directory[\\\/](?:(?!(?:[\\\/]|^)(?:\.{1,2})($|[\\\/]))(?!\.{2}).)*?[\\\/](?!(?:^|[\\\/])\.{1,2}(?:$|[\\\/]))(?!(\.{2}|\.[\\\/]))(?=.)[^\\\/]*?)(?:[\\\/]|$))$/;

re.test('bench.js'); // → true
re.test('directory/.dotted'); // → false

@mrmlnc
Copy link
Owner

mrmlnc commented Feb 19, 2019

As a temporary solution, you can divide the pattern into several:

const entries = fg.sync(['bench.js', 'directory/**/*'], {
    dot: true
});

@alexander-akait
Copy link
Author

@mrmlnc thanks, we want to migrate copy-webpack-plugin (https://www.npmjs.com/package/copy-webpack-plugin) on last globby (uses fat-glob) and can't use this workaround, unfortunately we cannot migrate due to this problem, also i find something strange this ( and ) characters you can see all failed tests https://ci.appveyor.com/project/webpack-contrib/copy-webpack-plugin/builds/22457587/job/y5320ckr1fvs6r67 (on old globby with node-glob all tests passed)

@jonschlinkert
Copy link

also i find something strange this ( and ) characters you can see all failed tests https://ci.appveyor.com/project/webpack-contrib/copy-webpack-plugin/builds/22457587/job/y5320ckr1fvs6r67 (on old globby with node-glob all tests passed)

FWIW, the tests passed with node-glob because node-glob can't handle non-extglob parenthesis and so it just escapes everything, resulting in \\(. It's not technically "working", it's just coincidental that your pattern happened to work, as the escaping often results in nothing matching at all.

To use parens with micromatch, you can either use a valid extglob, like +(foo|bar), or escape the parens with backslashes, like \\(.

Happy to help if you still have questions.

@alexander-akait
Copy link
Author

@jonschlinkert can you clarify with examples, thanks

@jonschlinkert
Copy link

unfortunately we cannot migrate due to this problem, also i find something strange this ( and ) characters you can see all failed tests

The pattern (special-file).txt should be \\(special-file\\).txt.

I think that was the only failing pattern, correct?

The reason node-glob matched before is that minimatch assumes that ( and ) should always be matched literally and adds \\ before all parentheses.

@jonschlinkert
Copy link

@evilebottnawi @mrmlnc

FWIW I'm definitely open to changing the default behavior in micromatch/picomatch to assume that ( and ) should always be matched literally. We can require the user to enable regex-like behavior using options. We can at least get a discussion going if you think it makes sense.

@mrmlnc
Copy link
Owner

mrmlnc commented Mar 18, 2019

Sorry guys, I don't have free time right now. I'll be back as soon as I can. Add a record to the ToDo.

@jonschlinkert
Copy link

No worries take your time!

@mrmlnc
Copy link
Owner

mrmlnc commented Mar 20, 2019

I suggest we relocate discussion to the Picomatch repository. It seems that in this ticket we had to talk about curly braces.

micromatch/picomatch#7

@mrmlnc
Copy link
Owner

mrmlnc commented Apr 21, 2019

The original problem is fixed after migration from micromatch@3 to micromatch@4.

#154

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

3 participants