package-lock-json.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <html><head>
  2. <title>package-lock.json</title>
  3. <style>
  4. body {
  5. background-color: #ffffff;
  6. color: #24292e;
  7. margin: 0;
  8. line-height: 1.5;
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  10. }
  11. #rainbar {
  12. height: 10px;
  13. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #0366d6;
  18. }
  19. a:hover {
  20. text-decoration: underline;
  21. }
  22. pre {
  23. margin: 1em 0px;
  24. padding: 1em;
  25. border: solid 1px #e1e4e8;
  26. border-radius: 6px;
  27. display: block;
  28. overflow: auto;
  29. white-space: pre;
  30. background-color: #f6f8fa;
  31. color: #393a34;
  32. }
  33. code {
  34. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  35. font-size: 85%;
  36. padding: 0.2em 0.4em;
  37. background-color: #f6f8fa;
  38. color: #393a34;
  39. }
  40. pre > code {
  41. padding: 0;
  42. background-color: inherit;
  43. color: inherit;
  44. }
  45. h1, h2, h3 {
  46. font-weight: 600;
  47. }
  48. #logobar {
  49. background-color: #333333;
  50. margin: 0 auto;
  51. padding: 1em 4em;
  52. }
  53. #logobar .logo {
  54. float: left;
  55. }
  56. #logobar .title {
  57. font-weight: 600;
  58. color: #dddddd;
  59. float: left;
  60. margin: 5px 0 0 1em;
  61. }
  62. #logobar:after {
  63. content: "";
  64. display: block;
  65. clear: both;
  66. }
  67. #content {
  68. margin: 0 auto;
  69. padding: 0 4em;
  70. }
  71. #table_of_contents > h2 {
  72. font-size: 1.17em;
  73. }
  74. #table_of_contents ul:first-child {
  75. border: solid 1px #e1e4e8;
  76. border-radius: 6px;
  77. padding: 1em;
  78. background-color: #f6f8fa;
  79. color: #393a34;
  80. }
  81. #table_of_contents ul {
  82. list-style-type: none;
  83. padding-left: 1.5em;
  84. }
  85. #table_of_contents li {
  86. font-size: 0.9em;
  87. }
  88. #table_of_contents li a {
  89. color: #000000;
  90. }
  91. header.title {
  92. border-bottom: solid 1px #e1e4e8;
  93. }
  94. header.title > h1 {
  95. margin-bottom: 0.25em;
  96. }
  97. header.title > .description {
  98. display: block;
  99. margin-bottom: 0.5em;
  100. line-height: 1;
  101. }
  102. footer#edit {
  103. border-top: solid 1px #e1e4e8;
  104. margin: 3em 0 4em 0;
  105. padding-top: 2em;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="banner">
  111. <div id="rainbar"></div>
  112. <div id="logobar">
  113. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  114. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  115. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  116. </svg>
  117. <div class="title">
  118. npm command-line interface
  119. </div>
  120. </div>
  121. </div>
  122. <section id="content">
  123. <header class="title">
  124. <h1 id="package-lockjson">package-lock.json</h1>
  125. <span class="description">A manifestation of the manifest</span>
  126. </header>
  127. <section id="table_of_contents">
  128. <h2 id="table-of-contents">Table of contents</h2>
  129. <div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#package-lockjson-vs-npm-shrinkwrapjson"><code>package-lock.json</code> vs <code>npm-shrinkwrap.json</code></a></li><li><a href="#hidden-lockfiles">Hidden Lockfiles</a></li><li><a href="#handling-old-lockfiles">Handling Old Lockfiles</a></li><li><a href="#file-format">File Format</a></li><ul><li><a href="#name"><code>name</code></a></li><li><a href="#version"><code>version</code></a></li><li><a href="#lockfileversion"><code>lockfileVersion</code></a></li><li><a href="#packages"><code>packages</code></a></li><li><a href="#dependencies">dependencies</a></li></ul><li><a href="#see-also">See also</a></li></ul></div>
  130. </section>
  131. <div id="_content"><h3 id="description">Description</h3>
  132. <p><code>package-lock.json</code> is automatically generated for any operations where npm
  133. modifies either the <code>node_modules</code> tree, or <code>package.json</code>. It describes the
  134. exact tree that was generated, such that subsequent installs are able to
  135. generate identical trees, regardless of intermediate dependency updates.</p>
  136. <p>This file is intended to be committed into source repositories, and serves
  137. various purposes:</p>
  138. <ul>
  139. <li>
  140. <p>Describe a single representation of a dependency tree such that
  141. teammates, deployments, and continuous integration are guaranteed to
  142. install exactly the same dependencies.</p>
  143. </li>
  144. <li>
  145. <p>Provide a facility for users to “time-travel” to previous states of
  146. <code>node_modules</code> without having to commit the directory itself.</p>
  147. </li>
  148. <li>
  149. <p>Facilitate greater visibility of tree changes through readable source
  150. control diffs.</p>
  151. </li>
  152. <li>
  153. <p>Optimize the installation process by allowing npm to skip repeated
  154. metadata resolutions for previously-installed packages.</p>
  155. </li>
  156. <li>
  157. <p>As of npm v7, lockfiles include enough information to gain a complete
  158. picture of the package tree, reducing the need to read <code>package.json</code>
  159. files, and allowing for significant performance improvements.</p>
  160. </li>
  161. </ul>
  162. <h3 id="package-lockjson-vs-npm-shrinkwrapjson"><code>package-lock.json</code> vs <code>npm-shrinkwrap.json</code></h3>
  163. <p>Both of these files have the same format, and perform similar functions in
  164. the root of a project.</p>
  165. <p>The difference is that <code>package-lock.json</code> cannot be published, and it will
  166. be ignored if found in any place other than the root project.</p>
  167. <p>In contrast, <a href="../configuring-npm/npm-shrinkwrap-json.html">npm-shrinkwrap.json</a> allows
  168. publication, and defines the dependency tree from the point encountered.
  169. This is not recommended unless deploying a CLI tool or otherwise using the
  170. publication process for producing production packages.</p>
  171. <p>If both <code>package-lock.json</code> and <code>npm-shrinkwrap.json</code> are present in the
  172. root of a project, <code>npm-shrinkwrap.json</code> will take precedence and
  173. <code>package-lock.json</code> will be ignored.</p>
  174. <h3 id="hidden-lockfiles">Hidden Lockfiles</h3>
  175. <p>In order to avoid processing the <code>node_modules</code> folder repeatedly, npm as
  176. of v7 uses a “hidden” lockfile present in
  177. <code>node_modules/.package-lock.json</code>. This contains information about the
  178. tree, and is used in lieu of reading the entire <code>node_modules</code> hierarchy
  179. provided that the following conditions are met:</p>
  180. <ul>
  181. <li>All package folders it references exist in the <code>node_modules</code> hierarchy.</li>
  182. <li>No package folders exist in the <code>node_modules</code> hierarchy that are not
  183. listed in the lockfile.</li>
  184. <li>The modified time of the file is at least as recent as all of the package
  185. folders it references.</li>
  186. </ul>
  187. <p>That is, the hidden lockfile will only be relevant if it was created as
  188. part of the most recent update to the package tree. If another CLI mutates
  189. the tree in any way, this will be detected, and the hidden lockfile will be
  190. ignored.</p>
  191. <p>Note that it <em>is</em> possible to manually change the <em>contents</em> of a package
  192. in such a way that the modified time of the package folder is unaffected.
  193. For example, if you add a file to <code>node_modules/foo/lib/bar.js</code>, then the
  194. modified time on <code>node_modules/foo</code> will not reflect this change. If you
  195. are manually editing files in <code>node_modules</code>, it is generally best to
  196. delete the file at <code>node_modules/.package-lock.json</code>.</p>
  197. <p>As the hidden lockfile is ignored by older npm versions, it does not
  198. contain the backwards compatibility affordances present in “normal”
  199. lockfiles. That is, it is <code>lockfileVersion: 3</code>, rather than
  200. <code>lockfileVersion: 2</code>.</p>
  201. <h3 id="handling-old-lockfiles">Handling Old Lockfiles</h3>
  202. <p>When npm detects a lockfile from npm v6 or before during the package
  203. installation process, it is automatically updated to fetch missing
  204. information from either the <code>node_modules</code> tree or (in the case of empty
  205. <code>node_modules</code> trees or very old lockfile formats) the npm registry.</p>
  206. <h3 id="file-format">File Format</h3>
  207. <h4 id="name"><code>name</code></h4>
  208. <p>The name of the package this is a package-lock for. This will match what’s
  209. in <code>package.json</code>.</p>
  210. <h4 id="version"><code>version</code></h4>
  211. <p>The version of the package this is a package-lock for. This will match
  212. what’s in <code>package.json</code>.</p>
  213. <h4 id="lockfileversion"><code>lockfileVersion</code></h4>
  214. <p>An integer version, starting at <code>1</code> with the version number of this
  215. document whose semantics were used when generating this
  216. <code>package-lock.json</code>.</p>
  217. <p>Note that the file format changed significantly in npm v7 to track
  218. information that would have otherwise required looking in <code>node_modules</code> or
  219. the npm registry. Lockfiles generated by npm v7 will contain
  220. <code>lockfileVersion: 2</code>.</p>
  221. <ul>
  222. <li>No version provided: an “ancient” shrinkwrap file from a version of npm
  223. prior to npm v5.</li>
  224. <li><code>1</code>: The lockfile version used by npm v5 and v6.</li>
  225. <li><code>2</code>: The lockfile version used by npm v7, which is backwards compatible
  226. to v1 lockfiles.</li>
  227. <li><code>3</code>: The lockfile version used by npm v7, <em>without</em> backwards
  228. compatibility affordances. This is used for the hidden lockfile at
  229. <code>node_modules/.package-lock.json</code>, and will likely be used in a future
  230. version of npm, once support for npm v6 is no longer relevant.</li>
  231. </ul>
  232. <p>npm will always attempt to get whatever data it can out of a lockfile, even
  233. if it is not a version that it was designed to support.</p>
  234. <h4 id="packages"><code>packages</code></h4>
  235. <p>This is an object that maps package locations to an object containing the
  236. information about that package.</p>
  237. <p>The root project is typically listed with a key of <code>""</code>, and all other
  238. packages are listed with their relative paths from the root project folder.</p>
  239. <p>Package descriptors have the following fields:</p>
  240. <ul>
  241. <li>
  242. <p>version: The version found in <code>package.json</code></p>
  243. </li>
  244. <li>
  245. <p>resolved: The place where the package was actually resolved from. In
  246. the case of packages fetched from the registry, this will be a url to a
  247. tarball. In the case of git dependencies, this will be the full git url
  248. with commit sha. In the case of link dependencies, this will be the
  249. location of the link target. <code>registry.npmjs.org</code> is a magic value meaning
  250. “the currently configured registry”.</p>
  251. </li>
  252. <li>
  253. <p>integrity: A <code>sha512</code> or <code>sha1</code> <a href="https://w3c.github.io/webappsec/specs/subresourceintegrity/">Standard Subresource
  254. Integrity</a>
  255. string for the artifact that was unpacked in this location.</p>
  256. </li>
  257. <li>
  258. <p>link: A flag to indicate that this is a symbolic link. If this is
  259. present, no other fields are specified, since the link target will also
  260. be included in the lockfile.</p>
  261. </li>
  262. <li>
  263. <p>dev, optional, devOptional: If the package is strictly part of the
  264. <code>devDependencies</code> tree, then <code>dev</code> will be true. If it is strictly part
  265. of the <code>optionalDependencies</code> tree, then <code>optional</code> will be set. If it
  266. is both a <code>dev</code> dependency <em>and</em> an <code>optional</code> dependency of a non-dev
  267. dependency, then <code>devOptional</code> will be set. (An <code>optional</code> dependency of
  268. a <code>dev</code> dependency will have both <code>dev</code> and <code>optional</code> set.)</p>
  269. </li>
  270. <li>
  271. <p>inBundle: A flag to indicate that the package is a bundled dependency.</p>
  272. </li>
  273. <li>
  274. <p>hasInstallScript: A flag to indicate that the package has a <code>preinstall</code>,
  275. <code>install</code>, or <code>postinstall</code> script.</p>
  276. </li>
  277. <li>
  278. <p>hasShrinkwrap: A flag to indicate that the package has an
  279. <code>npm-shrinkwrap.json</code> file.</p>
  280. </li>
  281. <li>
  282. <p>bin, license, engines, dependencies, optionalDependencies: fields from
  283. <code>package.json</code></p>
  284. </li>
  285. </ul>
  286. <h4 id="dependencies">dependencies</h4>
  287. <p>Legacy data for supporting versions of npm that use <code>lockfileVersion: 1</code>.
  288. This is a mapping of package names to dependency objects. Because the
  289. object structure is strictly hierarchical, symbolic link dependencies are
  290. somewhat challenging to represent in some cases.</p>
  291. <p>npm v7 ignores this section entirely if a <code>packages</code> section is present,
  292. but does keep it up to date in order to support switching between npm v6
  293. and npm v7.</p>
  294. <p>Dependency objects have the following fields:</p>
  295. <ul>
  296. <li>
  297. <p>version: a specifier that varies depending on the nature of the package,
  298. and is usable in fetching a new copy of it.</p>
  299. <ul>
  300. <li>bundled dependencies: Regardless of source, this is a version number
  301. that is purely for informational purposes.</li>
  302. <li>registry sources: This is a version number. (eg, <code>1.2.3</code>)</li>
  303. <li>git sources: This is a git specifier with resolved committish. (eg,
  304. <code>git+https://example.com/foo/bar#115311855adb0789a0466714ed48a1499ffea97e</code>)</li>
  305. <li>http tarball sources: This is the URL of the tarball. (eg,
  306. <code>https://example.com/example-1.3.0.tgz</code>)</li>
  307. <li>local tarball sources: This is the file URL of the tarball. (eg
  308. <code>file:///opt/storage/example-1.3.0.tgz</code>)</li>
  309. <li>local link sources: This is the file URL of the link. (eg
  310. <code>file:libs/our-module</code>)</li>
  311. </ul>
  312. </li>
  313. <li>
  314. <p>integrity: A <code>sha512</code> or <code>sha1</code> <a href="https://w3c.github.io/webappsec/specs/subresourceintegrity/">Standard Subresource
  315. Integrity</a>
  316. string for the artifact that was unpacked in this location. For git
  317. dependencies, this is the commit sha.</p>
  318. </li>
  319. <li>
  320. <p>resolved: For registry sources this is path of the tarball relative to
  321. the registry URL. If the tarball URL isn’t on the same server as the
  322. registry URL then this is a complete URL. <code>registry.npmjs.org</code> is a magic
  323. value meaning “the currently configured registry”.</p>
  324. </li>
  325. <li>
  326. <p>bundled: If true, this is the bundled dependency and will be installed
  327. by the parent module. When installing, this module will be extracted
  328. from the parent module during the extract phase, not installed as a
  329. separate dependency.</p>
  330. </li>
  331. <li>
  332. <p>dev: If true then this dependency is either a development dependency ONLY
  333. of the top level module or a transitive dependency of one. This is false
  334. for dependencies that are both a development dependency of the top level
  335. and a transitive dependency of a non-development dependency of the top
  336. level.</p>
  337. </li>
  338. <li>
  339. <p>optional: If true then this dependency is either an optional dependency
  340. ONLY of the top level module or a transitive dependency of one. This is
  341. false for dependencies that are both an optional dependency of the top
  342. level and a transitive dependency of a non-optional dependency of the top
  343. level.</p>
  344. </li>
  345. <li>
  346. <p>requires: This is a mapping of module name to version. This is a list of
  347. everything this module requires, regardless of where it will be
  348. installed. The version should match via normal matching rules a
  349. dependency either in our <code>dependencies</code> or in a level higher than us.</p>
  350. </li>
  351. <li>
  352. <p>dependencies: The dependencies of this dependency, exactly as at the top
  353. level.</p>
  354. </li>
  355. </ul>
  356. <h3 id="see-also">See also</h3>
  357. <ul>
  358. <li><a href="../commands/npm-shrinkwrap.html">npm shrinkwrap</a></li>
  359. <li><a href="../configuring-npm/npm-shrinkwrap-json.html">npm-shrinkwrap.json</a></li>
  360. <li><a href="../configuring-npm/package-json.html">package.json</a></li>
  361. <li><a href="../commands/npm-install.html">npm install</a></li>
  362. </ul>
  363. </div>
  364. <footer id="edit">
  365. <a href="https://github.com/npm/cli/edit/latest/docs/content/configuring-npm/package-lock-json.md">
  366. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  367. <path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
  368. </svg>
  369. Edit this page on GitHub
  370. </a>
  371. </footer>
  372. </section>
  373. </body></html>