Skip to main content

Git 协议

git: 协议直接从 git 存储库获取包。当你需要使用尚未发布到 npm 注册表的软件包版本时,这很有用。

¥The git: protocol fetches packages directly from a git repository. This is useful when you need to use a version of a package that has not been published to the npm registry.

yarn add typanion@git@github.com/arcanis/typanion.git

打包

¥Packing

目标存储库不会按原样使用 - 它将首先使用 pack 进行打包。

¥The target repository won't be used as-is - it will first be packed using pack.

信息

为了确保输出与链接存储库发布后的样子相同,打包将查看其配置以决定使用哪个包管理器。

¥To be sure the output is identical to what the linked repository would look like after being published, the packing will look at its configuration to decide which package manager to use.

换句话说,如果有 yarn.lock,则使用 Yarn 打包项目,如果有 package-lock.json,则使用 npm,如果有 pnpm-lock.yaml,则使用 pnpm。

¥In other words, the project will be packed using Yarn if there's a yarn.lock, npm if there's a package-lock.json, or pnpm if there's a pnpm-lock.yaml.

提交固定

¥Commit pinning

你可以使用其中一个关键字明确请求标签、提交、分支或 semver 标签(如果你缺少关键字,Yarn 将查找似乎匹配的第一个内容,如以前的版本):

¥You can explicitly request a tag, commit, branch, or semver tag, by using one of those keywords (if you're missing the keyword, Yarn will look for the first thing that seems to match, as in prior versions):

git@github.com:yarnpkg/berry.git#tag=@yarnpkg/cli/2.2.0
git@github.com:yarnpkg/berry.git#commit=a806c88
git@github.com:yarnpkg/berry.git#head=master

工作区支持

¥Workspaces support

只要远程存储库使用 Yarn(或 npm,在这种情况下必须在系统上安装 npm@>=7.x),就可以克隆工作区:

¥Workspaces can be cloned as long as the remote repository uses Yarn (or npm, in which case npm@>=7.x has to be installed on the system):

git@github.com:yarnpkg/berry.git#workspace=@yarnpkg/shell&tag=@yarnpkg/shell/2.1.0
警告

并非所有包管理器都支持从 git 存储库安装工作区;如果你的包要发布,则不应依赖 dependencies 字段中的此功能。

¥Not all package managers support installing workspaces from git repositories; you shouldn't rely on this feature in your dependencies field if your package is meant to be published.