繁体   English   中英

如何在 Yarn 中从 github repo 安装 package

[英]How to install package from github repo in Yarn

当我使用npm install fancyapps/fancybox#v2.6.1 --save时,将安装 fancybox package at v2.6.1 标签。 文档中描述了此行为

我想问一下,如何用yarn做到这一点?

这个命令是正确的选择吗? yarn docs中没有关于这种格式的任何内容。

yarn add fancyapps/fancybox#v2.6.1

您可以通过指定远程 URL(HTTPS 或 SSH)将任何 Git 存储库(或 tarball)添加为yarn的依赖项:

yarn add <git remote url> installs a package from a remote git repository.
yarn add <git remote url>#<branch/commit/tag> installs a package from a remote git repository at specific git branch, git commit or git tag.
yarn add https://my-project.org/package.tgz installs a package from a remote gzipped tarball.

这里有些例子:

yarn add https://github.com/fancyapps/fancybox [remote url]
yarn add ssh://github.com/fancyapps/fancybox#3.0  [branch]
yarn add https://github.com/fancyapps/fancybox#5cda5b529ce3fb6c167a55d42ee5a316e921d95f [commit]

(注意:Fancybox v2.6.1 在 Git 版本中不可用。)

要同时支持 npm 和 yarn,您可以使用 git+url 语法:

git+https://github.com/owner/package.git#commithashortagorbranch
git+ssh://github.com/owner/package.git#commithashortagorbranch

对于 ssh 样式的 url,只需在 url 前添加 ssh:

yarn add ssh://<whatever>@<xxx>#<branch,tag,commit>

这在这里描述: https : //yarnpkg.com/en/docs/cli/add#toc-adding-dependencies

例如:

yarn add https://github.com/novnc/noVNC.git#0613d18

对于GitHub (或类似)私有存储库:

yarn add 'ssh://git@github.com:myproject.git#<branch,tag,commit>'
npm install 'ssh://git@github.com:myproject.git#<branch,tag,commit>'

我对 github 存储库使用这种短格式:

yarn add github_user/repository_name#commit_hash

纱线 2

从远程 URL 安装在Yarn 2 中略有变化。 具体来说, 远程 URL 必须以包名作为前缀 所以对于 github 这意味着:

yarn add '<package name>@https://github.com/<github user>/<github repo>'

确保<package name>与 repo 的package.json文件的"name"字段中的值匹配。

要定位特定分支,请通过 URL 片段添加head=<branch>commit=<full commit hash>

yarn add '<package name>@https://github.com/<github user>/<github repo>#head=<branch name>'

如果您尝试从 github 上的 Yarn monorepo 安装单个包,您可以将workspace=<package name>到 URL 片段:

yarn add '<package name>@https://github.com/<github user>/<github repo>#head=<branch name>&workspace=<package name>'

对于最新版本的 Yarn,它们在 URL 之前需要一个 package 名称。如果您正在安装一个发布到 Github 的私有 package 包,则语法如下所示:

yarn add @organization/packagename@https://github.com/organization/packagename

这应该在 package.json 中产生这一行:

"@organization/packagename": "https://github.com/organization/packagename"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM