Skip to content

Conversation

DDDDD12138
Copy link
Contributor

@DDDDD12138 DDDDD12138 commented Jul 14, 2025

这个 PR 做了什么? (简要描述所做更改)

错误原因

install_deps 函数没有确保在正确的项目目录中执行包管理器命令,导致 pnpm install 无法找到 package.json 文件,从而失败

解决方案

  • 修改 install_deps 函数

    • 添加 project_path: &str 参数
    • 在执行安装命令前,使用 env::set_current_dir(project_path) 切换到项目目录
  • 更新函数调用

    • project.rs 中调用 install_deps 时传入项目路径参数

验证步骤

# 1. 在 Taro 根目录执行
cd /root/github/taro

# 2. 安装 Rust 工具链(如果还没安装)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.bashrc

# 3. 安装依赖
pnpm install

# 4. 构建 Rust 绑定
pnpm run build:binding:debug

# 5. 构建项目
pnpm run build

# 6. 链接 CLI 包
cd packages/taro-cli
pnpm link --global

# 7. 确认链接状态
which taro
# 如果显示包含 pnpm 的路径(如 /root/.local/share/pnpm/taro),说明链接成功

# 8. 切换到任意测试目录
cd /tmp

# 9. 测试本地 CLI
taro init test-app

结果

root@ZHIQING-DESKTOP:~/github/taro# taro init test-app
👽 Taro v4.1.4



Taro 即将创建一个新项目!
Need help? Go and open issue: https://tls.jd.com/taro-issue-helper

? 请输入项目介绍 
? 请选择框架 React
? 是否需要使用 TypeScript ? Yes
? 是否需要编译为 ES5 ? No
? 请选择 CSS 预处理器(Sass/Less/Stylus) Less
? 请选择包管理工具 pnpm
? 请选择编译工具 Vite
? 请选择模板源 Gitee(最快)
✔ 拉取远程模板仓库成功!
? 请选择模板 默认模板

✔ 创建项目: test-app
✔ 创建文件: /root/github/taro/test-app/commitlint.config.mjs
✔ 创建文件: /root/github/taro/test-app/src/index.html
✔ 创建文件: /root/github/taro/test-app/src/app.ts
✔ 创建文件: /root/github/taro/test-app/src/app.less
✔ 创建文件: /root/github/taro/test-app/src/pages/index/index.tsx
✔ 创建文件: /root/github/taro/test-app/src/pages/index/index.config.ts
✔ 创建文件: /root/github/taro/test-app/src/pages/index/index.less
✔ 创建文件: /root/github/taro/test-app/src/app.config.ts
✔ 创建文件: /root/github/taro/test-app/.husky/commit-msg
✔ 创建文件: /root/github/taro/test-app/.eslintrc
✔ 创建文件: /root/github/taro/test-app/babel.config.js
✔ 创建文件: /root/github/taro/test-app/package.json
✔ 创建文件: /root/github/taro/test-app/types/global.d.ts
✔ 创建文件: /root/github/taro/test-app/.gitignore
✔ 创建文件: /root/github/taro/test-app/.env.development
✔ 创建文件: /root/github/taro/test-app/tsconfig.json
✔ 创建文件: /root/github/taro/test-app/project.config.json
✔ 创建文件: /root/github/taro/test-app/stylelint.config.mjs
✔ 创建文件: /root/github/taro/test-app/config/prod.ts
✔ 创建文件: /root/github/taro/test-app/config/dev.ts
✔ 创建文件: /root/github/taro/test-app/config/index.ts
✔ 创建文件: /root/github/taro/test-app/.editorconfig
✔ 创建文件: /root/github/taro/test-app/.env.production
✔ 创建文件: /root/github/taro/test-app/.env.test

✔ 初始化 git 成功
执行安装项目依赖 pnpm install, 需要一会儿...
Done in 7.2s using pnpm v10.13.0
✔ 安装项目依赖成功
创建项目 test-app 成功!
请进入项目目录 test-app 开始工作吧!😝

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有平台( cli 创建项目)

Summary by CodeRabbit

  • 新功能
    • 依赖安装过程现在会在指定的项目目录下执行,确保依赖被正确安装到对应项目中。

Copy link

coderabbitai bot commented Jul 14, 2025

"""

Walkthrough

本次更改将依赖安装函数 install_deps 的调用方式从传递两个参数(npm 类型和回调)调整为传递三个参数(npm 类型、项目路径字符串和回调)。并在依赖安装函数内部,新增了切换当前工作目录到指定项目路径的逻辑,以确保依赖安装命令在正确的目录下执行。

Changes

文件/文件组 变更摘要
项目初始化调用修改
crates/taro_init/src/project.rs
install_deps 调用增加了项目路径参数
依赖安装函数实现修改
crates/taro_init/src/utils.rs
install_deps 函数签名新增 project_path 参数,并在函数内部切换工作目录到该路径

Sequence Diagram(s)

sequenceDiagram
    participant Project
    participant Utils

    Project->>Utils: install_deps(npm, project_path, cb)
    Utils->>Utils: set_current_dir(project_path)
    Utils->>Utils: 执行依赖安装命令
    Utils->>Project: 调用回调 cb
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Assessment against linked issues

Objective Addressed Explanation
修复 taro init 阶段依赖安装失败,确保依赖安装命令在正确目录下执行(#18018

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes identified.

Poem

🐇
项目初始化,依赖来安,
跳进目录,不再迷茫。
一行代码,世界变宽,
兔子挥爪,问题扫光!

"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24c86c7 and 86a6702.

📒 Files selected for processing (2)
  • crates/taro_init/src/project.rs (1 hunks)
  • crates/taro_init/src/utils.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/taro_init/src/project.rs
  • crates/taro_init/src/utils.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.99%. Comparing base (b1e8dc9) to head (86a6702).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #18019   +/-   ##
=======================================
  Coverage   54.99%   54.99%           
=======================================
  Files         417      417           
  Lines       21696    21696           
  Branches     5361     5365    +4     
=======================================
  Hits        11931    11931           
+ Misses       8116     8081   -35     
- Partials     1649     1684   +35     
Flag Coverage Δ
taro-cli 72.56% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This was referenced Jul 19, 2025
@Single-Dancer Single-Dancer added this to the 4.1.5 milestone Jul 28, 2025
@Single-Dancer Single-Dancer force-pushed the fix/install-deps-working-directory branch from 24c86c7 to 86a6702 Compare July 28, 2025 11:26
@Single-Dancer Single-Dancer merged commit 651e9d4 into NervJS:main Jul 28, 2025
24 checks passed
This was referenced Aug 2, 2025
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.

Taro init fails at install stage (安装项目依赖失败,请自行重新安装!)
2 participants