Skip to content

fix: 修复pnpmv11版本下脚本无法使用的问题 - #674

Merged
yusheng929 merged 1 commit into
mainfrom
ys-cli
Aug 13, 2026
Merged

yusheng929 merged 1 commit into
mainfrom
ys-cli

Conversation

@yusheng929

@yusheng929 yusheng929 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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:

  • Remove devEngines from generated package.json during project creation to avoid pnpm v11 script execution issues.
  • Normalize stderr to a string in the exec utility to prevent type-related failures when consuming command output.

Summary by CodeRabbit

  • Bug Fixes
    • Improved project setup by removing unsupported development engine settings after installing dependencies.
    • Improved command output handling so error messages are consistently displayed as text.

@sourcery-ai

sourcery-ai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor
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
Loading

File-Level Changes

Change Details Files
确保新创建的项目在运行初始化脚本前,其 package.json 与 pnpm v11 兼容。
  • 在初始化过程中,从新创建的项目目录中读取 package.json。
  • 解析 JSON 内容并检查是否存在 devEngines 字段。
  • 当存在 devEngines 字段时将其删除,以避免与 pnpm v11 的兼容性问题。
  • 将清理后的 package.json 以带缩进的 JSON 格式写回磁盘。
  • 当检测到并移除 devEngines 时,在控制台输出一条日志消息。
packages/create-karin/src/project.ts
通过始终以字符串形式返回 stdout 和 stderr 来增强 exec 工具的健壮性。
  • 当底层 exec 调用返回非字符串类型的值时,将 stdout 规范化为字符串。
  • 当底层 exec 调用返回非字符串类型的值时,将 stderr 规范化为字符串。
  • 在已解析的 Promise 中,与 status 和 error 一同返回规范化后的 stdout 和 stderr。
packages/create-karin/src/utils/exec.ts

Possibly linked issues

  • #Bug: 最新版karin 使用pnpm app运行时 报错:本 PR 调整了 exec 对 stderr 的处理方式并移除了 devEngines,修复了 pnpm v11 下脚本错误,例如已报告的路径参数相关 bug。

Tips and commands

Interacting with Sourcery

  • 触发新的代码审查: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论即可继续讨论。
  • 从审查评论生成 GitHub Issue: 通过回复某条审查评论让 Sourcery 基于该评论创建一个 Issue。你也可以在审查评论下回复 @sourcery-ai issue 来从该评论创建 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任何位置写上 @sourcery-ai,即可随时生成一个标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 描述中任何位置写上 @sourcery-ai summary,即可在指定位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来在任何时候(重新)生成摘要。
  • 生成审查者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可在任何时候(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。适用于你已经处理完所有评论且不再希望看到它们的情况。
  • 取消所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss,即可取消所有现有的 Sourcery 审查。特别适用于你希望从头开始一次新的审查——别忘了再评论 @sourcery-ai review 来触发新的审查!

Customizing Your Experience

前往你的 dashboard 以:

  • 启用或禁用审查功能,例如由 Sourcery 生成的 Pull Request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

Getting Help

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This 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 behavior

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
Loading

File-Level Changes

Change Details Files
Ensure newly created projects have pnpm v11-compatible package.json before running initialization scripts.
  • Read package.json from the newly created project directory during initialization.
  • Parse the JSON content and check for the presence of the devEngines field.
  • Delete the devEngines field when present to avoid compatibility issues with pnpm v11.
  • Write the cleaned package.json back to disk with pretty-printed JSON formatting.
  • Log a message to the console when devEngines is detected and removed.
packages/create-karin/src/project.ts
Make the exec utility robust by always returning stdout and stderr as strings.
  • Normalize stdout to a string when the underlying exec call returns a non-string value.
  • Normalize stderr to a string when the underlying exec call returns a non-string value.
  • Return the normalized stdout and stderr along with status and error in the resolved promise.
packages/create-karin/src/utils/exec.ts

Possibly linked issues

  • #Bug: 最新版karin 使用pnpm app运行时 报错: PR adjusts exec stderr handling and removes devEngines, fixing pnpm v11 script errors like the reported path argument bug.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d7796e64-6855-46bf-8121-2211da705c44

📥 Commits

Reviewing files that changed from the base of the PR and between 66fa9a2 and 69889bc.

📒 Files selected for processing (2)
  • packages/create-karin/src/project.ts
  • packages/create-karin/src/utils/exec.ts

📝 Walkthrough

Walkthrough

The project creation flow removes devEngines from the generated package.json. The asynchronous exec helper converts non-string stderr values to strings before returning results.

Changes

Project metadata cleanup

Layer / File(s) Summary
Remove generated devEngines metadata
packages/create-karin/src/project.ts
createProject parses and rewrites package.json after installing node-karin when devEngines is present. It logs the removal.

Command output normalization

Layer / File(s) Summary
Normalize stderr results
packages/create-karin/src/utils/exec.ts
exec converts non-string stderr callback values with String() before resolving the command result.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ys-cli

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yusheng929
yusheng929 merged commit bf601ab into main Aug 13, 2026
3 of 4 checks passed
@yusheng929
yusheng929 deleted the ys-cli branch August 13, 2026 13:09
@github-actions

Copy link
Copy Markdown
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/node-karin@69889bc -w

@github-actions github-actions Bot mentioned this pull request Aug 13, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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。

Sourcery 对开源项目是免费的——如果你觉得我们的代码评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant