软件包概述
¥Package Overview
这个 monorepo 包含两个主要包:@google/gemini-cli和@google/gemini-cli-core。
¥This monorepo contains two main packages: @google/gemini-cli and @google/gemini-cli-core.
@google/gemini-cli
¥@google/gemini-cli
这是 Gemini CLI 的主软件包。它负责用户界面、命令解析以及所有其他面向用户的功能。
¥This is the main package for the Gemini CLI. It is responsible for the user interface, command parsing, and all other user-facing functionality.
此软件包发布后,会被打包成一个可执行文件。此文件包含软件包的所有依赖项,包括@google/gemini-cli-core。这意味着用户是否使用npm install -g @google/gemini-cli或者直接运行npx @google/gemini-cli,他们正在使用这个单一的、独立的可执行文件。
¥When this package is published, it is bundled into a single executable file. This bundle includes all of the package's dependencies, including @google/gemini-cli-core. This means that whether a user installs the package with npm install -g @google/gemini-cli or runs it directly with npx @google/gemini-cli, they are using this single, self-contained executable.
@google/gemini-cli-core
¥@google/gemini-cli-core
此包包含与 Gemini API 交互的核心逻辑。它负责发出 API 请求、处理身份验证以及管理本地缓存。
¥This package contains the core logic for interacting with the Gemini API. It is responsible for making API requests, handling authentication, and managing the local cache.
此软件包未捆绑。发布时,它将作为带有自身依赖项的标准 Node.js 软件包发布。如果需要,它可以在其他项目中作为独立软件包使用。所有已编译的 js 代码dist文件夹包含在包中。
¥This package is not bundled. When it is published, it is published as a standard Node.js package with its own dependencies. This allows it to be used as a standalone package in other projects, if needed. All transpiled js code in the dist folder is included in the package.
NPM 工作区
¥NPM Workspaces
该项目使用NPM 工作区管理此 monorepo 中的包。这允许我们从项目根目录管理依赖项并跨多个包运行脚本,从而简化了开发。
¥This project uses NPM Workspaces to manage the packages within this monorepo. This simplifies development by allowing us to manage dependencies and run scripts across multiple packages from the root of the project.
工作原理
¥How it Works
根package.json文件定义了该项目的工作区:
¥The root package.json file defines the workspaces for this project:
{
"workspaces": ["packages/*"]
}
这告诉 NPM 文件夹内的任何packages目录是一个单独的包,应该作为工作区的一部分进行管理。
¥This tells NPM that any folder inside the packages directory is a separate package that should be managed as part of the workspace.
工作区的好处
¥Benefits of Workspaces
简化的依赖管理: 跑步
npm install从项目根目录运行将安装工作区中所有包的所有依赖项并将它们链接在一起。这意味着您不需要运行npm install在每个包的目录中。¥Simplified Dependency Management: Running
npm installfrom the root of the project will install all dependencies for all packages in the workspace and link them together. This means you don't need to runnpm installin each package's directory.自动链接:工作区内的包可以相互依赖。运行
npm install之后,NPM 会自动在软件包之间创建符号链接。这意味着,当你对一个软件包进行更改时,这些更改会立即被依赖它的其他软件包所使用。¥Automatic Linking: Packages within the workspace can depend on each other. When you run
npm install, NPM will automatically create symlinks between the packages. This means that when you make changes to one package, the changes are immediately available to other packages that depend on it.简化脚本执行:您可以使用以下方式从项目根目录运行任何包中的脚本
--workspace标志。例如,要运行build脚本中的cli包,你可以运行npm run build --workspace @google/gemini-cli。¥Simplified Script Execution: You can run scripts in any package from the root of the project using the
--workspaceflag. For example, to run thebuildscript in theclipackage, you can runnpm run build --workspace @google/gemini-cli.