Skip to content

fix(prompts): treat symlinks to directories as directories in path - #659

Open
Abmichael01 wants to merge 1 commit into
bombshell-dev:mainfrom
Abmichael01:fix/path-symlinked-directories
Open

Abmichael01 wants to merge 1 commit into
bombshell-dev:mainfrom
Abmichael01:fix/path-symlinked-directories

Conversation

@Abmichael01

Copy link
Copy Markdown

What does this PR do?

path checks entries with lstatSync, which describes the link itself, so a symlink to a directory counts as a file. With directory: true that means:

  • symlinked directories are missing from the suggestions
  • typing the exact path of one and pressing enter shows "Please select a path", so it cannot be chosen at all

On macOS this should include /tmp, which is a symlink to /private/tmp (I tested on Linux).

To reproduce with 1.9.0:

mkdir real && ln -s real link
import { path } from '@clack/prompts';

// press enter: "Please select a path" (with `${process.cwd()}/real` it submits)
await path({ message: 'Pick a folder', directory: true, initialValue: `${process.cwd()}/link` });

The prompt now uses statSync, which follows links. statSync throws for broken and circular links, and one of those would have emptied the whole list, so they are caught and still count as files, as before.

One behavior change without directory: when root or initialValue is a symlinked directory, the prompt now lists its contents, as it already does for a normal directory. Before, it suggested the link itself.

I searched for an existing issue and did not find one. The fix is small, so I included the reproduction here instead of opening one, but I can open an issue if you prefer.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

I ran the core and prompts test suites, the type check, and Biome on the changed files. I did not run pnpm build locally. Circular links are not in the unit tests because memfs hangs on them; I checked that case on a real file system.

AI-generated code disclosure

  • This PR includes AI-generated code

🤖 Generated with Claude Code

https://claude.ai/code/session_0147uBPeX9ixTKJddVsvFtix

`path` checked entries with lstat, which describes the link itself, so a symlink
to a directory counted as a file. With `directory: true` it was never suggested
and could not be submitted, even when its exact path was typed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0147uBPeX9ixTKJddVsvFtix
@changeset-bot

changeset-bot Bot commented Dec 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 950b94f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dreyfus92

Copy link
Copy Markdown
Member

hey @Abmichael01 before creating a pr, it is recommended opening an issue for previous discussion. so this will be on hold before we get a chance to talk about it. thanks in advance! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants