Skip to content

Commit

Permalink
fix(cli): handle path completion at base
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Dec 30, 2023
1 parent d5b731c commit 1a5fa1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cli/__tests__/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 1a5fa1e

Please sign in to comment.