build: remove klaw dependency (#42701)

* refactor: remove klaw dependency

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

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! refactor: remove klaw dependency

findMatchingFiles returns a Promise<string[]>

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-06-28 10:11:42 +02:00 committed by GitHub
parent 8322c61a0a
commit 2c3a9fd3c5
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 = {