diff --git a/src/index.ts b/src/index.ts index 3328d3f..f4da040 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/test/index.test.ts b/test/index.test.ts index f76ecf2..98972fd 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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']);