sindresorhus / globby

User-friendly glob matching
MIT License
2.52k stars 130 forks source link

Windows globby.sync no longer works for window's paths #130

Closed k2snowman69 closed 5 years ago

k2snowman69 commented 5 years ago

Recently updated from globby@9.2.0 -> globby@10.0.0 and I've found a difference in execution.

Note that this only happens on Windows. It does not happen on OSX or Linux

9.2.0

let fileList = sync("d:\Temporary\prettier\src*\.js"); // fileList.length === 109

10.0.0

let fileList = sync("d:\Temporary\prettier\src*\.js"); // fileList.length === 0

Expected: fileList.length to be 109

sindresorhus commented 5 years ago

Duplicate of #127

sindresorhus commented 5 years ago

This is mentioned in the release notes: https://github.com/sindresorhus/globby/releases/tag/v10.0.0

k2snowman69 commented 5 years ago

Where in the release notes? This is all I see:

Breaking: Upgrade fast-glob package to v3 (#126) 3706920 Important: Read the fast-glob release notes! There are many breaking changes. Require Node.js 8 9f781ce Remove /bower_components/ as a default ignore pattern 2dd76d2

Enhancements: Add globby.stream() (#113) 8aadde8

Fixes: Fix using the gitignore and stats options together (#121) 33ca01c

k2snowman69 commented 5 years ago

Ahh you meant here https://github.com/mrmlnc/fast-glob#pattern-syntax

k2snowman69 commented 5 years ago

Closing issue... will have to determine next steps on my own...

the-simian commented 5 years ago

If anyone finds this, this is the relevant part: https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows

just using posix alone wasn't good enough, because like when I did path.resolve with __dirname, it gave me a path with mixed / directions on Windows. I had to actually do

.replace(/\\/g, '/') on my final path string to get good results... this particular issue really caught me by surprise

citrusjunoss commented 4 years ago

If anyone finds this, this is the relevant part: https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows

just using posix alone wasn't good enough, because like when I did path.resolve with __dirname, it gave me a path with mixed / directions on Windows. I had to actually do

.replace(/\\/g, '/') on my final path string to get good results... this particular issue really caught me by surprise

Can you help me see where there is a problem with usage?

const entriesPath = globby.sync([ path .join(process.cwd(), resolveApp('src') + '/containers/*/index.tsx') .replace(/\\/g, '/'), ]);

This can't find any matching files

the-simian commented 4 years ago

'/containers/*/index.tsx' may need to be '/containers/**/index.tsx'

try to glob a specific file first. also you likely want to do the replace on the final path, looks like you've also got like a trailing , and no more glob patterns?

let _path = path .join(process.cwd(), resolveApp('src') + '/containers/*/index.tsx') ;
//console.log(_path)  is this right?? does resolveApp and process.cwd being joined truly work?
_path = _path.replace(/\\/g, '/');
globby.sync(_path);

better suggestion? just use the unixify package!

const glob = require('globby');
const unixify = require('unixify');

function patternToFile(pattern) {
    let _path = unixify(pattern);
    return glob.sync(_path);
}

const files = patternToFile(`./containers/**/index.tsx`);