【架构优化】从 runtime.installNPMCLI 中拆出 npm 参数拼装 npmCLIInstallArgs 与安装结果启用 activateNPMStage

Đang mở
#485 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@fx-kurumi đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #487 của @fx-kurumi — đang mở

Đá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
30/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
tooling

Hướng nghiên cứu

Start in internal/runtime/cli_ondemand.go, where installNPMCLI mixes directory setup, npm argument assembly and stage activation. Check open pull request #487 first, since work on this split may already be under way. Done means npmCLIInstallArgs and activateNPMStage exist as private helpers with unit tests, installNPMCLI keeps its signature, and go test ./internal/runtime/ passes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

现状问题

internal/runtime/cli_ondemand.go 的 installNPMCLI 约 45 行,把三件事写在一个函数里:

  1. 准备安装目录与临时 stage 目录;
  2. 拼装 npm install 参数(--engine-strict / --engine-strict=false 依 RelaxEngines 切换)并执行;
  3. 校验 stage 内可执行文件、替换 current 目录、返回最终路径。

参数拼装是纯逻辑,却只能通过伪造 npm 可执行文件的集成测试间接覆盖;启用安装结果的逻辑也无法单独测试。

重构方案

  • 拆出纯函数 npmCLIInstallArgs(stage string, spec onDemandCLI) []string,负责参数拼装;
  • 拆出 activateNPMStage(parent, stage, binary string) (string, error),负责校验可执行文件、替换 current 并返回路径;
  • installNPMCLI 只保留目录准备、执行 npm 与调用上面两个函数,签名与调用方不变;参数顺序、报错文字逐字保持一致。

影响范围

仅 internal/runtime/cli_ondemand.go,包内私有函数,不影响对外接口和行为。

验证方式

  • 新增单元测试覆盖 npmCLIInstallArgs(严格/放宽 engines 两种)与 activateNPMStage(成功替换旧 current、缺可执行文件报错);
  • 现有 cli_ondemand_test.go 集成测试保持通过;
  • gofmt、go vet ./internal/runtime/、go test ./internal/runtime/。
Ngôn ngữ chính
Go
Star
141
Fork
28
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
113

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Tencent/LoopForge

Tất cả issue của Tencent/LoopForge

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.