thecodrr / fdir

⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
https://thecodrr.github.io/fdir/
MIT License
1.51k stars 58 forks source link

Crawl with options group interface no longer correct in v5.2.0 (v5.1.0 was the same) #75

Closed p-mcgowan closed 1 year ago

p-mcgowan commented 2 years ago

crawlWithOptions API in combination with withPromise no longer outputs a GroupOutput as per the typings.

The test script:

const { fdir } = require('../');

const test = async (dir) => {
  const files = await new fdir()
    .crawlWithOptions(dir, {
      includeBasePath: true,
      group: true,
    })
    .withPromise();

  console.log(files);
};

test(`${__dirname}/dir`);
$ tree fdir-api-change/
fdir-api-change/
├── dir
│   ├── a
│   │   ├── a.txt
│   │   └── b
│   │       ├── b.txt
│   │       └── x.txt
│   └── dir.txt
└── test.js
$ git checkout 8f1c4b9 && node fdir-api-change/test.js 
HEAD is now at 8f1c4b9 fix: make all tests pass
[
  'home/source/fdir/fdir-api-change/dir/': [ 'home/source/fdir/fdir-api-change/dir/dir.txt' ],
  'home/source/fdir/fdir-api-change/dir/a/': [ 'home/source/fdir/fdir-api-change/dir/a/a.txt' ],
  'home/source/fdir/fdir-api-change/dir/a/b/': [
    'home/source/fdir/fdir-api-change/dir/a/b/b.txt',
    'home/source/fdir/fdir-api-change/dir/a/b/x.txt'
  ]
]
$ git checkout 8f1c4b9^ && node fdir-api-change/test.js
Previous HEAD position was 8f1c4b9 fix: make all tests pass
HEAD is now at 0cafa69 feat: refactor & minor performance improvements
[]
$ git checkout 8f1c4b9^^ && node fdir-api-change/test.js
Previous HEAD position was 0cafa69 feat: refactor & minor performance improvements
HEAD is now at 16d0790 feat: add withRelativePaths option (fix #51)
[
  {
    dir: 'home/source/fdir/fdir-api-change/dir',
    files: [ 'home/source/fdir/fdir-api-change/dir/dir.txt' ]
  },
  {
    dir: 'home/source/fdir/fdir-api-change/dir/a',
    files: [ 'home/source/fdir/fdir-api-change/dir/a/a.txt' ]
  },
  {
    dir: 'home/source/fdir/fdir-api-change/dir/a/b',
    files: [
      'home/source/fdir/fdir-api-change/dir/a/b/b.txt',
      'home/source/fdir/fdir-api-change/dir/a/b/x.txt'
    ]
  }
]

Unless I'm missing something very obvious (entirely possible), I have to lock at 5.1.0 and miss out on performance boosts or change my api to call Object.entries, which I assume is much slower than the original version.

thecodrr commented 2 years ago

This will be fixed in the upcoming v6.0 which has been fully rewritten in Typescript.