fix: 修复pnpmv11版本下脚本无法使用的问题 - #674
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's Guide此 PR 更新了 create-karin 项目初始化流程:在运行初始化脚本之前,从生成的 package.json 中移除不兼容的 devEngines 字段,并通过将 stdout/stderr 统一规范为字符串来增强 exec 工具的健壮性,从而修复在 pnpm v11 下的脚本执行问题。 更新后的项目初始化和 exec 行为的时序图sequenceDiagram
actor User
participant createProject
participant fs
participant exec
participant child_process_exec as child_process_exec
User->>createProject: createProject(dir, karinVersion, httpAuthKey, wsAuthKey)
createProject->>fs: readFileSync(package_json_path, utf-8)
createProject->>createProject: JSON.parse(content)
createProject->>createProject: [if pkg.devEngines]
createProject->>createProject: delete pkg.devEngines
createProject->>fs: writeFileSync(package_json_path, JSON.stringify(pkg, null, 2))
createProject->>User: console.log(devEngines removed)
createProject->>exec: exec("npx karin init", { cwd: dir })
exec->>child_process_exec: exec(command, options, callback)
child_process_exec-->>exec: callback(status, error, stdout, stderr)
exec->>exec: [if typeof stdout !== string] stdout = String(stdout)
exec->>exec: [if typeof stderr !== string] stderr = String(stderr)
exec-->>createProject: { status, error, stdout, stderr }
createProject-->>User: initialization completed message
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your Experience前往你的 dashboard 以:
Getting HelpOriginal review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR updates the create-karin project initialization workflow to remove an incompatible devEngines field from the generated package.json before running initialization scripts, and hardens the exec utility by normalizing stdout/stderr to strings, fixing script execution issues under pnpm v11. Sequence diagram for updated project initialization and exec behaviorsequenceDiagram
actor User
participant createProject
participant fs
participant exec
participant child_process_exec as child_process_exec
User->>createProject: createProject(dir, karinVersion, httpAuthKey, wsAuthKey)
createProject->>fs: readFileSync(package_json_path, utf-8)
createProject->>createProject: JSON.parse(content)
createProject->>createProject: [if pkg.devEngines]
createProject->>createProject: delete pkg.devEngines
createProject->>fs: writeFileSync(package_json_path, JSON.stringify(pkg, null, 2))
createProject->>User: console.log(devEngines removed)
createProject->>exec: exec("npx karin init", { cwd: dir })
exec->>child_process_exec: exec(command, options, callback)
child_process_exec-->>exec: callback(status, error, stdout, stderr)
exec->>exec: [if typeof stdout !== string] stdout = String(stdout)
exec->>exec: [if typeof stderr !== string] stderr = String(stderr)
exec-->>createProject: { status, error, stdout, stderr }
createProject-->>User: initialization completed message
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe project creation flow removes ChangesProject metadata cleanup
Command output normalization
Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
你可以通过以下命令安装该版本: |
There was a problem hiding this comment.
Hey - 我已经给出了一些高层次的反馈:
- 新的 package.json 变更逻辑假设该文件一定存在且包含有效的 JSON;建议将读取/解析/写入的过程包裹在 try/catch 中,如果解析失败则优雅地失败或者跳过删除 devEngines 字段的操作。
- 为了保持 CLI 输出的一致性,建议在报告已从 package.json 中移除 devEngines 字段时,使用同样的 spinner/日志机制,而不是直接使用原始的 console.log。
给 AI Agents 的提示
Please address the comments from this code review:
## Overall Comments
- 新的 package.json 变更逻辑假设该文件一定存在且包含有效的 JSON;建议将读取/解析/写入的过程包裹在 try/catch 中,如果解析失败则优雅地失败或者跳过删除 devEngines 字段的操作。
- 为了保持 CLI 输出的一致性,建议在报告已从 package.json 中移除 devEngines 字段时,使用同样的 spinner/日志机制,而不是直接使用原始的 console.log。帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The new package.json mutation logic assumes the file exists and contains valid JSON; consider wrapping the read/parse/write sequence in a try/catch and failing gracefully or skipping the devEngines removal if parsing fails.
- To keep output consistent in the CLI, consider using the same spinner/logging mechanism instead of a raw console.log when reporting that the devEngines field has been removed from package.json.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new package.json mutation logic assumes the file exists and contains valid JSON; consider wrapping the read/parse/write sequence in a try/catch and failing gracefully or skipping the devEngines removal if parsing fails.
- To keep output consistent in the CLI, consider using the same spinner/logging mechanism instead of a raw console.log when reporting that the devEngines field has been removed from package.json.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
通过清理不兼容的
package.json字段,并增强命令执行输出的处理方式,确保项目初始化在较新的 pnpm 版本下正常工作。Bug 修复:
package.json中移除devEngines字段,以避免 pnpm v11 在执行脚本时出现问题。exec工具中将stderr统一规范为字符串类型,防止在消费命令输出时因类型问题导致的故障。Original summary in English
Summary by Sourcery
Ensure project initialization works under newer pnpm by cleaning incompatible package.json fields and making exec output handling more robust.
Bug Fixes:
Summary by CodeRabbit