<h1 dir="auto">What / Why</h1>
<p dir="auto"><code class="notranslate">npm</code> keeps creating its cache directory in my <code class="notranslate">$HOME</code>. I keep very few directories in my <code class="notranslate">$HOME</code> to keep things findable, and its very annoying when apps start littering stuff there.</p>
<h2 dir="auto">When</h2>
<p dir="auto">Any time I run things like <code class="notranslate">npm install blah</code>.</p>
<h2 dir="auto">Where</h2>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ uname -srmo
Linux 5.7.2-arch1-1 x86_64 GNU/Linux"><pre class="notranslate">$ <span class="pl-s1">uname -srmo</span>
<span class="pl-c1">Linux 5.7.2-arch1-1 x86_64 GNU/Linux</span></pre></div>
<h2 dir="auto">How</h2>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">A directory is creted in <code class="notranslate">$HOME</code> and cache data stored in there.</p>
<h3 dir="auto">Steps to Reproduce</h3>
<ol start="0" dir="auto">
<li>Run <code class="notranslate">rm -rf .cache</code> to delete your existing cache.</li>
<li>Navigate to a directory with an existing <code class="notranslate">package.json</code>.</li>
<li>Run <code class="notranslate">npm install</code>.</li>
</ol>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">The cache directory should be in <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html" rel="nofollow"><code class="notranslate">$XDG_CACHE_HOME</code></a> on Linux. Specifically, it should be <code class="notranslate">$XDG_CACHE_HOME/npm</code>. <code class="notranslate">$XDG_CACHE_HOME</code> should default to <code class="notranslate">.cache</code> if undefined.</p>
<p dir="auto">I believe on macOS there's a different spec for default locations, and things like cache are stored in a different place. I don't know the name of the spec so can't easily link in here.</p>
<h2 dir="auto">Who</h2>
<ul dir="auto">
<li>n/a</li>
</ul>
<h2 dir="auto">References</h2>
<p dir="auto"><a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html" rel="nofollow">XDG Base Directory Specification</a></p>
<h3 dir="auto">Is there an existing issue for this?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the existing issues</li>
</ul>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">I'm trying to link 2 packages and I know this worked at some point in the past. The current process is running the following commands one after another</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm link guidemaker
npm link guidemaker-default-template"><pre class="notranslate"><code class="notranslate">npm link guidemaker
npm link guidemaker-default-template
</code></pre></div>
<p dir="auto">after the first link <code class="notranslate">guidemaker</code> is linked correctly, but after you run the second link it removes the link to <code class="notranslate">guidemaker</code> and only has the link to <code class="notranslate">guidemaker-ember-template</code></p>
<p dir="auto">while I was writing this section I wondered if the problem was running them "one after another" and I tried</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm link guidemaker guidemaker-default-template"><pre class="notranslate"><code class="notranslate">npm link guidemaker guidemaker-default-template
</code></pre></div>
<p dir="auto">which happened to work <g-emoji class="g-emoji" alias="see_no_evil" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f648.png">🙈</g-emoji></p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">I expect that running link twice with two different packages should just link both those packages. It's nice to have the workaround that I described above but this is quite confusing for people.</p>
<p dir="auto">I know that there are existing issues around <a href="https://github.com/npm/cli/issues/2380" data-hovercard-type="issue" data-hovercard-url="/npm/cli/issues/2380/hovercard">running <code class="notranslate">npm install</code> removing links</a> but that isn't related to the expected behaviour that I have for this feature.</p>
<h3 dir="auto">Steps To Reproduce</h3>
<ol dir="auto">
<li>checkout and run <code class="notranslate">npm link</code> in guidemaker (or any npm package)</li>
<li>checkout and run <code class="notranslate">npm link</code> in guidemaker-default-template</li>
<li>go to a new node project with a package.json (ember app in my case)</li>
<li>run <code class="notranslate">npm link guidemaker</code></li>
<li>run <code class="notranslate">npm link guidemaker-default-template</code></li>
</ol>
<h3 dir="auto">Environment</h3>
<p dir="auto">OS: macOS 11.4<br>
npm: '7.20.0',<br>
node: '12.18.1',</p>