isaacs/npm — Issue #1912: Should .npmignore work like .gitignore?
Author: quackingduck
Created: 2011-12-21 06:02:37+00:00
State: open

Node & npm versions

$ node --version
v0.6.6
$ npm --version
1.0.106

Package structure

$ tree -a npm-ignore-test
npm-ignore-test
├── .npmignore
├── dir-to-be-ignored
│ └── foo.txt
└── package.json
1 directory, 3 files
$ cat npm-ignore-test/package.json
{
"name": "npm-ignore-test",
"version": "1.0.0"
}

Prefix slash - git will only ignore dir in repo root. Seems to have no effect in npm

$ echo "/dir-to-be-ignored" > npm-ignore-test/.npmignore
$ npm pack npm-ignore-test && tar -zxvf npm-ignore-test-1.0.0.tgz
./npm-ignore-test-1.0.0.tgz
x package/.npmignore
x package/package.json
x package/dir-to-be-ignored/foo.txt

No slash - git will ignore matching dirs anywhere in repo, also appears to be ignored by npm

$ echo "dir-to-be-ignored" > npm-ignore-test/.npmignore
$ npm pack npm-ignore-test && tar -zxvf npm-ignore-test-1.0.0.tgz
./npm-ignore-test-1.0.0.tgz
x package/.npmignore
x package/package.json
x package/dir-to-be-ignored/foo.txt

Trailing slash - npm _will_ ignore a directory when it sees a trailing slash

$ echo "dir-to-be-ignored/" > npm-ignore-test/.npmignore
$ npm pack npm-ignore-test && tar -zxvf npm-ignore-test-1.0.0.tgz
./npm-ignore-test-1.0.0.tgz
x package/.npmignore
x package/package.json

Is this the expected behavior?