findup-sync
Advanced tools
Comparing version 0.4.2 to 0.4.3
54
index.js
@@ -22,4 +22,7 @@ 'use strict'; | ||
module.exports = function(patterns, options) { | ||
options = options || {}; | ||
var cwd = path.resolve(resolveDir(options.cwd || '')); | ||
if (typeof patterns === 'string') { | ||
return lookup(patterns, options); | ||
return lookup(cwd, [patterns], options); | ||
} | ||
@@ -31,7 +34,16 @@ | ||
return lookup(cwd, patterns, options); | ||
}; | ||
function lookup(cwd, patterns, options) { | ||
var len = patterns.length; | ||
var idx = -1; | ||
var res; | ||
while (++idx < len) { | ||
var res = lookup(patterns[idx], options); | ||
if (isGlob(patterns[idx])) { | ||
res = matchFile(cwd, patterns[idx], options); | ||
} else { | ||
res = findFile(cwd, patterns[idx], options); | ||
} | ||
if (res) { | ||
@@ -42,13 +54,7 @@ return res; | ||
return null; | ||
}; | ||
function lookup(pattern, options) { | ||
options = options || {}; | ||
var cwd = path.resolve(resolveDir(options.cwd || '')); | ||
if (isGlob(pattern)) { | ||
return matchFile(cwd, pattern, options); | ||
} else { | ||
return findFile(cwd, pattern, options); | ||
var dir = path.dirname(cwd); | ||
if (dir === cwd) { | ||
return null; | ||
} | ||
return lookup(dir, patterns, options); | ||
} | ||
@@ -69,28 +75,8 @@ | ||
} | ||
var dir = path.dirname(cwd); | ||
if (dir === cwd) { | ||
return null; | ||
} | ||
return matchFile(dir, pattern, opts); | ||
return null; | ||
} | ||
function findFile(cwd, filename, options) { | ||
var res; | ||
var fp = cwd ? path.resolve(cwd, filename) : filename; | ||
if (res = detect(fp, options)) { | ||
return res; | ||
} | ||
var segs = cwd.split(path.sep); | ||
var len = segs.length; | ||
while (len--) { | ||
cwd = segs.slice(0, len).join(path.sep); | ||
fp = path.resolve(cwd, filename); | ||
if (res = detect(fp, options)) { | ||
return res; | ||
} | ||
} | ||
return null; | ||
return detect(fp, options); | ||
} | ||
@@ -97,0 +83,0 @@ |
{ | ||
"name": "findup-sync", | ||
"description": "Find the first file matching a given pattern in the current directory or the nearest ancestor directory.", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"homepage": "https://github.com/cowboy/node-findup-sync", | ||
@@ -6,0 +6,0 @@ "author": "\"Cowboy\" Ben Alman (http://benalman.com)", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
5506
3
0
68
71
1