package.json files that start with a UTF-8 BOM are rejected as invalid JSON
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
- Lĩnh vực
- cli
Hướng nghiên cứu
Đọc lib/workspace.js, lib/package-managers.js và lib/config.js, bắt đầu từ ba vị trí phân tích được nêu trong issue. Kiểm tra các bài kiểm thử hiện có bao quát việc phân tích JSON như thế nào, rồi thêm các trường hợp có BOM ở đầu cho getScripts(), detectPackageManager() và readWorkspaceConfig(). Công việc hoàn tất khi từng tệp được đọc thành công và BOM không ảnh hưởng đến các giá trị đã phân tích.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
A package.json that starts with a UTF-8 byte order mark (BOM) is rejected by the CLI, while npm reads it without complaint. Files like this are common on Windows: Windows PowerShell 5.1 writes a BOM with Set-Content -Encoding UTF8 or Out-File -Encoding utf8, and some editors add one.
For such a project, the CLI:
- shows no scripts: opening the project shows
Could not read package.json: Invalid JSON in …instead of the script list, althoughnpm run <script>works in that folder; - would pick the wrong package manager: the
packageManagerfield is read with the sameJSON.parse, which fails silently, so a"packageManager": "[email protected]"project is detected as npm.
The CLI's own configuration file has the same problem: a config.json saved with a BOM, for example after editing it in an editor that adds one, is reported as Invalid configuration JSON.
Steps to reproduce
-
Create a project whose
package.jsonstarts with a BOM.In a POSIX shell:
mkdir -p /tmp/dws-bom/bom-app printf '\357\273\277{"name":"bom-app","packageManager":"[email protected]","scripts":{"hello":"echo hello"}}' \ > /tmp/dws-bom/bom-app/package.jsonIn PowerShell 7, the same file can be written with
Set-Content -Encoding utf8BOM; Windows PowerShell 5.1 adds the BOM with-Encoding UTF8. -
Check that npm accepts it:
cd /tmp/dws-bom/bom-app && npm run helloThis prints
hello. -
Start the published CLI on the workspace, then open
bom-app:DEV_WORKSPACE_CONFIG=/tmp/dws-bom/config.json \ npx -p @modulane/[email protected] dws --workspace /tmp/dws-bom
Actual behaviour
The project screen shows the error from getScripts(). Observed on Windows, with the folder path shortened:
Could not read package.json: Invalid JSON in …\bom-app\package.json: Unexpected token '', "{"name":""... is not valid JSON
Called directly on the same folder, detectPackageManager() returns { "name": "npm", "source": "default" } instead of pnpm from the packageManager field.
Expected behaviour
The BOM is ignored, as npm does: the script list shows hello, and the package manager line reads pnpm (from the packageManager field). A config.json with a BOM is read normally.
Cause
Three places pass the file content straight to JSON.parse, which rejects a leading U+FEFF:
getScripts()inworkspace.js;readPackageManagerField()inpackage-managers.js, which then falls back to the lockfile or npm without any message;readWorkspaceConfig()inconfig.js.
Suggested fix
- Remove a single leading
before parsing, in all three places, for example with a small shared helper that reads and parses a JSON file. Only the start of the file is affected, so a BOM-like character inside a string value is kept. - Add tests:
getScripts(),detectPackageManager()andreadWorkspaceConfig()each read a file that starts with a BOM.
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.13.1 and npm 10.9.2, Windows 11. The parsing code is the same on every platform.
- Ngôn ngữ chính
- JavaScript
- Star
- 0
- Fork
- 0
- Merge trung bình
- 43 phút
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modulane/dev-workspace-cli
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modulane/dev-workspace-cli#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 22/100
modulane/dev-workspace-cli#54 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Write the 1.0 documentationĐang mởenhancement help wanted
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 43/100
modulane/dev-workspace-cli#53 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Clean up legacy behaviourĐang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
modulane/dev-workspace-cli#52 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Freeze the public interfaceĐang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
modulane/dev-workspace-cli#51 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modulane/dev-workspace-cli
Issue tương tự
-
FEATURE REQUEST
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
linuxmint/cinnamon-spices-extensions#1193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ds-bot collides with dsh-argp: tool "recall" is already registered, Bot layer never activatesĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Fei2411/DeepSeek-Bot#703 ·
-
area:web first-timers-only good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
career-ops-hq/career-ops#6264 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
catppuccin/firefox#21 ·
-
[Server Submission]: Wiro AIĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
cline/mcp-marketplace#3394 ·