summaryrefslogtreecommitdiff
path: root/deps/npm/html/doc/cli/npm-shrinkwrap.html
blob: 5a83f749dbe1ea905988a9a80e2562aec6aa75a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!doctype html>
<html>
  <title>npm-shrinkwrap</title>
  <meta http-equiv="content-type" value="text/html;utf-8">
  <link rel="stylesheet" type="text/css" href="../../static/style.css">

  <body>
    <div id="wrapper">
<h1><a href="../cli/npm-shrinkwrap.html">npm-shrinkwrap</a></h1> <p>Lock down dependency versions</p>

<h2 id="SYNOPSIS">SYNOPSIS</h2>

<pre><code>npm shrinkwrap</code></pre>

<h2 id="DESCRIPTION">DESCRIPTION</h2>

<p>This command locks down the versions of a package&#39;s dependencies so
that you can control exactly which versions of each dependency will be
used when your package is installed. The &quot;package.json&quot; file is still
required if you want to use &quot;npm install&quot;.</p>

<p>By default, &quot;npm install&quot; recursively installs the target&#39;s
dependencies (as specified in package.json), choosing the latest
available version that satisfies the dependency&#39;s semver pattern. In
some situations, particularly when shipping software where each change
is tightly managed, it&#39;s desirable to fully specify each version of
each dependency recursively so that subsequent builds and deploys do
not inadvertently pick up newer versions of a dependency that satisfy
the semver pattern. Specifying specific semver patterns in each
dependency&#39;s package.json would facilitate this, but that&#39;s not always
possible or desirable, as when another author owns the npm package.
It&#39;s also possible to check dependencies directly into source control,
but that may be undesirable for other reasons.</p>

<p>As an example, consider package A:</p>

<pre><code>{
  &quot;name&quot;: &quot;A&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;dependencies&quot;: {
    &quot;B&quot;: &quot;&lt;0.1.0&quot;
  }
}</code></pre>

<p>package B:</p>

<pre><code>{
  &quot;name&quot;: &quot;B&quot;,
  &quot;version&quot;: &quot;0.0.1&quot;,
  &quot;dependencies&quot;: {
    &quot;C&quot;: &quot;&lt;0.1.0&quot;
  }
}</code></pre>

<p>and package C:</p>

<pre><code>{
  &quot;name&quot;: &quot;C,
  &quot;version&quot;: &quot;0.0.1&quot;
}</code></pre>

<p>If these are the only versions of A, B, and C available in the
registry, then a normal &quot;npm install A&quot; will install:</p>

<pre><code>A@0.1.0
`-- B@0.0.1
    `-- C@0.0.1</code></pre>

<p>However, if B@0.0.2 is published, then a fresh &quot;npm install A&quot; will
install:</p>

<pre><code>A@0.1.0
`-- B@0.0.2
    `-- C@0.0.1</code></pre>

<p>assuming the new version did not modify B&#39;s dependencies. Of course,
the new version of B could include a new version of C and any number
of new dependencies. If such changes are undesirable, the author of A
could specify a dependency on B@0.0.1. However, if A&#39;s author and B&#39;s
author are not the same person, there&#39;s no way for A&#39;s author to say
that he or she does not want to pull in newly published versions of C
when B hasn&#39;t changed at all.</p>

<p>In this case, A&#39;s author can run</p>

<pre><code>npm shrinkwrap</code></pre>

<p>This generates npm-shrinkwrap.json, which will look something like this:</p>

<pre><code>{
  &quot;name&quot;: &quot;A&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;dependencies&quot;: {
    &quot;B&quot;: {
      &quot;version&quot;: &quot;0.0.1&quot;,
      &quot;dependencies&quot;: {
        &quot;C&quot;: {
          &quot;version&quot;: &quot;0.1.0&quot;
        }
      }
    }
  }
}</code></pre>

<p>The shrinkwrap command has locked down the dependencies based on
what&#39;s currently installed in node_modules.  When &quot;npm install&quot;
installs a package with a npm-shrinkwrap.json file in the package
root, the shrinkwrap file (rather than package.json files) completely
drives the installation of that package and all of its dependencies
(recursively).  So now the author publishes A@0.1.0, and subsequent
installs of this package will use B@0.0.1 and C@0.1.0, regardless the
dependencies and versions listed in A&#39;s, B&#39;s, and C&#39;s package.json
files.</p>

<h3 id="Using-shrinkwrapped-packages">Using shrinkwrapped packages</h3>

<p>Using a shrinkwrapped package is no different than using any other
package: you can &quot;npm install&quot; it by hand, or add a dependency to your
package.json file and &quot;npm install&quot; it.</p>

<h3 id="Building-shrinkwrapped-packages">Building shrinkwrapped packages</h3>

<p>To shrinkwrap an existing package:</p>

<ol><li>Run &quot;npm install&quot; in the package root to install the current
versions of all dependencies.</li><li>Validate that the package works as expected with these versions.</li><li>Run &quot;npm shrinkwrap&quot;, add npm-shrinkwrap.json to git, and publish
your package.</li></ol>

<p>To add or update a dependency in a shrinkwrapped package:</p>

<ol><li>Run &quot;npm install&quot; in the package root to install the current
versions of all dependencies.</li><li>Add or update dependencies. &quot;npm install&quot; each new or updated
package individually and then update package.json.  Note that they
must be explicitly named in order to be installed: running <code>npm
install</code> with no arguments will merely reproduce the existing
shrinkwrap.</li><li>Validate that the package works as expected with the new
dependencies.</li><li>Run &quot;npm shrinkwrap&quot;, commit the new npm-shrinkwrap.json, and
publish your package.</li></ol>

<p>You can use <a href="../cli/npm-outdated.html">npm-outdated(1)</a> to view dependencies with newer versions
available.</p>

<h3 id="Other-Notes">Other Notes</h3>

<p>A shrinkwrap file must be consistent with the package&#39;s package.json
file. &quot;npm shrinkwrap&quot; will fail if required dependencies are not
already installed, since that would result in a shrinkwrap that
wouldn&#39;t actually work. Similarly, the command will fail if there are
extraneous packages (not referenced by package.json), since that would
indicate that package.json is not correct.</p>

<p>Since &quot;npm shrinkwrap&quot; is intended to lock down your dependencies for
production use, <code>devDependencies</code> will not be included unless you
explicitly set the <code>--dev</code> flag when you run <code>npm shrinkwrap</code>.  If
installed <code>devDependencies</code> are excluded, then npm will print a
warning.  If you want them to be installed with your module by
default, please consider adding them to <code>dependencies</code> instead.</p>

<p>If shrinkwrapped package A depends on shrinkwrapped package B, B&#39;s
shrinkwrap will not be used as part of the installation of A. However,
because A&#39;s shrinkwrap is constructed from a valid installation of B
and recursively specifies all dependencies, the contents of B&#39;s
shrinkwrap will implicitly be included in A&#39;s shrinkwrap.</p>

<h3 id="Caveats">Caveats</h3>

<p>Shrinkwrap files only lock down package versions, not actual package
contents.  While discouraged, a package author can republish an
existing version of a package, causing shrinkwrapped packages using
that version to pick up different code than they were before. If you
want to avoid any risk that a byzantine author replaces a package
you&#39;re using with code that breaks your application, you could modify
the shrinkwrap file to use git URL references rather than version
numbers so that npm always fetches all packages from git.</p>

<p>If you wish to lock down the specific bytes included in a package, for
example to have 100% confidence in being able to reproduce a
deployment or build, then you ought to check your dependencies into
source control, or pursue some other mechanism that can verify
contents rather than versions.</p>

<h2 id="SEE-ALSO">SEE ALSO</h2>

<ul><li><a href="../cli/npm-install.html">npm-install(1)</a></li><li><a href="../files/package.json.html">package.json(5)</a></li><li><a href="../cli/npm-ls.html">npm-ls(1)</a></li></ul>
</div>
<p id="footer">npm-shrinkwrap &mdash; npm@1.3.13</p>
<script>
;(function () {
var wrapper = document.getElementById("wrapper")
var els = Array.prototype.slice.call(wrapper.getElementsByTagName("*"), 0)
  .filter(function (el) {
    return el.parentNode === wrapper
        && el.tagName.match(/H[1-6]/)
        && el.id
  })
var l = 2
  , toc = document.createElement("ul")
toc.innerHTML = els.map(function (el) {
  var i = el.tagName.charAt(1)
    , out = ""
  while (i > l) {
    out += "<ul>"
    l ++
  }
  while (i < l) {
    out += "</ul>"
    l --
  }
  out += "<li><a href='#" + el.id + "'>" +
    ( el.innerText || el.text || el.innerHTML)
    + "</a>"
  return out
}).join("\n")
toc.id = "toc"
document.body.appendChild(toc)
})()
</script>