chore: remove walkdir dev dependency (#42591)

This commit is contained in:
Charles Kerr 2024-06-21 09:31:10 -05:00 committed by GitHub
parent ba8ad4716b
commit 24d6c28b5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 19 deletions

View file

@ -1,14 +1,11 @@
import { once } from 'node:events';
import * as walkdir from 'walkdir';
import * as fs from 'node:fs';
import * as path from 'node:path';
export async function getFiles (directoryPath: string, { filter = null }: {filter?: ((file: string) => boolean) | null} = {}) {
const files: string[] = [];
const walker = walkdir(directoryPath, {
no_recurse: true
});
walker.on('file', (file) => {
if (!filter || filter(file)) { files.push(file); }
});
await once(walker, 'end');
return files;
export async function getFiles (
dir: string,
test: ((file: string) => boolean) = (_: string) => true // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<string[]> {
return fs.promises.readdir(dir)
.then(files => files.map(file => path.join(dir, file)))
.then(files => files.filter(file => test(file)));
}