From f9fe994da000bcce714053994e4315e71e464c2f Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:40:48 +0100 Subject: [PATCH] fix path inferring with `expandDirectories` disabled --- src/index.ts | 3 ++- test/index.test.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 012a803..a42f368 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,11 +62,12 @@ function normalizePattern( if (properties.commonPath[i] === part && !/[\!\*\{\}\(\)]/.test(part)) { newCommonPath.push(part); } else { - newCommonPath.pop(); break; } } + newCommonPath.pop(); + properties.depthOffset = newCommonPath.length; properties.commonPath = newCommonPath; diff --git a/test/index.test.ts b/test/index.test.ts index 83ac7ce..9da644d 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -68,6 +68,16 @@ test('expandDirectories true', async () => { assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts']); }); +test("no expandDirectories doesn't break common path inferring", async () => { + const files = await glob({ patterns: ['a/a.ts'], expandDirectories: false, cwd }); + assert.deepEqual(files.sort(), ['a/a.ts']); +}); + +test("expandDirectories doesn't break common path inferring either", async () => { + const files = await glob({ patterns: ['a/a.ts'], expandDirectories: true, cwd }); + assert.deepEqual(files.sort(), ['a/a.ts']); +}); + test('handle absolute patterns to some extent', async () => { const files = await glob({ patterns: [`${cwd.replaceAll('\\', '/')}/a/a.ts`], cwd }); assert.deepEqual(files.sort(), ['a/a.ts']);