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

With onlyFiles: false directories at the root are not included #47

Open
pvdlg opened this issue Jan 30, 2018 · 8 comments
Open

With onlyFiles: false directories at the root are not included #47

pvdlg opened this issue Jan 30, 2018 · 8 comments
Assignees
Milestone

Comments

@pvdlg
Copy link

pvdlg commented Jan 30, 2018

With the following directory tree:

+-- test/
|   +-- dir
|       +-- file.js
fg.sync('test/**', {onlyFiles: false});

// Result => ['test/dir/', 'test/dir/file.js']
// Should be => ['test', 'test/dir', 'test/dir/file.js']

For example with node-glob:

glob.sync('test/**', {nodir: false});

// Result => ['test', 'test/dir', 'test/dir/file.js']
@dylang
Copy link

dylang commented Mar 15, 2018

I'm not sure if this is the same issue:

+ fixtures
  + dir1
  + dir2
// I expect this to return [ 'dir1', 'dir2' ]
// and it does
const results = await glob(['fixtures/*'], { onlyDirectories: true });
// I expect this to return [ 'fixtures' ],
// but it returns [ ]
const results = await glob(['fixtures'], { onlyDirectories: true });

@mrmlnc
Copy link
Owner

mrmlnc commented Mar 15, 2018

Hello, @dylang,

Looks like separated issue. Please create a issue for your problem.

I can say right now, that this is works on my machine:

tree fixtures/
fixtures/
├── b
│   └── c
│       ├── md.md
│       └── txt.txt
├── md.md
└── txt.txt
const fg = require('fast-glob');

const entries0 = fg.sync(['fixtures/*'], { onlyDirectories: true });

console.dir(entries0, { colors: true });  // [ 'fixtures/b' ]

const entries1 = fg.sync(['fixtures'], { onlyDirectories: true });

console.dir(entries1, { colors: true });  // [ 'fixtures' ]

Are you sure you're using the latest version of the package? But I need more information about your case. Your version of the fast-glob package, OS and etc.

@dylang
Copy link

dylang commented Mar 15, 2018

@mrmlnc You are correct, older version via globby at fault, thanks for the quick reply!

@mrmlnc mrmlnc removed this from the 2.2.1 milestone Apr 22, 2018
@mrmlnc
Copy link
Owner

mrmlnc commented May 18, 2018

Blocked by migrate to @nodelib/fs.walk (nodelib/nodelib#9).

@mrmlnc mrmlnc added this to the 3.0.0 milestone Jan 2, 2019
@mrmlnc mrmlnc modified the milestones: 3.0.0, 3.1.0 Apr 5, 2019
@mrmlnc mrmlnc modified the milestones: 3.1.0, 3.2.0 Sep 22, 2019
@mrmlnc mrmlnc modified the milestones: 3.2.0, 3.x.x Jan 21, 2020
@lcrespom
Copy link

lcrespom commented Feb 8, 2020

I am executing this code:

const glob = require('fast-glob').sync
console.log(glob('/*', { onlyFiles: false }))

And I get [] as the output. I am using MacOS and v12.14.0.
I think this problem is related with this issue, but maybe it's a different one.

@mrmlnc
Copy link
Owner

mrmlnc commented Feb 8, 2020

@lcrespom,

Nope, if you want to get only directories, then you need to use the onlyDirectories option. When you disable the onlyFiles option the onlyDirectories option is not automatically enabled.

@lcrespom
Copy link

lcrespom commented Feb 8, 2020

I don't want only directories, I want to get all dirs and files of my root directory, but instead I am getting an empty array, and I can assure you my root directory is not empty.

P.S. even if I wanted only directories, I have just tested this code:

const glob = require('fast-glob').sync
console.log(glob('/*', { onlyFiles: false, onlyDirectories: true }))

...and it also displays [].

@75lb
Copy link

75lb commented Jun 5, 2021

Any update on a fix for this? This issue is preventing me switching to fast-glob from node-glob (without a breaking change)..

$ tree
.
├── 1
│   ├── one
│   └── two
│       └── three

$ echo 1/**
1/ 1/one 1/two 1/two/three

$ node
Welcome to Node.js v16.2.0.
> fg = require('fast-glob')
> fg.sync(['1/**'], { onlyFiles: false })
[ '1/one', '1/two', '1/two/three' ]

As you can see in the example above, bash expands 1/** to four paths while fast-glob only expands to three paths ('1/' is missing).

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