Skip to content

Different Dirent instance is returned based on pattern type #487

@Ethan-Arrowood

Description

@Ethan-Arrowood

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions