The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / npm / man / man1 / shrinkwrap.1 @ d46ebffb

History | View | Annotate | Download (6.54 KB)

1
.\" Generated with Ronnjs 0.3.8
2
.\" http://github.com/kapouer/ronnjs/
3
.
4
.TH "NPM\-SHRINKWRAP" "1" "April 2013" "" ""
5
.
6
.SH "NAME"
7
\fBnpm-shrinkwrap\fR \-\- Lock down dependency versions
8
.
9
.SH "SYNOPSIS"
10
.
11
.nf
12
npm shrinkwrap
13
.
14
.fi
15
.
16
.SH "DESCRIPTION"
17
This command locks down the versions of a package\'s dependencies so that you can
18
control exactly which versions of each dependency will be used when your package
19
is installed\.
20
.
21
.P
22
By default, "npm install" recursively installs the target\'s dependencies (as
23
specified in package\.json), choosing the latest available version that satisfies
24
the dependency\'s semver pattern\. In some situations, particularly when shipping
25
software where each change is tightly managed, it\'s desirable to fully specify
26
each version of each dependency recursively so that subsequent builds and
27
deploys do not inadvertently pick up newer versions of a dependency that satisfy
28
the semver pattern\. Specifying specific semver patterns in each dependency\'s
29
package\.json would facilitate this, but that\'s not always possible or desirable,
30
as when another author owns the npm package\. It\'s also possible to check
31
dependencies directly into source control, but that may be undesirable for other
32
reasons\.
33
.
34
.P
35
As an example, consider package A:
36
.
37
.IP "" 4
38
.
39
.nf
40
{
41
    "name": "A",
42
    "version": "0\.1\.0",
43
    "dependencies": {
44
        "B": "<0\.1\.0"
45
    }
46
}
47
.
48
.fi
49
.
50
.IP "" 0
51
.
52
.P
53
package B:
54
.
55
.IP "" 4
56
.
57
.nf
58
{
59
    "name": "B",
60
    "version": "0\.0\.1",
61
    "dependencies": {
62
        "C": "<0\.1\.0"
63
    }
64
}
65
.
66
.fi
67
.
68
.IP "" 0
69
.
70
.P
71
and package C:
72
.
73
.IP "" 4
74
.
75
.nf
76
{
77
    "name": "C,
78
    "version": "0\.0\.1"
79
}
80
.
81
.fi
82
.
83
.IP "" 0
84
.
85
.P
86
If these are the only versions of A, B, and C available in the registry, then
87
a normal "npm install A" will install:
88
.
89
.IP "" 4
90
.
91
.nf
92
A@0\.1\.0
93
`\-\- B@0\.0\.1
94
    `\-\- C@0\.0\.1
95
.
96
.fi
97
.
98
.IP "" 0
99
.
100
.P
101
However, if B@0\.0\.2 is published, then a fresh "npm install A" will install:
102
.
103
.IP "" 4
104
.
105
.nf
106
A@0\.1\.0
107
`\-\- B@0\.0\.2
108
    `\-\- C@0\.0\.1
109
.
110
.fi
111
.
112
.IP "" 0
113
.
114
.P
115
assuming the new version did not modify B\'s dependencies\. Of course, the new
116
version of B could include a new version of C and any number of new
117
dependencies\. If such changes are undesirable, the author of A could specify a
118
dependency on B@0\.0\.1\. However, if A\'s author and B\'s author are not the same
119
person, there\'s no way for A\'s author to say that he or she does not want to
120
pull in newly published versions of C when B hasn\'t changed at all\.
121
.
122
.P
123
In this case, A\'s author can run
124
.
125
.IP "" 4
126
.
127
.nf
128
npm shrinkwrap
129
.
130
.fi
131
.
132
.IP "" 0
133
.
134
.P
135
This generates npm\-shrinkwrap\.json, which will look something like this:
136
.
137
.IP "" 4
138
.
139
.nf
140
{
141
  "name": "A",
142
  "version": "0\.1\.0",
143
  "dependencies": {
144
    "B": {
145
      "version": "0\.0\.1",
146
      "dependencies": {
147
        "C": {
148
          "version": "0\.1\.0"
149
        }
150
      }
151
    }
152
  }
153
}
154
.
155
.fi
156
.
157
.IP "" 0
158
.
159
.P
160
The shrinkwrap command has locked down the dependencies based on what\'s
161
currently installed in node_modules\.  When "npm install" installs a package with
162
a npm\-shrinkwrap\.json file in the package root, the shrinkwrap file (rather than
163
package\.json files) completely drives the installation of that package and all
164
of its dependencies (recursively)\.  So now the author publishes A@0\.1\.0, and
165
subsequent installs of this package will use B@0\.0\.1 and C@0\.1\.0, regardless the
166
dependencies and versions listed in A\'s, B\'s, and C\'s package\.json files\.
167
.
168
.SS "Using shrinkwrapped packages"
169
Using a shrinkwrapped package is no different than using any other package: you
170
can "npm install" it by hand, or add a dependency to your package\.json file and
171
"npm install" it\.
172
.
173
.SS "Building shrinkwrapped packages"
174
To shrinkwrap an existing package:
175
.
176
.IP "1" 4
177
Run "npm install" in the package root to install the current versions of all
178
dependencies\.
179
.
180
.IP "2" 4
181
Validate that the package works as expected with these versions\.
182
.
183
.IP "3" 4
184
Run "npm shrinkwrap", add npm\-shrinkwrap\.json to git, and publish your
185
package\.
186
.
187
.IP "" 0
188
.
189
.P
190
To add or update a dependency in a shrinkwrapped package:
191
.
192
.IP "1" 4
193
Run "npm install" in the package root to install the current versions of all
194
dependencies\.
195
.
196
.IP "2" 4
197
Add or update dependencies\. "npm install" each new or updated package
198
individually and then update package\.json\.  Note that they must be
199
explicitly named in order to be installed: running \fBnpm install\fR with
200
no arguments will merely reproduce the existing shrinkwrap\.
201
.
202
.IP "3" 4
203
Validate that the package works as expected with the new dependencies\.
204
.
205
.IP "4" 4
206
Run "npm shrinkwrap", commit the new npm\-shrinkwrap\.json, and publish your
207
package\.
208
.
209
.IP "" 0
210
.
211
.P
212
You can use npm help outdated to view dependencies with newer versions available\.
213
.
214
.SS "Other Notes"
215
Since "npm shrinkwrap" uses the locally installed packages to construct the
216
shrinkwrap file, devDependencies will be included if and only if you\'ve
217
installed them already when you make the shrinkwrap\.
218
.
219
.P
220
A shrinkwrap file must be consistent with the package\'s package\.json file\. "npm
221
shrinkwrap" will fail if required dependencies are not already installed, since
222
that would result in a shrinkwrap that wouldn\'t actually work\. Similarly, the
223
command will fail if there are extraneous packages (not referenced by
224
package\.json), since that would indicate that package\.json is not correct\.
225
.
226
.P
227
If shrinkwrapped package A depends on shrinkwrapped package B, B\'s shrinkwrap
228
will not be used as part of the installation of A\. However, because A\'s
229
shrinkwrap is constructed from a valid installation of B and recursively
230
specifies all dependencies, the contents of B\'s shrinkwrap will implicitly be
231
included in A\'s shrinkwrap\.
232
.
233
.SS "Caveats"
234
Shrinkwrap files only lock down package versions, not actual package contents\.
235
While discouraged, a package author can republish an existing version of a
236
package, causing shrinkwrapped packages using that version to pick up different
237
code than they were before\. If you want to avoid any risk that a byzantine
238
author replaces a package you\'re using with code that breaks your application,
239
you could modify the shrinkwrap file to use git URL references rather than
240
version numbers so that npm always fetches all packages from git\.
241
.
242
.P
243
If you wish to lock down the specific bytes included in a package, for
244
example to have 100% confidence in being able to reproduce a deployment
245
or build, then you ought to check your dependencies into source control,
246
or pursue some other mechanism that can verify contents rather than
247
versions\.
248
.
249
.SH "SEE ALSO"
250
.
251
.IP "\(bu" 4
252
npm help install
253
.
254
.IP "\(bu" 4
255
npm help json
256
.
257
.IP "\(bu" 4
258
npm help list
259
.
260
.IP "" 0
261