From bd81dad100345525b0871ee1a87f9a6f57ec0daf Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Wed, 28 May 2025 13:02:02 +0200 Subject: [PATCH 1/2] fix: do not stop crawling at `currentDepth` 0 --- src/api/functions/walk-directory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/functions/walk-directory.ts b/src/api/functions/walk-directory.ts index 1a9197a..9cddb3d 100644 --- a/src/api/functions/walk-directory.ts +++ b/src/api/functions/walk-directory.ts @@ -20,7 +20,7 @@ const walkAsync: WalkDirectoryFunction = ( ) => { state.queue.enqueue(); - if (currentDepth <= 0) return state.queue.dequeue(null, state); + if (currentDepth < 0) return state.queue.dequeue(null, state); state.visited.push(crawlPath); state.counts.directories++; @@ -41,7 +41,7 @@ const walkSync: WalkDirectoryFunction = ( currentDepth, callback ) => { - if (currentDepth <= 0) return; + if (currentDepth < 0) return; state.visited.push(crawlPath); state.counts.directories++; From cdd8c6130e49e2d7fbaf15822baae4968841b84a Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Wed, 28 May 2025 13:16:42 +0200 Subject: [PATCH 2/2] chore: improve depth tests --- __tests__/fdir.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/__tests__/fdir.test.ts b/__tests__/fdir.test.ts index 3dc1cf0..0cec2c5 100644 --- a/__tests__/fdir.test.ts +++ b/__tests__/fdir.test.ts @@ -52,17 +52,24 @@ for (const type of apiTypes) { includeBasePath: true, }).crawl("node_modules"); const files = await api[type](); - t.expect(files.every((file) => file.split("/").length <= 2)).toBe(true); + t.expect(files).not.toHaveLength(0); + t.expect(files.every((file) => file.split(path.sep).length === 2)).toBe( + true + ); }); test(`[${type}] crawl multi depth directory with options`, async (t) => { const api = new fdir({ maxDepth: 1, + includeBasePath: true, }).crawl("node_modules"); const files = await api[type](); - t.expect( - files.every((file) => file.split(path.sep).length <= 3) - ).toBeTruthy(); + t.expect(files.some((file) => file.split(path.sep).length === 3)).toBe( + true + ); + t.expect(files.every((file) => file.split(path.sep).length <= 3)).toBe( + true + ); }); test(`[${type}] crawl multi depth directory`, async (t) => {