Comparing version 0.4.1 to 0.5.0
69
index.js
@@ -10,3 +10,4 @@ 'use strict'; | ||
var isGlob = require('is-glob'); | ||
var mm = require('multimatch'); | ||
var mm = require('micromatch'); | ||
var dir = process.cwd(); | ||
@@ -27,28 +28,31 @@ /** | ||
options = options || {matchBase: true}; | ||
var cwd = options.cwd || process.cwd(); | ||
var plen = patterns.length; | ||
var opts = options || {}; | ||
var cwd = opts.cwd || process.cwd(); | ||
var len = patterns.length; | ||
// loop over patterns | ||
while (plen--) { | ||
var pattern = patterns[plen]; | ||
while (len--) { | ||
var pattern = patterns[len]; | ||
// if the pattern is a glob pattern, move on | ||
if (isGlob(pattern)) { | ||
continue; | ||
if (!isGlob(pattern)) { | ||
// if the pattern is not a glob pattern, try | ||
// to see if it resolves to an actual file so | ||
// we can avoid using fs.readdir and matching | ||
var file = path.join(cwd, pattern); | ||
if (fs.existsSync(file)) { | ||
return file; | ||
} | ||
} else if (!/\*\*/.test(pattern)) { | ||
opts.matchBase = true; | ||
} | ||
// if the pattern is not a glob pattern, try | ||
// to see if it resolves to an actual file so | ||
// we can avoid using minimatch | ||
var tmp = path.join(cwd, pattern); | ||
if (fs.existsSync(tmp)) { | ||
return tmp; | ||
} | ||
} | ||
var files = fs.readdirSync(cwd); | ||
var len = files.length; | ||
var flen = files.length; | ||
// loop through the files in the current directory | ||
while (len--) { | ||
var fp = path.join(cwd, files[len]); | ||
while (flen--) { | ||
var fp = path.join(cwd, files[flen]); | ||
@@ -58,22 +62,19 @@ // if the current directory is the actual cwd, break out | ||
// check the file path to see if it matches the pattern(s) | ||
var match = mm(fp, patterns, options); | ||
if (match.length === 0) { | ||
continue; | ||
// if the file path matches the pattern(s), return it | ||
var match = mm(fp, patterns, opts); | ||
if (match.length !== 0) { | ||
return fp; | ||
} | ||
return fp; | ||
} | ||
// since nothing was matched in the last dir, | ||
// move up a directory and create a new `cwd` for the search | ||
cwd = path.join(cwd, '..'); | ||
if (cwd !== '..') { | ||
// since we haven't run out of dirs yet, try again | ||
options.cwd = cwd; | ||
return lookup(patterns, options); | ||
} | ||
// nothing was matched in the last dir, so move up a | ||
// directory and create a new `cwd` for the search | ||
cwd = path.resolve(cwd, '..'); | ||
// if we're here, it means we're past the actual cwd | ||
// so we've gone too far, no matches... | ||
return null; | ||
// we're past the actual cwd with no matches. | ||
if (cwd === dir) return null; | ||
// try again | ||
opts.cwd = cwd; | ||
return lookup(patterns, opts); | ||
}; |
{ | ||
"name": "look-up", | ||
"description": "Like findup-sync and supports the same features but 20x-40x faster on avg.", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/jonschlinkert/look-up", | ||
@@ -29,13 +29,13 @@ "author": { | ||
"dependencies": { | ||
"is-glob": "^0.1.0", | ||
"multimatch": "^1.0.1" | ||
"is-glob": "^1.1.0", | ||
"micromatch": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"benchmarked": "^0.1.2", | ||
"benchmarked": "^0.1.3", | ||
"chalk": "^0.5.1", | ||
"findup-sync": "^0.1.3", | ||
"findup-sync": "^0.2.1", | ||
"mocha": "*", | ||
"normalize-path": "^0.3.0", | ||
"resolve": "^1.0.0", | ||
"should": "^4.1.0" | ||
"should": "*" | ||
}, | ||
@@ -42,0 +42,0 @@ "keywords": [ |
@@ -69,3 +69,3 @@ # look-up [![NPM version](https://badge.fury.io/js/look-up.svg)](http://badge.fury.io/js/look-up) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
@@ -75,5 +75,5 @@ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on December 18, 2014._ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on January 19, 2015._ | ||
[minimatch]: http://github.com/isaacs/minimatch | ||
[findup-sync]: https://github.com/cowboy/node-findup-sync |
5989
61
+ Addedmicromatch@^1.0.1
+ Addedansi@0.3.1(transitive)
+ Addedansi-regex@0.2.12.1.1(transitive)
+ Addedansi-styles@1.1.02.2.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarr-diff@1.1.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-map@1.0.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-slice@0.2.3(transitive)
+ Addedasync-array-reduce@0.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbenchmark@1.0.0(transitive)
+ Addedbenchmarked@0.1.5(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedcamel-case@1.2.2(transitive)
+ Addedchalk@0.5.11.1.3(transitive)
+ Addedclone@1.0.4(transitive)
+ Addedclone-stats@0.0.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedexpand-tilde@1.2.2(transitive)
+ Addedextend-shallow@1.1.42.0.1(transitive)
+ Addedextglob@0.2.0(transitive)
+ Addedfile-reader@1.1.1(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@0.1.81.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedfs-exists-sync@0.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-base@0.1.1(transitive)
+ Addedglob-parent@1.3.0(transitive)
+ Addedglob-path-regex@1.0.0(transitive)
+ Addedglobal-modules@0.2.3(transitive)
+ Addedglobal-prefix@0.1.5(transitive)
+ Addedhas-ansi@0.1.02.0.0(transitive)
+ Addedhas-glob@0.1.1(transitive)
+ Addedhas-values@0.1.4(transitive)
+ Addedhomedir-polyfill@1.0.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@1.1.32.0.1(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-valid-glob@0.3.0(transitive)
+ Addedis-windows@0.2.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisobject@0.2.02.1.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedkind-of@1.1.03.2.26.0.3(transitive)
+ Addedlazy-cache@1.0.42.0.2(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedmap-files@0.8.2(transitive)
+ Addedmatched@0.4.4(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@1.6.2(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.0.0(transitive)
+ Addedobject.omit@0.2.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedparse-glob@2.1.1(transitive)
+ Addedparse-passwd@1.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedread-yaml@1.1.0(transitive)
+ Addedregex-cache@0.3.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedreplace-ext@0.0.1(transitive)
+ Addedresolve-dir@0.1.1(transitive)
+ Addedsentence-case@1.1.3(transitive)
+ Addedset-getter@0.1.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstrip-ansi@0.3.03.0.1(transitive)
+ Addedsupports-color@0.2.02.0.0(transitive)
+ Addedto-key@1.0.0(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedvinyl@1.2.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedmultimatch@^1.0.1
- Removedarray-differ@1.0.0(transitive)
- Removedarray-union@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedis-glob@0.1.0(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@1.0.0(transitive)
- Removedmultimatch@1.0.1(transitive)
- Removedsigmund@1.0.1(transitive)
Updatedis-glob@^1.1.0