npmc
Version:
a package manager for JavaScript
77 lines (70 loc) • 6.37 kB
HTML
<html>
<title>npm-archive</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../../static/style.css">
<link rel="canonical" href="https://www.npmjs.org/doc/cli/npm-archive.html">
<script async=true src="../../static/toc.js"></script>
<body>
<div id="wrapper">
<h1><a href="../cli/npm-archive.html">npm-archive</a></h1> <p>Project-local dependency tarball archive</p>
<h2 id="synopsis">SYNOPSIS</h2>
<pre><code>npm archive
</code></pre><h2 id="example">EXAMPLE</h2>
<p>Make sure you have a package-lock and an up-to-date install:</p>
<pre><code>$ cd ./my/npm/project
$ npm install
added 154 packages in 10s
$ ls | grep package-lock
</code></pre><p>Run <code>npm archive</code> in that project</p>
<pre><code>$ npm archive
added 1964 packages in 4.103s
</code></pre><p>Commit the newly-created <code>archived-packages/</code> directory and the modified <code>package-lock.json</code></p>
<pre><code>$ git add package-lock.json archived-packages/
$ git commit -m 'misc: committing dependency archive'
</code></pre><p>Add a dependency as usual -- its archive will be automatically managed.</p>
<pre><code>$ npm i aubergine
added 1 package from 1 contributor in 5s
$ git status
M package-lock.json
M package.json
?? archived-packages/aubergine-1.0.1-46c5742af.tar
$ git add archived-packages package-lock.json package.json
$ git commit -m 'deps: aubergine@1.0.1'
</code></pre><p>The inverse happens when a package is removed.</p>
<p>You can then install normally using <code><a href="../cli/npm-ci.html">npm-ci(1)</a></code> or <code><a href="../cli/npm-install.html">npm-install(1)</a></code>!</p>
<pre><code>$ npm ci
added 1965 packages in 10.5s
</code></pre><p>Finally, you can remove and disable the archive, restoring <code>package-lock.json</code> its normal state, by using <code><a href="../cli/npm-unarchive.html">npm-unarchive(1)</a></code>.</p>
<pre><code>$ npm unarchive
</code></pre><h2 id="description">DESCRIPTION</h2>
<p>This command generates a committable archive of your project's dependencies. There are several benefits to this:</p>
<ol>
<li>Offline installs without having to warm up npm's global cache</li>
<li>No need for configuring credentials for dependency fetching</li>
<li>Much faster installs vs standard CI configurations</li>
<li>No need to have a <code>git</code> binary present in the system</li>
<li>Reduced download duplication across teams</li>
</ol>
<p><code>npm-archive</code> works by generating tarballs for your dependencies, unzipping them, and storing them in a directory called <code>archived-packages/</code>. It then rewrites your <code>package-lock.json</code> (or <code>npm-shrinkwrap.json</code>) such that the <code>resolved</code> field on those dependencies refers to the path in <code>archived-packages/</code>.</p>
<p>npm will detect these <code>file:</code> URLs and extract package data directly from them instead of the registry, git repositories, etc.</p>
<p>When installing or removing dependencies, npm will look for <code>archived-packages/</code> and switch to an "archive mode", which will automatically update archive files and information on every relevant npm operation. Remember to commit the directory, not just <code>package-lock.json</code>!</p>
<p>As an added benefit, <code>npm-archive</code> will generate tarballs for all your git dependencies and pre-pack them, meaning npm will not need to invoke the git binary or go through other heavy processes git dependencies go to -- making git deps as fast as registry dependencies when reinstalling from an archive.</p>
<p>If specific tarballs are removed from the archive, npm will fall back to standard behavior for fetching dependencies: first checking its global cache, then going out and fetching the dependency from its origin. To regenerate the tarball for a package after removing it, just reinstall the package while in archive mode.</p>
<h2 id="see-also">SEE ALSO</h2>
<ul>
<li><a href="../cli/npm-unarchive.html">npm-unarchive(1)</a></li>
<li><a href="../files/npm-package-locks.html">npm-package-locks(5)</a></li>
<li><a href="../cli/npm-ci.html">npm-ci(1)</a></li>
</ul>
</div>
<table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
<tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18> </td></tr>
<tr><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)"> </td><td style="width:40px;height:10px;background:#fff" colspan=4> </td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4> </td><td style="width:40px;height:10px;background:#fff" colspan=4> </td><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)"> </td><td colspan=6 style="width:60px;height:10px;background:#fff"> </td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4> </td></tr>
<tr><td colspan=2 style="width:20px;height:30px;background:#fff" rowspan=3> </td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3> </td><td style="width:10px;height:10px;background:#fff" rowspan=3> </td><td style="width:20px;height:10px;background:#fff" rowspan=4 colspan=2> </td><td style="width:10px;height:20px;background:rgb(237,127,127)" rowspan=2> </td><td style="width:10px;height:10px;background:#fff" rowspan=3> </td><td style="width:20px;height:10px;background:#fff" rowspan=3 colspan=2> </td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3> </td><td style="width:10px;height:10px;background:#fff" rowspan=3> </td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3> </td></tr>
<tr><td style="width:10px;height:10px;background:#fff" rowspan=2> </td></tr>
<tr><td style="width:10px;height:10px;background:#fff"> </td></tr>
<tr><td style="width:60px;height:10px;background:rgb(237,127,127)" colspan=6> </td><td colspan=10 style="width:10px;height:10px;background:rgb(237,127,127)"> </td></tr>
<tr><td colspan=5 style="width:50px;height:10px;background:#fff"> </td><td style="width:40px;height:10px;background:rgb(237,127,127)" colspan=4> </td><td style="width:90px;height:10px;background:#fff" colspan=9> </td></tr>
</table>
<p id="footer">npm-archive — npm@6.0.1-canary.2</p>