@@ -22,13 +22,19 @@ var getPackageJson = require("./get-package-json");
22
22
23
23
var cache = new Cache ( ) ;
24
24
var TAIL_SLASH = / \/ + $ / ;
25
+ var PARENT_RELATIVE_PATH = / ^ \. \. / ;
25
26
var 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;
26
27
27
28
/**
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.
29
35
*/
30
- function alwaysFalse ( ) {
31
- return false ;
36
+ function notAncestorFiles ( filePath ) {
37
+ return PARENT_RELATIVE_PATH . test ( filePath ) ;
32
38
}
33
39
34
40
/**
@@ -45,11 +51,12 @@ function and(f, g) {
45
51
/**
46
52
* @param {function } f - A function.
47
53
* @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`.
49
56
*/
50
- function or ( f , g ) {
57
+ function or ( f , g , h ) {
51
58
return function ( filePath ) {
52
- return f ( filePath ) || g ( filePath ) ;
59
+ return f ( filePath ) || g ( filePath ) || ( h && h ( filePath ) ) ;
53
60
} ;
54
61
}
55
62
@@ -151,7 +158,7 @@ function parseNpmignore(basedir, filesFieldExists) {
151
158
* `match` returns `true` if a given file path should be ignored.
152
159
*/
153
160
module . exports = function getNpmignore ( startPath ) {
154
- var retv = { match : alwaysFalse } ;
161
+ var retv = { match : notAncestorFiles } ;
155
162
156
163
var p = getPackageJson ( startPath ) ;
157
164
if ( p ) {
@@ -164,13 +171,13 @@ module.exports = function getNpmignore(startPath) {
164
171
var npmignoreIgnore = parseNpmignore ( path . dirname ( p . filePath ) , Boolean ( filesIgnore ) ) ;
165
172
166
173
if ( filesIgnore && npmignoreIgnore ) {
167
- retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( filesIgnore , npmignoreIgnore ) ) ;
174
+ retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( notAncestorFiles , filesIgnore , npmignoreIgnore ) ) ;
168
175
}
169
176
else if ( filesIgnore ) {
170
- retv . match = and ( filterNeverIgnoredFiles ( p ) , filesIgnore ) ;
177
+ retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( notAncestorFiles , filesIgnore ) ) ;
171
178
}
172
179
else if ( npmignoreIgnore ) {
173
- retv . match = and ( filterNeverIgnoredFiles ( p ) , npmignoreIgnore ) ;
180
+ retv . match = and ( filterNeverIgnoredFiles ( p ) , or ( notAncestorFiles , npmignoreIgnore ) ) ;
174
181
}
175
182
176
183
cache . put ( p . filePath , retv ) ;
0 commit comments