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

本文翻译自: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//.git#

git://github.com//.git#feature\/

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

/#

#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://[email protected]: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的答案,那么现在就不需要手动别名了!

你可能感兴趣的:(在package.json中使用git URL依赖分支或标记?)