Workspace prompt rejects existing folders entered with ~, quotes or escaped spaces
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
- 领域
- cli
调研方向
从 lib/cli.js 中的 validateWorkspace() 和 saveWorkspace() 入手;这两个函数目前都会去掉提示值首尾的空白,并将其解析为路径。追踪现有的平台注入在测试中的用法,然后补充对波浪号、带引号的路径、转义空格和错误消息的测试。两个提示都能接受有效的现有文件夹输入,且配置中存储的是未经修饰的绝对路径,即为完成。
由索引模型根据 Issue 内容生成。
描述
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
-
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 -
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 -
At Workspace path, enter each of these values, replacing
/home/youwith 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
validateWorkspace()andsaveWorkspace()call onlytrim()andpath.resolve().
Suggested fix
Add a single helper that resolves the prompt input, used by both functions:
- Trim the input. If the path exists as typed, use it unchanged, so a folder whose real name contains quotes or backslashes keeps working.
- Otherwise, try a normalised form:
- remove one pair of matching surrounding quotes;
- expand a leading
~(alone, or followed by/, or by\on Windows) withos.homedir(); - on non-Windows platforms only, turn
\into a space. On Windows,\is the path separator.
- 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-cli0.5.0 from npm.lib/is identical onmainat 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
glossyio/traffic-monitor#264 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 88/100
micromatch/picomatch#243 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
getComputedStyle().display is "" for span, a, b, label and other inline elements instead of "inline"未关闭
难度 2/5 1-3 小时 新手友好度 76/100
capricorn86/happy-dom#2556 ·
维护者通常 1 天内回复