From 24d6c28b5ac0dff74eceb805b9a0144abe4f51a3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 21 Jun 2024 09:31:10 -0500 Subject: [PATCH] chore: remove walkdir dev dependency (#42591) --- spec/get-files.ts | 21 +++++++++------------ spec/index.js | 2 +- spec/package.json | 1 - spec/yarn.lock | 5 ----- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/spec/get-files.ts b/spec/get-files.ts index e6e59c1da434..519f69427817 100644 --- a/spec/get-files.ts +++ b/spec/get-files.ts @@ -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 { + return fs.promises.readdir(dir) + .then(files => files.map(file => path.join(dir, file))) + .then(files => files.filter(file => test(file))); } diff --git a/spec/index.js b/spec/index.js index 2082ea9b2a39..34967e8f39f5 100644 --- a/spec/index.js +++ b/spec/index.js @@ -148,7 +148,7 @@ app.whenReady().then(async () => { }; const { getFiles } = require('./get-files'); - const testFiles = await getFiles(__dirname, { filter }); + const testFiles = await getFiles(__dirname, filter); for (const file of testFiles.sort()) { mocha.addFile(file); } diff --git a/spec/package.json b/spec/package.json index 94f0f54246b6..8455bdb996e1 100644 --- a/spec/package.json +++ b/spec/package.json @@ -35,7 +35,6 @@ "split": "^1.0.1", "temp": "^0.9.0", "uuid": "^3.3.3", - "walkdir": "^0.3.2", "winreg": "1.2.4", "ws": "^7.4.6", "yargs": "^16.0.3" diff --git a/spec/yarn.lock b/spec/yarn.lock index f833f786fe0d..d9bf04094c9c 100644 --- a/spec/yarn.lock +++ b/spec/yarn.lock @@ -2037,11 +2037,6 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -walkdir@^0.3.2: - version "0.3.2" - resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.3.2.tgz#ac8437a288c295656848ebc19981ebc677a5f590" - integrity sha512-0Twghia4Z5wDGDYWURlhZmI47GvERMCsXIu0QZWVVZyW9ZjpbbZvD9Zy9M6cWiQQRRbAcYajIyKNavaZZDt1Uw== - web-streams-polyfill@^3.2.1: version "3.3.3" resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b"