在package.json中使用git URL依赖分支或标记?

本文介绍了如何在package.json中使用git URL来依赖特定的分支或标签。从npm 1.1.65版本开始,可以直接使用'foo': 'user/foo-project'格式引用GitHub URL,并通过#commit-ish指定分支或标签。例如,'mocha': 'visionmedia/mocha#4727d357ea'表示引用mocha的特定提交。
摘要由CSDN通过智能技术生成

本文翻译自:Depend on a branch or tag using a git URL in a package.json?

Say I've forked a node module with a bugfix and I want to use my fixed version, on a feature branch of course, until the bugfix is merged and released. 假设我已经使用错误修复分叉了一个节点模块,我想在功能分支上使用我的固定版本,直到错误修复被合并和发布。

How would I reference my fixed version in the dependencies of my package.json ? 我如何在package.jsondependencies中引用我的固定版本?


#1楼

参考:https://stackoom.com/question/16bYX/在package-json中使用git-URL依赖分支或标记


#2楼

From the npm docs : 来自npm文档

git://github.com/<user>/<project>.git#<branch>

git://github.com/<user>/<project>.git#feature\/<branch>

As of NPM version 1.1.65, you can do this: 从NPM版本1.1.65开始,您可以这样做:

<user>/<project>#<branch>

#3楼

per @dantheta's comment: 根据@ dantheta的评论:

As of npm 1.1.65, Github URL can be more concise user/project. 从npm 1.1.65开始,Github URL可以更简洁的用户/项目。 npmjs.org/doc/files/package.json.html You can attach the branch like user/project#branch npmjs.org/doc/files/package.json.html您可以附加分支,如user / project#branch

So 所以

"babel-eslint": "babel/babel-eslint",

Or for tag v1.12.0 on jscs: 或者对于jscs上的标签v1.12.0:

"jscs": "jscs-dev/node-jscs#v1.12.0",

Note, if you use npm --save, you'll get the longer git 注意,如果你使用npm --save,你会得到更长的git

From https://docs.npmjs.com/files/package.json#git-urls-as-dependencies 来自https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Git URLs as Dependencies Git URL作为依赖项

Git urls can be of the form: Git网址可以是以下形式:

git://github.com/user/project.git#commit-ish git+ssh://user@hostname:project.git#commit-ish git+ssh://user@hostname/project.git#commit-ish git+ http://user@hostname/project/blah.git#commit-ish git+ https://user@hostname/project/blah.git#commit-ish git://github.com/user/project.git#commit-ish git + ssh:// user @ hostname:project.git#commit-ish git + ssh://user@hostname/project.git#commit- ish git + http://user@hostname/project/blah.git#commit-ish git + https://user@hostname/project/blah.git#commit-ish

The commit-ish can be any tag, sha, or branch which can be supplied as an argument to git checkout. commit-ish可以是任何标记,sha或分支,可以作为git checkout的参数提供。 The default is master. 默认值为master。

GitHub URLs GitHub网址

As of version 1.1.65, you can refer to GitHub urls as just "foo": "user/foo-project". 从版本1.1.65开始,您可以将GitHub URL称为“foo”:“user / foo-project”。 Just as with git URLs, a commit-ish suffix can be included. 与git URL一样,可以包含commit-ish后缀。 For example: 例如:

{ "name": "foo", {“name”:“foo”,
"version": "0.0.0", “版本”:“0.0.0”,
"dependencies": { "express": "visionmedia/express", "mocha": "visionmedia/mocha#4727d357ea" } } “依赖”:{“express”:“visionmedia / express”,“mocha”:“visionmedia / mocha#4727d357ea”}}


#4楼

If you want to use devel or feature branch, or you haven't published a certain package to the NPM registry, or you can't because it's a private module, then you can point to a git:// URI instead of a version number in your package.json : 如果你想使用develfeature分支,或者你没有将某个包发布到NPM注册表,或者你不能因为它是私有模块,那么你可以指向一个git:// URI而不是一个版本package.json

"dependencies": {
   "public": "git://github.com/user/repo.git#ref",
   "private": "git+ssh://git@github.com:user/repo.git#ref"
}

The #ref portion is optional, and it can be a branch (like master ), tag (like 0.0.1 ) or a partial or full commit id. #ref部分是可选的,它可以是分支(如master ),标记(如0.0.1 )或部分或完整的提交ID。


#5楼

On latest version of NPM you can just do: 在最新版本的NPM上你可以做到:

npm install gitAuthor/gitRepo#tag

If the repo is a valid NPM package it will be auto-aliased in package.json as: 如果repo是一个有效的NPM包,它将在package.json中自动别名为:

{ "NPMPackageName": "gitAuthor/gitRepo#tag" }

If you could add this to @justingordon 's answer there is no need for manual aliasing now ! 如果您可以将此添加到@justingordon的答案,那么现在就不需要手动别名了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值