Skip to content

docs: add npm registry note for OpenCode#586

Merged
ding113 merged 1 commit intodevfrom
docs/opencode-npm-registry-note
Jan 10, 2026
Merged

docs: add npm registry note for OpenCode#586
ding113 merged 1 commit intodevfrom
docs/opencode-npm-registry-note

Conversation

@ding113
Copy link
Owner

@ding113 ding113 commented Jan 10, 2026

Summary

Add a warning note to the OpenCode npm installation section advising users to avoid npm mirror registries (e.g., Taobao, cnpm), which may cause missing dependencies.

Problem

Users installing opencode-ai via third-party npm mirror registries may encounter missing dependency issues, leading to installation failures or runtime errors. This is a common issue in regions where npm mirrors are frequently used.

Related Issues:

Solution

Add a prominent note in the OpenCode installation section warning users about potential npm mirror registry issues:

  • Placed directly after the npm install command in both macOS/Linux and Windows sections
  • Translated into all 5 supported languages (en, zh-CN, zh-TW, ja, ru)
  • Directs users to the official npm registry if they encounter issues

Changes

Core Changes

  • src/app/[locale]/usage-doc/page.tsx - Add npm registry warning note display

i18n Changes

  • messages/en/usage.json - Add English translation for npm.note key
  • messages/zh-CN/usage.json - Add Simplified Chinese translation
  • messages/zh-TW/usage.json - Add Traditional Chinese translation
  • messages/ja/usage.json - Add Japanese translation
  • messages/ru/usage.json - Add Russian translation

Test Changes

  • tests/unit/usage-doc/opencode-usage-doc.test.tsx - Add test for npm mirror warning text and i18n key presence
  • tests/unit/usage-doc/usage-doc-page.test.tsx - Fix flaky test with improved cookie mocking

Testing

Automated Tests

  • Unit tests added for npm warning text verification
  • Unit tests verify i18n key exists in all 5 locales
  • Test improvements for cookie handling

Pre-commit Checklist

  • bun run lint - Passed
  • bun run typecheck - Passed
  • bun run test - Passed
  • bun run test:coverage - Passed
  • bun run build - Passed

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally
  • i18n translations provided for all 5 supported languages (zh-CN, zh-TW, en, ja, ru)

Description enhanced by Claude AI

@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

📝 Walkthrough

演进说明

在英文、日文、俄文、中文等五个语言文件中的 OpenCode npm 安装部分添加了新的 note 字段,同时在页面和测试中相应地添加了渲染和验证逻辑。

变更摘要

文件分组 变更说明
多语言翻译文件
messages/en/usage.json, messages/ja/usage.json, messages/ru/usage.json, messages/zh-CN/usage.json, messages/zh-TW/usage.json
opencode.installation.npm 对象中新增 note 字段,提示用户避免使用 npm 镜像源,建议使用官方 npm 仓库
UI 页面层
src/app/[locale]/usage-doc/page.tsx
在 Windows 和非 Windows 安装步骤后各添加一行代码以渲染新的 npm note 消息
单元测试 - 文档验证
tests/unit/usage-doc/opencode-usage-doc.test.tsx
新增断言检查 npm 镜像源相关文本的存在,添加跨语言环境的 opencode.installation.npm.note 翻译键验证
单元测试 - 页面测试
tests/unit/usage-doc/usage-doc-page.test.tsx
document.cookie 的直接赋值改为基于 getter 的 mock 方式,并在卸载后清理 cookie mock

评估代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 分钟

可能相关的 PR

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地总结了主要变更:为OpenCode的npm安装部分添加注册表注意事项。
Description check ✅ Passed 描述准确地说明了变更内容:在OpenCode的npm安装部分添加注意事项,涵盖5个本地化版本和单元测试扩展。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/opencode-npm-registry-note

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

📥 Commits

Reviewing files that changed from the base of the PR and between 11b2a01 and 6da9ff9.

📒 Files selected for processing (8)
  • messages/en/usage.json
  • messages/ja/usage.json
  • messages/ru/usage.json
  • messages/zh-CN/usage.json
  • messages/zh-TW/usage.json
  • src/app/[locale]/usage-doc/page.tsx
  • tests/unit/usage-doc/opencode-usage-doc.test.tsx
  • tests/unit/usage-doc/usage-doc-page.test.tsx
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

No emoji characters in any code, comments, or string literals

Files:

  • tests/unit/usage-doc/usage-doc-page.test.tsx
  • tests/unit/usage-doc/opencode-usage-doc.test.tsx
  • src/app/[locale]/usage-doc/page.tsx
**/*.{ts,tsx,jsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,jsx,js}: All user-facing strings must use i18n (5 languages supported: zh-CN, en, ja, ko, de). Never hardcode display text
Use path alias @/ to map to ./src/
Use Biome for code formatting with configuration: double quotes, trailing commas, 2-space indent, 100 character line width
Prefer named exports over default exports
Use next-intl for internationalization
Use Next.js 16 App Router with Hono for API routes

Files:

  • tests/unit/usage-doc/usage-doc-page.test.tsx
  • tests/unit/usage-doc/opencode-usage-doc.test.tsx
  • src/app/[locale]/usage-doc/page.tsx
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Place unit tests in tests/unit/, integration tests in tests/integration/, and source-adjacent tests in src/**/*.test.ts

Files:

  • tests/unit/usage-doc/usage-doc-page.test.tsx
  • tests/unit/usage-doc/opencode-usage-doc.test.tsx
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use React 19, shadcn/ui, Tailwind CSS, and Recharts for the UI layer

Files:

  • tests/unit/usage-doc/usage-doc-page.test.tsx
  • tests/unit/usage-doc/opencode-usage-doc.test.tsx
  • src/app/[locale]/usage-doc/page.tsx
🧠 Learnings (2)
📓 Common learnings
Learnt from: NieiR
Repo: ding113/claude-code-hub PR: 573
File: src/actions/model-prices.ts:275-335
Timestamp: 2026-01-10T06:20:04.478Z
Learning: In the `ding113/claude-code-hub` repository, Server Actions (files under `src/actions/*.ts`) currently return hardcoded Chinese error messages directly. This is a codebase-wide architectural decision that applies to all action files (e.g., model-prices.ts, users.ts, system-config.ts). Changing this pattern requires a coordinated i18n refactor across all Server Actions, which should be handled as a separate unified task rather than piecemeal changes in individual PRs.
📚 Learning: 2026-01-07T17:05:37.171Z
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-07T17:05:37.171Z
Learning: Applies to **/*.{ts,tsx,jsx,js} : All user-facing strings must use i18n (5 languages supported: zh-CN, en, ja, ko, de). Never hardcode display text

Applied to files:

  • tests/unit/usage-doc/opencode-usage-doc.test.tsx
🧬 Code graph analysis (1)
src/app/[locale]/usage-doc/page.tsx (1)
scripts/sync-settings-keys.js (2)
  • p (102-102)
  • t (72-72)
⏰ 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). (7)
  • GitHub Check: pr-label
  • GitHub Check: pr-review
  • GitHub Check: check-codex-status
  • GitHub Check: pr-description
  • GitHub Check: Docker Build Test
  • GitHub Check: 🌐 API Tests
  • GitHub Check: dev-build-deploy
🔇 Additional comments (11)
messages/ru/usage.json (1)

510-511: LGTM!i18n 翻译添加正确

新增的 opencode.installation.npm.note 翻译键结构合理,内容清晰地说明了避免使用 npm 镜像源的建议。与其他语言的翻译保持一致。

messages/zh-TW/usage.json (1)

506-507: LGTM!繁体中文翻译添加正确

opencode.installation.npm.note 的繁体中文翻译表达清晰,与其他语言版本保持语义一致。

messages/en/usage.json (1)

510-511: LGTM!英文翻译清晰准确

英文版本的注意事项描述清楚,既说明了问题(依赖缺失),又提供了解决方案(使用官方 registry)。

src/app/[locale]/usage-doc/page.tsx (3)

999-999: LGTM!Windows 安装部分的注意事项渲染正确

使用 t("opencode.installation.npm.note") 正确调用国际化翻译,样式使用 text-sm text-muted-foreground 适合提示性文本。


1049-1049: LGTM!非 Windows 平台的注意事项渲染一致

与 Windows 部分保持一致的实现方式,确保所有平台的用户都能看到 npm 镜像源的警告信息。代码复用合理。


999-999: 翻译键缺失 - 所有语言的消息文件都不包含该键

代码使用的翻译键 opencode.installation.npm.note 在所有支持的语言文件中均不存在(zh-CN、zh-TW、en、ru、ja)。需要在各语言的 messages/[locale]/usage.json 中添加该翻译键及其对应的翻译内容。

补充说明:仓库支持的语言为 zh-CN、zh-TW、en、ru、ja(共5种),无需添加 ko 和 de 的翻译。

⛔ Skipped due to learnings
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-07T17:05:37.171Z
Learning: Applies to **/*.{ts,tsx,jsx,js} : All user-facing strings must use i18n (5 languages supported: zh-CN, en, ja, ko, de). Never hardcode display text
Learnt from: NieiR
Repo: ding113/claude-code-hub PR: 539
File: src/app/[locale]/dashboard/_components/user/user-key-table-row.tsx:66-66
Timestamp: 2026-01-05T03:02:14.502Z
Learning: In the claude-code-hub project, the translations.actions.addKey field in UserKeyTableRowProps is defined as optional for backward compatibility, but all actual callers in the codebase provide the complete translations object. The field has been added to all 5 locale files (messages/{locale}/dashboard.json).
Learnt from: NieiR
Repo: ding113/claude-code-hub PR: 573
File: src/actions/model-prices.ts:275-335
Timestamp: 2026-01-10T06:20:04.478Z
Learning: In the `ding113/claude-code-hub` repository, Server Actions (files under `src/actions/*.ts`) currently return hardcoded Chinese error messages directly. This is a codebase-wide architectural decision that applies to all action files (e.g., model-prices.ts, users.ts, system-config.ts). Changing this pattern requires a coordinated i18n refactor across all Server Actions, which should be handled as a separate unified task rather than piecemeal changes in individual PRs.
tests/unit/usage-doc/opencode-usage-doc.test.tsx (2)

95-95: LGTM!测试断言合理

新增的断言 expect(text).toContain("npm mirror registries") 正确验证了注意事项在页面中的渲染。由于测试使用的是英文 locale,检查英文关键词是合适的。


116-116: LGTM!i18n 翻译键验证完善

新增的断言 expect(usageMessages).toHaveProperty("opencode.installation.npm.note") 确保所有支持的语言都包含新的翻译键,这是良好的 i18n 测试实践。

tests/unit/usage-doc/usage-doc-page.test.tsx (1)

65-68: 改进的 mock 模式和清理机制。

document.cookie 的模拟方式从直接赋值改为使用 Object.defineProperty 的 getter 模式是一个很好的改进,提高了测试的健壮性和隔离性。同时添加的 Reflect.deleteProperty 清理逻辑确保了测试之间不会产生副作用。

这种模式更加符合测试最佳实践,特别是在处理只读或配置受限的属性时。

Also applies to: 79-80

messages/ja/usage.json (1)

510-511: 日语翻译内容恰当。

日语翻译准确传达了原意,与其他语言环境的内容保持一致。提示用户避免使用 npm 镜像源以防止依赖缺失的建议表述清晰。

messages/zh-CN/usage.json (1)

506-507: 翻译内容准确清晰,所有语言环境文件已完整更新。

新增的 npm 安装提示内容表述准确,有效提醒用户避免使用 npm 镜像源以防止依赖缺失问题。已验证项目所有语言环境文件(zh-CN、en、ja、ru、zh-TW)均包含该字段和相应翻译。


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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ding113, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the OpenCode installation documentation by adding a crucial warning about the use of npm mirror registries, which can lead to dependency issues. The change is fully internationalized across five languages and integrated into the user interface, ensuring that users receive clear guidance regardless of their locale. Additionally, the update includes improvements to the testing suite for robustness.

Highlights

  • Documentation Update: A new note has been added to the OpenCode npm installation instructions, advising users to avoid npm mirror registries due to potential missing dependencies.
  • Internationalization: The new npm registry note has been translated and integrated into five locales: English, Japanese, Russian, Simplified Chinese, and Traditional Chinese.
  • UI Integration: The npm registry warning is now displayed on the usage documentation page for both Windows and general npm installation methods.
  • Test Enhancements: Unit tests have been updated to verify the presence of the new npm registry note and to improve cookie handling for better test isolation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ding113 ding113 merged commit 64b6ba2 into dev Jan 10, 2026
11 of 12 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Jan 10, 2026
@github-actions github-actions bot added size/S Small PR (< 200 lines) documentation Improvements or additions to documentation area:i18n area:docs labels Jan 10, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds an important note to the OpenCode installation documentation regarding the use of npm mirror registries, and correctly updates the i18n files and unit tests to reflect this change. The changes are logical and well-executed. Additionally, a test file was refactored to improve how document.cookie is mocked. My review includes a couple of suggestions for improving maintainability: one to reduce code duplication on the documentation page, and another to make the test mocking more idiomatic using Vitest's built-in features.

<CodeBlock language="powershell" code={`npm install -g opencode-ai`} />
</div>

<p className="text-sm text-muted-foreground">{t("opencode.installation.npm.note")}</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While this change is correct, I noticed that the entire npm installation section, including this new note, is duplicated for Windows (here) and for macOS/Linux (around line 1049). This duplication can make future updates more difficult and error-prone.

To improve maintainability, consider refactoring the npm installation UI into a separate component that accepts the shell language (powershell or bash) as a prop. This would centralize the logic and markup for this section.

For example:

const NpmInstallSection = ({ lang }: { lang: 'powershell' | 'bash' }) => {
  const t = useTranslations("usage");
  return (
    <>
      <div className="space-y-3">
        <h5 className="font-semibold text-foreground">
          {t("opencode.installation.npm.title")}
        </h5>
        <p>{t("opencode.installation.npm.description")}</p>
        <CodeBlock language={lang} code={'npm install -g opencode-ai'} />
      </div>
      <p className="text-sm text-muted-foreground">{t("opencode.installation.npm.note")}</p>
    </>
  );
}

While a full refactor is outside the scope of this PR, it's a good improvement to keep in mind for the future.

Comment on lines +65 to +68
Object.defineProperty(document, "cookie", {
configurable: true,
get: () => "auth-token=test-token",
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using Object.defineProperty is a good improvement for mocking document.cookie. To make the test more idiomatic with Vitest, consider using vi.spyOn. It provides a clear API for mocking and restoring spies. You can then replace the manual cleanup on line 80 with cookieSpy.mockRestore().

    const cookieSpy = vi
      .spyOn(document, "cookie", "get")
      .mockReturnValue("auth-token=test-token");


await unmount();

Reflect.deleteProperty(document, "cookie");
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

If you adopt the vi.spyOn approach suggested for lines 65-68, this manual cleanup can be replaced with a call to cookieSpy.mockRestore() for better consistency with Vitest's testing patterns.

    cookieSpy.mockRestore();

@github-actions
Copy link
Contributor

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR.

PR Size: S

  • Lines changed: 26
  • Files changed: 8

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Codex AI

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

  • Identified PR #586 (docs: add npm registry note for OpenCode): +20/-6 across 8 files → Size S.
  • Applied PR label size/S.
  • Reviewed the diff across all changed files with the 6 required perspectives; no issues met the reporting threshold (confidence < 80), so no inline comments were posted.
  • Submitted the required PR review summary via gh pr review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs area:i18n documentation Improvements or additions to documentation size/S Small PR (< 200 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant