<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Files under directories already added to <code class="notranslate">files</code> of package.json cannot be excluded by adding them to <code class="notranslate">files</code> (like <code class="notranslate">!some_directory</code>). Up to npm 6.14.11 it was possible to exclude, but from npm 7.5.2 it is no longer possible.</p>
<ul dir="auto">
<li><code class="notranslate">package.json</code>, <code class="notranslate">src/index.js</code>, <strong><code class="notranslate">src/__tests__/indexTest.js</code></strong> are added to the npm package.</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="❯ npm pack --dry-run      
...
npm notice === Tarball Contents === 
npm notice 97B package.json              
npm notice 0B  src/__tests__/indexTest.js
npm notice 21B src/index.js              
npm notice === Tarball Details === 
...
npm notice total files:   3                                       
..."><pre class="notranslate"><code class="notranslate">❯ npm pack --dry-run      
...
npm notice === Tarball Contents === 
npm notice 97B package.json              
npm notice 0B  src/__tests__/indexTest.js
npm notice 21B src/index.js              
npm notice === Tarball Details === 
...
npm notice total files:   3                                       
...
</code></pre></div>
<h3 dir="auto">Expected Behavior</h3>

<ul dir="auto">
<li><code class="notranslate">package.json</code>, <code class="notranslate">src/index.js</code> are added to the npm package. (use  npm 6.14.11)</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="❯ npm pack --dry-run
...
npm notice === Tarball Contents === 
npm notice 21B src/index.js
npm notice 97B package.json
npm notice === Tarball Details === 
...
npm notice total files:   2                                       
..."><pre class="notranslate"><code class="notranslate">❯ npm pack --dry-run
...
npm notice === Tarball Contents === 
npm notice 21B src/index.js
npm notice 97B package.json
npm notice === Tarball Details === 
...
npm notice total files:   2                                       
...
</code></pre></div>
<h3 dir="auto">Steps to Reproduce</h3>

<ol dir="auto">
<li>Create a package.json</li>
</ol>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;name&quot;: &quot;some-package&quot;,
  &quot;files&quot;: [
    &quot;src&quot;,
    &quot;!__tests__&quot;
  ],
  &quot;version&quot;: &quot;0.0.0&quot;
}"><pre class="notranslate">{
  <span class="pl-ent">"name"</span>: <span class="pl-s"><span class="pl-pds">"</span>some-package<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"files"</span>: [
    <span class="pl-s"><span class="pl-pds">"</span>src<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>!__tests__<span class="pl-pds">"</span></span>
  ],
  <span class="pl-ent">"version"</span>: <span class="pl-s"><span class="pl-pds">"</span>0.0.0<span class="pl-pds">"</span></span>
}</pre></div>
<ol start="2" dir="auto">
<li>Create the following file structure:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  .
  └── src
     ├── index.js
     └── __tests__
        └── indexTest.js"><pre class="notranslate"><code class="notranslate">  .
  └── src
     ├── index.js
     └── __tests__
        └── indexTest.js
</code></pre></div>
<ol start="3" dir="auto">
<li>run <code class="notranslate">npm pack --dry-run</code></li>
</ol>
<h3 dir="auto">Other</h3>
<p dir="auto">By using wildcards, you can exclude them in both npm v6/v7. (ex. <code class="notranslate">!__tests__</code> -&gt; <code class="notranslate">!**/__tests__</code>)</p>
<h3 dir="auto">Environment:</h3>
<ul dir="auto">
<li>OS: macOS 11.1</li>
<li>Node: 12.18.2</li>
<li>npm: 7.5.2</li>
</ul>
<h3 dir="auto">Current Behavior:</h3>
<p dir="auto"><code class="notranslate">npm publish --dry-run</code> includes <code class="notranslate">__tests__</code> and <code class="notranslate">__mocks__</code></p>
<p dir="auto">package.json:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  &quot;files&quot;: [
    &quot;dist/**&quot;,
    &quot;!__mocks__&quot;,
    &quot;!__tests__&quot;,
    &quot;package.json&quot;,
    &quot;README.md&quot;
  ]"><pre class="notranslate">  <span class="pl-ent">"files"</span>: [
    <span class="pl-s"><span class="pl-pds">"</span>dist/**<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>!__mocks__<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>!__tests__<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>package.json<span class="pl-pds">"</span></span>,
    <span class="pl-s"><span class="pl-pds">"</span>README.md<span class="pl-pds">"</span></span>
  ]</pre></div>
<h3 dir="auto">Expected Behavior:</h3>
<p dir="auto">should exclude <code class="notranslate">__tests__</code> and <code class="notranslate">__mocks__</code></p>
<p dir="auto">works with npm <code class="notranslate">v6.14.9</code>.</p>
<h3 dir="auto">Steps To Reproduce:</h3>
<p dir="auto">see above</p>
<h3 dir="auto">Environment:</h3>
<ul dir="auto">
<li>OS: MacOs Catalina v10.15.7</li>
<li>Node: 15.5.0</li>
<li>npm: 7.3.0</li>
</ul>