Skip to content

Commit

Permalink
support . as a pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Sep 30, 2024
1 parent 707acb2 commit 3f8031a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ function getRelativePath(path: string, cwd: string, root: string) {
}

function processPath(path: string, cwd: string, root: string, isDirectory: boolean, absolute?: boolean) {
const relativePath = absolute ? path.slice(root.length + 1) : path;
const relativePath = absolute ? path.slice(root.length + 1) || '.' : path;

if (root === cwd) {
return isDirectory ? relativePath.slice(0, -1) : relativePath;
return isDirectory && relativePath !== '.' ? relativePath.slice(0, -1) : relativePath;
}

return getRelativePath(relativePath, cwd, root);
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ test('exclude symlinks if the option is disabled', async () => {
assert.deepEqual(files.sort(), []);
});

test('. works', async () => {
const files = await glob(['.'], { cwd, expandDirectories: false, onlyDirectories: true });
assert.deepEqual(files.sort(), ['.']);
});

test('. works (absolute)', async () => {
const files = await glob(['.'], { cwd, absolute: true, expandDirectories: false, onlyDirectories: true });
assert.deepEqual(files.sort(), [cwd.replaceAll('\\', '/')]);
});

test('works with non-absolute cwd', async () => {
const files = await glob({ patterns: ['index.test.ts'], cwd: 'test' });
assert.deepEqual(files.sort(), ['index.test.ts']);
Expand Down

0 comments on commit 3f8031a

Please sign in to comment.