Skip to content

Different Dirent instance is returned based on pattern type #487

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

Open
Ethan-Arrowood opened this issue Feb 24, 2025 · 0 comments
Open

Different Dirent instance is returned based on pattern type #487

Ethan-Arrowood opened this issue Feb 24, 2025 · 0 comments

Comments

@Ethan-Arrowood
Copy link

When using a dynamic vs static pattern and the objectMode: true option, different Dirent instances are being returned.

In a very basic project (mkdir test && cd test && npm i fast-glob), the following code will return two different Dirent isntances.

import fg from 'fast-glob';

const f1 = fg.sync('./**/package.json', { objectMode: true, ignore: ['node_modules'] });
console.log(f1[0].dirent);

const f2 = fg.sync('./package.json', { objectMode: true, ignore: ['node_modules'] });
console.log(f2[0].dirent);

Run with node index.js (in v22):

# omitting unnecessary warnings

Dirent {
  name: 'package.json',
  parentPath: '/Users/ethan/dev/fast-glob-test',
  path: '/Users/ethan/dev/fast-glob-test',
  [Symbol(type)]: 1
}

DirentFromStats {
  name: './package.json',
  isBlockDevice: [Function: bound ],
  isCharacterDevice: [Function: bound ],
  isDirectory: [Function: bound ],
  isFIFO: [Function: bound ],
  isFile: [Function: bound ],
  isSocket: [Function: bound ],
  isSymbolicLink: [Function: bound ]
}

I've debugged the library and it seems like the first pattern is considered dynamic which mean its uses the dynamic reader (calling fs.walk) as compared to the static flow which only retrieves the stats instead of a complete Dirent.

Is this difference intended?

I would expect the behavior to be the same, and ideally the static path returns an actual Dirent instance

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

1 participant