1NPM-DIFF(1) NPM-DIFF(1)
2
3
4
6 npm-diff - The registry diff command
7
8 Synopsis
9 npm diff [...<paths>]
10
11 Description
12 Similar to its git diff counterpart, this command will print diff
13 patches of files for packages published to the npm registry.
14
15 • npm diff --diff=<spec-a> --diff=<spec-b>
16 Compares two package versions using their registry specifiers, e.g:
17 npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0. It's also possible to
18 compare across forks of any package,
19 e.g: npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0.
20 Any valid spec can be used, so that it's also possible to compare
21 directories or git repositories,
22 e.g: npm diff --diff=pkg@latest --diff=./packages/pkg
23 Here's an example comparing two different versions of a package
24 named
25 abbrev from the registry:
26
27 npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1
28 On success, output looks like:
29
30 diff --git a/package.json b/package.json
31 index v1.1.0..v1.1.1 100644
32 --- a/package.json
33 +++ b/package.json
34 @@ -1,6 +1,6 @@
35 {
36 "name": "abbrev",
37 - "version": "1.1.0",
38 + "version": "1.1.1",
39 "description": "Like ruby's abbrev module, but in js",
40 "author": "Isaac Z. Schlueter <i@izs.me>",
41 "main": "abbrev.js",
42 Given the flexible nature of npm specs, you can also target local
43 directories or git repos just like when using npm install:
44
45 npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path
46 In the example above we can compare the contents from the package in‐
47 stalled
48 from the git repo at github.com/npm/libnpmdiff with the contents of
49 the
50 ./local-path that contains a valid package, such as a modified copy
51 of
52 the original.
53
54 • npm diff (in a package directory, no arguments):
55 If the package is published to the registry, npm diff will fetch
56 the
57 tarball version tagged as latest (this value can be configured us‐
58 ing the
59 tag option) and proceed to compare the contents of files present in
60 that
61 tarball, with the current files in your local file system.
62 This workflow provides a handy way for package authors to see what
63 package-tracked files have been changed in comparison with the lat‐
64 est
65 published version of that package.
66
67 • npm diff --diff=<pkg-name> (in a package directory):
68 When using a single package name (with no version or tag specifier)
69 as an
70 argument, npm diff will work in a similar way to
71 npm-outdated npm-outdated and reach for the registry to figure out
72 what current published version of the package named <pkg-name>
73 will satisfy its dependent declared semver-range. Once that spe‐
74 cific
75 version is known npm diff will print diff patches comparing the
76 current version of <pkg-name> found in the local file system with
77 that specific version returned by the registry.
78 Given a package named abbrev that is currently installed:
79
80 npm diff --diff=abbrev
81 That will request from the registry its most up to date version and
82 will print a diff output comparing the currently installed version to
83 this
84 newer one if the version numbers are not the same.
85
86 • npm diff --diff=<spec-a> (in a package directory):
87 Similar to using only a single package name, it's also possible to
88 declare
89 a full registry specifier version if you wish to compare the local
90 version
91 of an installed package with the specific version/tag/semver-range
92 provided
93 in <spec-a>.
94 An example: assuming pkg@1.0.0 is installed in the current
95 node_modules
96 folder, running:
97
98 npm diff --diff=pkg@2.0.0
99 It will effectively be an alias to
100 npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0.
101
102 • npm diff --diff=<semver-a> [--diff=<semver-b>] (in a package direc‐
103 tory):
104 Using npm diff along with semver-valid version numbers is a short‐
105 hand
106 to compare different versions of the current package.
107 It needs to be run from a package directory, such that for a pack‐
108 age named
109 pkg running npm diff --diff=1.0.0 --diff=1.0.1 is the same as run‐
110 ning
111 npm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1.
112 If only a single argument <version-a> is provided, then the current
113 local
114 file system is going to be compared against that version.
115 Here's an example comparing two specific versions (published to the
116 configured registry) of the current project directory:
117
118 npm diff --diff=1.0.0 --diff=1.1.0
119
120
121 Note that tag names are not valid --diff argument values, if you wish
122 to compare to a published tag, you must use the pkg@tagname syntax.
123
124 Filtering files
125 It's possible to also specify positional arguments using file names or
126 globs pattern matching in order to limit the result of diff patches to
127 only a subset of files for a given package, e.g:
128
129 npm diff --diff=pkg@2 ./lib/ CHANGELOG.md
130
131 In the example above the diff output is only going to print contents of
132 files located within the folder ./lib/ and changed lines of code within
133 the CHANGELOG.md file.
134
135 Configuration
136 diff
137 • Default:
138
139 • Type: String (can be set multiple times)
140
141
142 Define arguments to compare in npm diff.
143
144 diff-name-only
145 • Default: false
146
147 • Type: Boolean
148
149
150 Prints only filenames when using npm diff.
151
152 diff-unified
153 • Default: 3
154
155 • Type: Number
156
157
158 The number of lines of context to print in npm diff.
159
160 diff-ignore-all-space
161 • Default: false
162
163 • Type: Boolean
164
165
166 Ignore whitespace when comparing lines in npm diff.
167
168 diff-no-prefix
169 • Default: false
170
171 • Type: Boolean
172
173
174 Do not show any source or destination prefix in npm diff output.
175
176 Note: this causes npm diff to ignore the --diff-src-prefix and
177 --diff-dst-prefix configs.
178
179 diff-src-prefix
180 • Default: "a/"
181
182 • Type: String
183
184
185 Source prefix to be used in npm diff output.
186
187 diff-dst-prefix
188 • Default: "b/"
189
190 • Type: String
191
192
193 Destination prefix to be used in npm diff output.
194
195 diff-text
196 • Default: false
197
198 • Type: Boolean
199
200
201 Treat all files as text in npm diff.
202
203 global
204 • Default: false
205
206 • Type: Boolean
207
208
209 Operates in "global" mode, so that packages are installed into the pre‐
210 fix folder instead of the current working directory. See npm help fold‐
211 ers for more on the differences in behavior.
212
213 • packages are installed into the {prefix}/lib/node_modules folder, in‐
214 stead of the current working directory.
215
216 • bin files are linked to {prefix}/bin
217
218 • man pages are linked to {prefix}/share/man
219
220
221 tag
222 • Default: "latest"
223
224 • Type: String
225
226
227 If you ask npm to install a package and don't tell it a specific ver‐
228 sion, then it will install the specified tag.
229
230 Also the tag that is added to the package@version specified by the npm
231 tag command, if no explicit tag is given.
232
233 When used by the npm diff command, this is the tag used to fetch the
234 tarball that will be compared with the local files by default.
235
236 workspace
237 • Default:
238
239 • Type: String (can be set multiple times)
240
241
242 Enable running a command in the context of the configured workspaces of
243 the current project while filtering by running only the workspaces de‐
244 fined by this configuration option.
245
246 Valid values for the workspace config are either:
247
248 • Workspace names
249
250 • Path to a workspace directory
251
252 • Path to a parent workspace directory (will result in selecting all
253 workspaces within that folder)
254
255
256 When set for the npm init command, this may be set to the folder of a
257 workspace which does not yet exist, to create the folder and set it up
258 as a brand new workspace within the project.
259
260 This value is not exported to the environment for child processes.
261
262 workspaces
263 • Default: null
264
265 • Type: null or Boolean
266
267
268 Set to true to run the command in the context of all configured
269 workspaces.
270
271 Explicitly setting this to false will cause commands like install to
272 ignore workspaces altogether. When not set explicitly:
273
274 • Commands that operate on the node_modules tree (install, update,
275 etc.) will link workspaces into the node_modules folder. - Commands
276 that do other things (test, exec, publish, etc.) will operate on the
277 root project, unless one or more workspaces are specified in the
278 workspace config.
279
280
281 This value is not exported to the environment for child processes.
282
283 include-workspace-root
284 • Default: false
285
286 • Type: Boolean
287
288
289 Include the workspace root when workspaces are enabled for a command.
290
291 When false, specifying individual workspaces via the workspace config,
292 or all workspaces via the workspaces flag, will cause npm to operate
293 only on the specified workspaces, and not on the root project.
294
295 This value is not exported to the environment for child processes.
296
298 • npm help outdated
299
300 • npm help install
301
302 • npm help config
303
304 • npm help registry
305
306
307
308
309 September 2022 NPM-DIFF(1)