build: remove klaw dependency (#42529)

* refactor: remove klaw dependency

Node 20 added recursive readdir() so klaw is not needed

* fixup! refactor: remove klaw dependency

findMatchingFiles returns a Promise<string[]>
This commit is contained in:
Charles Kerr 2024-06-18 17:54:26 -05:00 committed by GitHub
parent 71338140a4
commit 980e884fa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 30 deletions

View file

@ -1,6 +1,5 @@
const { GitProcess } = require('dugite');
const fs = require('node:fs');
const klaw = require('klaw');
const os = require('node:os');
const path = require('node:path');
@ -130,18 +129,13 @@ function chunkFilenames (filenames, offset = 0) {
* @returns {Promise<string[]>}
*/
async function findMatchingFiles (top, test) {
return new Promise(resolve => {
const matches = [];
klaw(top, {
filter: f => path.basename(f) !== '.bin'
})
.on('end', () => resolve(matches))
.on('data', item => {
if (test(item.path)) {
matches.push(item.path);
}
});
});
return fs.promises.readdir(top, { encoding: 'utf8', recursive: true })
.then(files => {
return files
.filter(name => path.basename(name) !== '.bin')
.filter(name => test(name))
.map(name => path.join(top, name));
});
}
module.exports = {