Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Workspace prompt rejects existing folders entered with ~, quotes or escaped spaces

已关闭 适合新手
#9 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
cli

调研方向

从 lib/cli.js 中的 validateWorkspace() 和 saveWorkspace() 入手;这两个函数目前都会去掉提示值首尾的空白,并将其解析为路径。追踪现有的平台注入在测试中的用法,然后补充对波浪号、带引号的路径、转义空格和错误消息的测试。两个提示都能接受有效的现有文件夹输入,且配置中存储的是未经修饰的绝对路径,即为完成。

由索引模型根据 Issue 内容生成。

描述

bug
Description

The README's Quick start says:

On the first launch, enter the folder that contains your projects, for example: ~/projects/

Entering ~/projects at that prompt is rejected, even when the folder exists:

That directory does not exist or is not accessible.

The prompt only trims the input and passes it to path.resolve(). Nothing expands ~, because the shell never sees text typed into a prompt, so ~/projects resolves to <current directory>/~/projects. For the same reason, two other common forms of an existing path are rejected:

  • quoted paths ("…" or '…'). Windows Explorer's Copy as path always adds double quotes, and many terminals quote a dragged folder whose path contains spaces;
  • escaped spaces (my\ projects), which some terminals produce when a folder is dragged in.

This applies to the first-run prompt and to Change workspace. dws --workspace ~/projects works because the shell expands the path before the CLI receives it.

Steps to reproduce
  1. Create two workspaces, one matching the README example and one with a space in its name:

    mkdir -p ~/projects/storefront ~/"my projects"/app
    echo '{"scripts":{"dev":"echo dev"}}' > ~/projects/storefront/package.json
    echo '{"scripts":{"hello":"echo hello"}}' > ~/"my projects"/app/package.json
    
  2. Start the published CLI with an empty configuration file, which triggers the first-run prompt:

    DEV_WORKSPACE_CONFIG=/tmp/dws-first-run.json \
      npx -p @modulane/[email protected] dws
    
  3. At Workspace path, enter each of these values, replacing /home/you with your home directory:

    ~/projects
    ~/my projects
    "/home/you/my projects"
    '/home/you/my projects'
    /home/you/my\ projects
    
Actual behaviour

Every value is rejected:

? Workspace path ~/projects
> That directory does not exist or is not accessible.

Only the bare absolute path (/home/you/my projects) is accepted. Choosing Change workspace from the project list and entering ~/projects gives the same error.

Expected behaviour

Each input resolves to the existing folder, and the configuration stores the plain absolute path.

When a path really doesn't exist, the error names the path that was checked, for example No directory at /current/dir/~/projects, so the cause is obvious.

Where
Suggested fix

Add a single helper that resolves the prompt input, used by both functions:

  1. Trim the input. If the path exists as typed, use it unchanged, so a folder whose real name contains quotes or backslashes keeps working.
  2. Otherwise, try a normalised form:
    • remove one pair of matching surrounding quotes;
    • expand a leading ~ (alone, or followed by /, or by \ on Windows) with os.homedir();
    • on non-Windows platforms only, turn \ into a space. On Windows, \ is the path separator.
  3. Use the error message above when neither form exists.

Each case can be unit-tested, including Windows-style input through the existing platform injection pattern.

This also helps the planned first-run experience in ROADMAP.md, which suggests ~/dev and ~/projects and keeps "Enter another path" as an option.

I'm happy to open a PR for this.

Environment
  • @modulane/dev-workspace-cli 0.5.0 from npm. lib/ is identical on main at dfccb6b.
  • Node.js 22.22.2, Linux x64. Windows and macOS were not tested; the code path is the same on every platform.
主要语言
JavaScript
星标
0
派生
0
平均合并
46 分钟
30 天内合并 PR
15

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。