Browse Source

chore: remove walkdir dev dependency (#42591)

Charles Kerr 10 months ago
parent
commit
24d6c28b5a
4 changed files with 10 additions and 19 deletions
  1. 9 12
      spec/get-files.ts
  2. 1 1
      spec/index.js
  3. 0 1
      spec/package.json
  4. 0 5
      spec/yarn.lock

+ 9 - 12
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<string[]> {
+  return fs.promises.readdir(dir)
+    .then(files => files.map(file => path.join(dir, file)))
+    .then(files => files.filter(file => test(file)));
 }

+ 1 - 1
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);
   }

+ 0 - 1
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"

+ 0 - 5
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"