diff --git a/packages/cli/__tests__/path.spec.ts b/packages/cli/__tests__/path.spec.ts index 8cee472f..e2792f8a 100644 --- a/packages/cli/__tests__/path.spec.ts +++ b/packages/cli/__tests__/path.spec.ts @@ -28,7 +28,7 @@ expect.extend({ }) it('pathCompletion', () => { - // expect(pathCompletion({ input: '', baseDir })).toBe('./folder/') + expect(pathCompletion({ input: '', baseDir })).toBeSamePath('./folder/') expect(pathCompletion({ input: 'f', baseDir })).toBeSamePath('./folder/') expect(pathCompletion({ input: 'fold', baseDir })).toBeSamePath('./folder/') expect(pathCompletion({ input: 'folder', baseDir })).toBeSamePath('./folder/') diff --git a/packages/cli/src/path.ts b/packages/cli/src/path.ts index c9db504c..6fc743c5 100644 --- a/packages/cli/src/path.ts +++ b/packages/cli/src/path.ts @@ -81,10 +81,11 @@ export function pathCompletion({ }): string { // Determine if the input is an absolute path const fullPath = path.isAbsolute(input) ? input : path.resolve(baseDir, input) + const isAtBase = path.resolve(baseDir) === path.resolve(fullPath) // Get the directory part and the part of the path to be completed - const dir = path.dirname(fullPath) - const toComplete = path.basename(fullPath) + const dir = isAtBase ? fullPath : path.dirname(fullPath) + const toComplete = isAtBase ? '' : path.basename(fullPath) // Check if the directory exists if (!fsa.existsSync(dir)) {