npm-diff
选择命令行版本:
See Details
目录
概要
¥Synopsis
npm diff [...<paths>]
描述
¥Description
与其对应的 git diff
类似,此命令将打印发布到 npm 注册表的包的文件差异补丁。
¥Similar to its git diff
counterpart, this command will print diff patches of files for packages published to the npm registry.
-
npm diff --diff=<spec-a> --diff=<spec-b>
使用注册表说明符比较两个包版本,例如:
npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0
。也可以比较任何包的复刻,例如:npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0
。¥Compares two package versions using their registry specifiers, e.g:
npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0
. It's also possible to compare across forks of any package, e.g:npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0
.可以使用任何有效的规范,因此也可以比较目录或 git 存储库,例如:
npm diff --diff=pkg@latest --diff=./packages/pkg
¥Any valid spec can be used, so that it's also possible to compare directories or git repositories, e.g:
npm diff --diff=pkg@latest --diff=./packages/pkg
这是一个比较注册表中名为
abbrev
的包的两个不同版本的示例:¥Here's an example comparing two different versions of a package named
abbrev
from the registry:npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1成功后,输出如下所示:
¥On success, output looks like:
diff --git a/package.json b/package.jsonindex v1.1.0..v1.1.1 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "abbrev",- "version": "1.1.0",+ "version": "1.1.1","description": "Like ruby's abbrev module, but in js","author": "Isaac Z. Schlueter <i@izs.me>","main": "abbrev.js",鉴于 npm 规范的灵活性,你还可以像使用
npm install
时一样定位本地目录或 git repos:¥Given the flexible nature of npm specs, you can also target local directories or git repos just like when using
npm install
:npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path在上面的示例中,我们可以比较从
github.com/npm/libnpmdiff
的 git repo 安装的包的内容与包含有效包的./local-path
的内容,例如原始包的修改副本。¥In the example above we can compare the contents from the package installed from the git repo at
github.com/npm/libnpmdiff
with the contents of the./local-path
that contains a valid package, such as a modified copy of the original. -
npm diff
(在包目录中,无参数):¥
npm diff
(in a package directory, no arguments):如果包发布到注册表,
npm diff
将获取标记为latest
的 tarball 版本(可以使用tag
选项配置此值)并继续比较该 tarball 中存在的文件内容与本地文件中的当前文件系统。¥If the package is published to the registry,
npm diff
will fetch the tarball version tagged aslatest
(this value can be configured using thetag
option) and proceed to compare the contents of files present in that tarball, with the current files in your local file system.此工作流程为包作者提供了一种方便的方式,可以查看与该包的最新发布版本相比,哪些包跟踪文件已更改。
¥This workflow provides a handy way for package authors to see what package-tracked files have been changed in comparison with the latest published version of that package.
-
npm diff --diff=<pkg-name>
(在包目录中):¥
npm diff --diff=<pkg-name>
(in a package directory):当使用单个包名(没有版本或标签说明符)作为参数时,
npm diff
将以与npm-outdated
类似的方式工作,并到达注册表以确定名为<pkg-name>
的包的当前发布版本将满足其依赖声明的 semver -范围。一旦知道该特定版本,npm diff
将打印差异补丁,将在本地文件系统中找到的<pkg-name>
的当前版本与注册表返回的特定版本进行比较。¥When using a single package name (with no version or tag specifier) as an argument,
npm diff
will work in a similar way tonpm-outdated
and reach for the registry to figure out what current published version of the package named<pkg-name>
will satisfy its dependent declared semver-range. Once that specific version is knownnpm diff
will print diff patches comparing the current version of<pkg-name>
found in the local file system with that specific version returned by the registry.给定当前安装的名为
abbrev
的包:¥Given a package named
abbrev
that is currently installed:npm diff --diff=abbrev这将向注册表请求其最新版本,如果版本号不同,将打印一个比较当前安装的版本与新版本的差异输出。
¥That will request from the registry its most up to date version and will print a diff output comparing the currently installed version to this newer one if the version numbers are not the same.
-
npm diff --diff=<spec-a>
(在包目录中):¥
npm diff --diff=<spec-a>
(in a package directory):与仅使用单个包名称类似,如果你希望将已安装包的本地版本与
<spec-a>
中提供的特定版本/标签/semver-range 进行比较,也可以声明完整的注册表说明符版本。¥Similar to using only a single package name, it's also possible to declare a full registry specifier version if you wish to compare the local version of an installed package with the specific version/tag/semver-range provided in
<spec-a>
.一个例子:假设
pkg@1.0.0
安装在当前的node_modules
文件夹中,运行:¥An example: assuming
pkg@1.0.0
is installed in the currentnode_modules
folder, running:npm diff --diff=pkg@2.0.0它实际上是
npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0
的别名。¥It will effectively be an alias to
npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0
. -
npm diff --diff=<semver-a> [--diff=<semver-b>]
(在包目录中):¥
npm diff --diff=<semver-a> [--diff=<semver-b>]
(in a package directory):使用
npm diff
和 semver-valid 版本号是比较当前包的不同版本的简写。¥Using
npm diff
along with semver-valid version numbers is a shorthand to compare different versions of the current package.它需要从一个包目录运行,这样对于一个名为
pkg
的包来说,运行npm diff --diff=1.0.0 --diff=1.0.1
与运行npm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1
是一样的。¥It needs to be run from a package directory, such that for a package named
pkg
runningnpm diff --diff=1.0.0 --diff=1.0.1
is the same as runningnpm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1
.如果只提供了一个参数
<version-a>
,那么当前本地文件系统将与该版本进行比较。¥If only a single argument
<version-a>
is provided, then the current local file system is going to be compared against that version.这是一个比较当前项目目录的两个特定版本(发布到配置的注册表)的示例:
¥Here's an example comparing two specific versions (published to the configured registry) of the current project directory:
npm diff --diff=1.0.0 --diff=1.1.0
请注意,标签名称不是有效的 --diff
参数值,如果你希望与已发布的标签进行比较,则必须使用 pkg@tagname
语法。
¥Note that tag names are not valid --diff
argument values, if you wish to compare to a published tag, you must use the pkg@tagname
syntax.