@@ -22,13 +22,19 @@ var getPackageJson = require("./get-package-json");
2222
2323var cache = new Cache ( ) ;
2424var TAIL_SLASH = / \/ + $ / ;
25+ var PARENT_RELATIVE_PATH = / ^ \. \. / ;
2526var NEVER_IGNORED = / ^ (?: r e a d m e \. [ ^ \. ] * | (?: l i c e n [ c s ] e | c h a n g e s | c h a n g e l o g | h i s t o r y ) (?: \. [ ^ \. ] * ) ? ) $ / i;
2627
2728/**
28- * @returns {boolean } `false` always.
29+ * Checks whether or not a given file name is a relative path to a ancestor
30+ * directory.
31+ *
32+ * @param {string } filePath - A file name to check.
33+ * @returns {boolean } `true` if the file name is a relative path to a ancestor
34+ * directory.
2935 */
30- function alwaysFalse ( ) {
31- return false ;
36+ function notAncestorFiles ( filePath ) {
37+ return PARENT_RELATIVE_PATH . test ( filePath ) ;
3238}
3339
3440/**
@@ -45,11 +51,12 @@ function and(f, g) {
4551/**
4652 * @param {function } f - A function.
4753 * @param {function } g - A function.
48- * @returns {function } A logical-or function of `f` and `g`.
54+ * @param {function|null } h - A function.
55+ * @returns {function } A logical-or function of `f`, `g`, and `h`.
4956 */
50- function or ( f , g ) {
57+ function or ( f , g , h ) {
5158 return function ( filePath ) {
52- return f ( filePath ) || g ( filePath ) ;
59+ return f ( filePath ) || g ( filePath ) || ( h && h ( filePath ) ) ;
5360 } ;
5461}
5562
@@ -151,7 +158,7 @@ function parseNpmignore(basedir, filesFieldExists) {
151158 * `match` returns `true` if a given file path should be ignored.
152159 */
153160module . exports = function getNpmignore ( startPath ) {
154- var retv = { match : alwaysFalse } ;
161+ var retv = { match : notAncestorFiles } ;
155162
156163 var p = getPackageJson ( startPath ) ;
157164 if ( p ) {
@@ -164,13 +171,13 @@ module.exports = function getNpmignore(startPath) {
164171 var npmignoreIgnore = parseNpmignore ( path . dirname ( p . filePath ) , Boolean ( filesIgnore ) ) ;
165172
166173 if ( filesIgnore && npmignoreIgnore ) {
167- retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( filesIgnore , npmignoreIgnore ) ) ;
174+ retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( notAncestorFiles , filesIgnore , npmignoreIgnore ) ) ;
168175 }
169176 else if ( filesIgnore ) {
170- retv . match = and ( filterNeverIgnoredFiles ( p ) , filesIgnore ) ;
177+ retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( notAncestorFiles , filesIgnore ) ) ;
171178 }
172179 else if ( npmignoreIgnore ) {
173- retv . match = and ( filterNeverIgnoredFiles ( p ) , npmignoreIgnore ) ;
180+ retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( notAncestorFiles , npmignoreIgnore ) ) ;
174181 }
175182
176183 cache . put ( p . filePath , retv ) ;
0 commit comments