| 3 | |
| 4 | // from https://github.com/webpro/knip/pull/426 |
| 5 | export function crawlFileSystemFsWalk<T = string>( |
| 6 | options: CrawlFileSystemOptions<T>, |
| 7 | ): Promise<T[]> { |
| 8 | const { directory } = options; |
| 9 | |
| 10 | return new Promise((resolve, reject) => { |
| 11 | const result: T[] = []; |
| 12 | const stream = walkStream(directory); |
| 13 | |
| 14 | stream.on('data', (entry: Entry) => { |
| 15 | // eslint-disable-next-line functional/immutable-data |
| 16 | result.push(entry.path as T); |
| 17 | }); |
| 18 | |
| 19 | stream.on('error', error => { |
| 20 | reject(error); |
| 21 | }); |
| 22 | |
| 23 | stream.on('end', () => { |
| 24 | resolve(result); |
| 25 | }); |
| 26 | }); |
| 27 | } |