Skip to content

[BUG] npm pack does not ignore patterns like "dir/" in subdirectories #1873

@pomgui

Description

@pomgui

Current Behavior:

npm pack does not ignore patterns like "dir/" in subdirectories, no matter if it was included in .gitignore or .npmignore.

Expected Behavior:

The npm documentation says:

And the git documentation says:

  • "You can end patterns with a forward slash (/) to specify a directory."
  • "# ignore all files in any directory named build: build/"

Steps To Reproduce:

  1. In a bash environment with awk, grep, diff.
  2. Execute this bash script in an empty directory (it will create all the necessary files and execute the required commands to reproduce the error).
  3. Basically it tries to ignore the pattern "src/" (i.e. any directory with that name).
  4. The output should be the following comparison between git and npm using the same .gitignore file:
npm pack result            git add -A result
------------------------   ------------------------
coverage/index.html        coverage/index.html
dist/file1.js              dist/file1.js
dist/file1.spec.js         dist/file1.spec.js
dist/file2.js              dist/file2.js
dist/file2.spec.js         dist/file2.spec.js
                        >  .gitignore
index.js                   index.js
LICENSE                    LICENSE
package.json               package.json
README.md                  README.md
spec/src/test1.spec.js  <
spec/src/test2.Spec.js  <
test/index.js              test/index.js
test/test1.js              test/test1.js
test/test2.js              test/test2.js

The file .gitignore is ignored by npm as expected, but npm wrongly includes two files inside an internal src directory that git ignores as expected.

Environment:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingRelease 6.xwork is associated with a specific npm 6 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions