Skip to content

Commit

Permalink
fix path inferring with expandDirectories disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Aug 24, 2024
1 parent ae772b9 commit f9fe994
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit f9fe994

Please sign in to comment.