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

Glob 7.2.0 -> 8.0.3 glob.sync returns different result, why? #480

Closed
fabiohaertel opened this issue Jun 9, 2022 · 2 comments
Closed

Glob 7.2.0 -> 8.0.3 glob.sync returns different result, why? #480

fabiohaertel opened this issue Jun 9, 2022 · 2 comments

Comments

@fabiohaertel
Copy link

Hi guys.

I'm using Windows with node 16.12 and npm 8.1.0

Couldn't figure this out by myself.
I have a simple scenario:

npm i glob@7.2.0

const glob = require('glob');
const $path = require('path');

const files = glob.sync($path.join(__dirname, '*.txt'));
console.log(files)

Result = [ 'C:/DEV/glob/a.txt', 'C:/DEV/glob/b.txt' ]

npm i glob@8.0.3

const glob = require('glob');
const $path = require('path');

const files = glob.sync($path.join(__dirname, '*.txt'));
console.log(files)

Result = []

Not sure what I should do here. Tried googling for some time but couldn't find an explanation.

Can anybody help me?
Thanks!

@nicolas377
Copy link

glob v8 updated minimatch, the library that does glob's matching, to v5. Minimatch v5 breaks windows glob matching by forcing all inputs to use forward slashes. Backslashes are considered escape characters. Since you're using the path module, it will automatically use backslashes for you since you're on windows. There are two solutions:

  1. import path/posix instead of path
    • that is a submodule of path that provides the *nix version of the path module. You will be able to use it just as you will path, but it will automatically use forward slashes
  2. manually convert the string to use forward slashes
    • you could use path.join(__dirname, '*.txt').split(path.sep).join("/") to split by the separator the path module is using, and recreates the string using forward slashes.

@fabiohaertel
Copy link
Author

Thanks for the explanation.

cmotsn pushed a commit to cmotsn/ngx-translate-extract that referenced this issue Apr 26, 2023
Since glob@9, glob pattern require `/` as path separator (see isaacs/node-glob#480)
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

No branches or pull requests

2 participants