.TH "NPM\-DIFF" "1" "November 2023" "9.2.0" .SH "NAME" \fBnpm-diff\fR .SH Synopsis .SH Description .P Similar to its \fBgit diff\fP counterpart, this command will print diff patches .br of files for packages published to the npm registry\. .RS 1 .IP \(bu 2 \fBnpm diff \-\-diff= \-\-diff=\fP .P Compares two package versions using their registry specifiers, e\.g: .br \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg@^2\.0\.0\fP\|\. It's also possible to .br compare across forks of any package, .br e\.g: \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg\-fork@1\.0\.0\fP\|\. .P Any valid spec can be used, so that it's also possible to compare .br directories or git repositories, .br e\.g: \fBnpm diff \-\-diff=pkg@latest \-\-diff=\./packages/pkg\fP .P Here's an example comparing two different versions of a package named .br \fBabbrev\fP from the registry: .RS 2 .nf npm diff \-\-diff=abbrev@1\.1\.0 \-\-diff=abbrev@1\.1\.1 .fi .RE .P On success, output looks like: .RS 2 .nf diff \-\-git a/package\.json b/package\.json index 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 ", "main": "abbrev\.js", .fi .RE .P Given the flexible nature of npm specs, you can also target local .br directories or git repos just like when using \fBnpm install\fP: .RS 2 .nf npm diff \-\-diff=https://github\.com/npm/libnpmdiff \-\-diff=\./local\-path .fi .RE .P In the example above we can compare the contents from the package installed .br from the git repo at \fBgithub\.com/npm/libnpmdiff\fP with the contents of the .br \fB\|\./local\-path\fP that contains a valid package, such as a modified copy of .br the original\. .IP \(bu 2 \fBnpm diff\fP (in a package directory, no arguments): .P If the package is published to the registry, \fBnpm diff\fP will fetch the .br tarball version tagged as \fBlatest\fP (this value can be configured using the .br \fBtag\fP option) and proceed to compare the contents of files present in that .br tarball, with the current files in your local file system\. .P This workflow provides a handy way for package authors to see what .br package\-tracked files have been changed in comparison with the latest .br published version of that package\. .IP \(bu 2 \fBnpm diff \-\-diff=\fP (in a package directory): .P When using a single package name (with no version or tag specifier) as an .br argument, \fBnpm diff\fP will work in a similar way to .br .UR npm-outdated .I `npm-outdated` .UE and reach for the registry to figure out .br what current published version of the package named \fB\fP .br will satisfy its dependent declared semver\-range\. Once that specific .br version is known \fBnpm diff\fP will print diff patches comparing the .br current version of \fB\fP found in the local file system with .br that specific version returned by the registry\. .P Given a package named \fBabbrev\fP that is currently installed: .RS 2 .nf npm diff \-\-diff=abbrev .fi .RE .P That will request from the registry its most up to date version and .br will print a diff output comparing the currently installed version to this .br newer one if the version numbers are not the same\. .IP \(bu 2 \fBnpm diff \-\-diff=\fP (in a package directory): .P Similar to using only a single package name, it's also possible to declare .br a full registry specifier version if you wish to compare the local version .br of an installed package with the specific version/tag/semver\-range provided .br in \fB\fP\|\. .P An example: assuming \fBpkg@1\.0\.0\fP is installed in the current \fBnode_modules\fP .br folder, running: .RS 2 .nf npm diff \-\-diff=pkg@2\.0\.0 .fi .RE .P It will effectively be an alias to .br \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg@2\.0\.0\fP\|\. .IP \(bu 2 \fBnpm diff \-\-diff= [\-\-diff=]\fP (in a package directory): .P Using \fBnpm diff\fP along with semver\-valid version numbers is a shorthand .br to compare different versions of the current package\. .P It needs to be run from a package directory, such that for a package named .br \fBpkg\fP running \fBnpm diff \-\-diff=1\.0\.0 \-\-diff=1\.0\.1\fP is the same as running .br \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg@1\.0\.1\fP\|\. .P If only a single argument \fB\fP is provided, then the current local .br file system is going to be compared against that version\. .P Here's an example comparing two specific versions (published to the .br configured registry) of the current project directory: .RS 2 .nf npm diff \-\-diff=1\.0\.0 \-\-diff=1\.1\.0 .fi .RE .RE .P Note that tag names are not valid \fB\-\-diff\fP argument values, if you wish to .br compare to a published tag, you must use the \fBpkg@tagname\fP syntax\. .SS Filtering files .P It's possible to also specify positional arguments using file names or globs .br pattern matching in order to limit the result of diff patches to only a subset .br of files for a given package, e\.g: .RS 2 .nf npm diff \-\-diff=pkg@2 \./lib/ CHANGELOG\.md .fi .RE .P In the example above the diff output is only going to print contents of files .br located within the folder \fB\|\./lib/\fP and changed lines of code within the .br \fBCHANGELOG\.md\fP file\. .SH Configuration .SH See Also .RS 1 .IP \(bu 2 npm outdated .IP \(bu 2 npm install .IP \(bu 2 npm config .IP \(bu 2 npm registry .RE