pax_global_header00006660000000000000000000000064127775271620014532gustar00rootroot0000000000000052 comment=701fd1044e1e26936aa066a35281ffdfb0b37d43 node-findup-sync-0.4.3/000077500000000000000000000000001277752716200147205ustar00rootroot00000000000000node-findup-sync-0.4.3/.gitattributes000066400000000000000000000001411277752716200176070ustar00rootroot00000000000000# Enforce Unix newlines *.* text eol=lf *.jpg binary *.gif binary *.png binary *.jpeg binarynode-findup-sync-0.4.3/.gitignore000066400000000000000000000000761277752716200167130ustar00rootroot00000000000000*.DS_Store *.sublime-* node_modules npm-debug.log test/actual node-findup-sync-0.4.3/.jshintrc000066400000000000000000000004551277752716200165510ustar00rootroot00000000000000{ "asi": false, "boss": true, "curly": true, "eqeqeq": true, "eqnull": true, "esnext": true, "immed": true, "latedef": false, "laxbreak": true, "laxcomma": false, "newcap": true, "noarg": true, "node": true, "sub": true, "undef": true, "unused": true, "mocha": true }node-findup-sync-0.4.3/.travis.yml000066400000000000000000000002571277752716200170350ustar00rootroot00000000000000sudo: false language: node_js os: - linux - osx node_js: - "6" - "5" - "4" - "0.12" - "0.10" matrix: fast_finish: true allow_failures: - node_js: "0.10" node-findup-sync-0.4.3/Gruntfile.js000066400000000000000000000005501277752716200172150ustar00rootroot00000000000000'use strict'; module.exports = function(grunt) { // Project configuration. grunt.initConfig({ jshint: { options: { jshintrc: '.jshintrc' }, all: ['*.js', 'test/{,support/}*.js'] } }); // Load plugins. grunt.loadNpmTasks('grunt-contrib-jshint'); // Default task. grunt.registerTask('default', ['jshint']); }; node-findup-sync-0.4.3/LICENSE-MIT000066400000000000000000000021041277752716200163510ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2013-2016, "Cowboy" Ben Alman. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-findup-sync-0.4.3/README.md000066400000000000000000000044721277752716200162060ustar00rootroot00000000000000# findup-sync [![Build Status](https://travis-ci.org/js-cli/node-findup-sync.svg)](https://travis-ci.org/js-cli/node-findup-sync) [![NPM version](https://badge.fury.io/js/findup-sync.svg)](http://badge.fury.io/js/findup-sync) > Find the first file matching a given pattern in the current directory or the nearest ancestor directory. Matching is done with [micromatch][], please report any matching related issues on that repository. ## Install with [npm](npmjs.org) ```bash npm i findup-sync --save ``` ## Usage ```js var findup = require('findup-sync'); findup(patternOrPatterns [, micromatchOptions]); // Start looking in the CWD. var filepath1 = findup('{a,b}*.txt'); // Start looking somewhere else, and ignore case (probably a good idea). var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true}); ``` * `patterns` **{String|Array}**: Glob pattern(s) or file path(s) to match against. * `options` **{Object}**: Options to pass to [micromatch]. Note that if you want to start in a different directory than the current working directory, specify a `cwd` property here. * `returns` **{String}**: Returns the first matching file. ## Running tests Install dev dependencies: ```bash npm i -d && npm test ``` ## Contributing In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/) For bugs and feature requests, [please create an issue](https://github.com/cowboy/node-findup-sync/issues). ## Release History 2015-01-30 - v0.4.0 - Refactored, not also uses [micromatch][] instead of minimatch. 2015-09-14 - v0.3.0 - updated glob to ~5.0. 2014-12-17 - v0.2.1 - Updated to glob 4.3. 2014-12-16 - v0.2.0 - Removed lodash, updated to glob 4.x. 2014-03-14 - v0.1.3 - Updated dependencies. 2013-03-08 - v0.1.2 - Updated dependencies. Fixed a Node 0.9.x bug. Updated unit tests to work cross-platform. 2012-11-15 - v0.1.1 - Now works without an options object. 2012-11-01 - v0.1.0 - Initial release. ## Authors **"Cowboy" Ben Alman** + [github/cowboy](https://github.com/cowboy) + [twitter/cowboy](http://twitter.com/cowboy) ## License Copyright (c) 2012-2016 "Cowboy" Ben Alman Released under the MIT license [micromatch]: http://github.com/jonschlinkert/micromatch node-findup-sync-0.4.3/index.js000066400000000000000000000037201277752716200163670ustar00rootroot00000000000000'use strict'; /** * Module dependencies */ var fs = require('fs'); var path = require('path'); var isGlob = require('is-glob'); var resolveDir = require('resolve-dir'); var detect = require('detect-file'); var mm = require('micromatch'); /** * @param {String|Array} `pattern` Glob pattern or file path(s) to match against. * @param {Object} `options` Options to pass to [micromatch]. Note that if you want to start in a different directory than the current working directory, specify the `options.cwd` property here. * @return {String} Returns the first matching file. * @api public */ module.exports = function(patterns, options) { options = options || {}; var cwd = path.resolve(resolveDir(options.cwd || '')); if (typeof patterns === 'string') { return lookup(cwd, [patterns], options); } if (!Array.isArray(patterns)) { throw new TypeError('findup-sync expects a string or array as the first argument.'); } return lookup(cwd, patterns, options); }; function lookup(cwd, patterns, options) { var len = patterns.length; var idx = -1; var res; while (++idx < len) { if (isGlob(patterns[idx])) { res = matchFile(cwd, patterns[idx], options); } else { res = findFile(cwd, patterns[idx], options); } if (res) { return res; } } var dir = path.dirname(cwd); if (dir === cwd) { return null; } return lookup(dir, patterns, options); } function matchFile(cwd, pattern, opts) { var isMatch = mm.matcher(pattern, opts); var files = tryReaddirSync(cwd); var len = files.length; var idx = -1; while (++idx < len) { var name = files[idx]; var fp = path.join(cwd, name); if (isMatch(name) || isMatch(fp)) { return fp; } } return null; } function findFile(cwd, filename, options) { var fp = cwd ? path.resolve(cwd, filename) : filename; return detect(fp, options); } function tryReaddirSync(fp) { try { return fs.readdirSync(fp); } catch(err) {} return []; } node-findup-sync-0.4.3/package.json000066400000000000000000000021701277752716200172060ustar00rootroot00000000000000{ "name": "findup-sync", "description": "Find the first file matching a given pattern in the current directory or the nearest ancestor directory.", "version": "0.4.3", "homepage": "https://github.com/cowboy/node-findup-sync", "author": "\"Cowboy\" Ben Alman (http://benalman.com)", "repository": "cowboy/node-findup-sync", "bugs": { "url": "https://github.com/cowboy/node-findup-sync/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">= 0.8.0" }, "scripts": { "test": "grunt && mocha" }, "dependencies": { "detect-file": "^0.1.0", "is-glob": "^2.0.1", "micromatch": "^2.3.7", "resolve-dir": "^0.1.0" }, "devDependencies": { "fs-exists-sync": "^0.1.0", "grunt": "^1.0.1", "grunt-contrib-jshint": "^0.12.0", "is-absolute": "^0.2.3", "minimist": "^1.2.0", "mocha": "^2.4.5", "normalize-path": "^2.0.1", "os-homedir": "^1.0.1", "resolve": "^1.1.7" }, "keywords": [ "file", "find", "find-up", "findup", "glob", "match", "pattern", "resolve", "search" ] } node-findup-sync-0.4.3/test/000077500000000000000000000000001277752716200156775ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/000077500000000000000000000000001277752716200175505ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/Mochafile.txt000066400000000000000000000000051277752716200221730ustar00rootroot00000000000000root node-findup-sync-0.4.3/test/fixtures/a/000077500000000000000000000000001277752716200177705ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/Mochafile.txt000066400000000000000000000000021277752716200224100ustar00rootroot00000000000000a node-findup-sync-0.4.3/test/fixtures/a/a.txt000066400000000000000000000000021277752716200207410ustar00rootroot00000000000000a node-findup-sync-0.4.3/test/fixtures/a/b/000077500000000000000000000000001277752716200202115ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/.config/000077500000000000000000000000001277752716200215345ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/.config/waldo000066400000000000000000000000001277752716200225530ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/Mochafile.txt000066400000000000000000000000021277752716200226310ustar00rootroot00000000000000b node-findup-sync-0.4.3/test/fixtures/a/b/ONE.js000066400000000000000000000000001277752716200211560ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/a.md000066400000000000000000000000001277752716200207410ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/b.txt000066400000000000000000000000021277752716200211630ustar00rootroot00000000000000b node-findup-sync-0.4.3/test/fixtures/a/b/c/000077500000000000000000000000001277752716200204335ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/Mochafile.txt000066400000000000000000000000021277752716200230530ustar00rootroot00000000000000c node-findup-sync-0.4.3/test/fixtures/a/b/c/ONE.txt000066400000000000000000000000001277752716200216030ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/c.txt000066400000000000000000000000021277752716200214060ustar00rootroot00000000000000c node-findup-sync-0.4.3/test/fixtures/a/b/c/d/000077500000000000000000000000001277752716200206565ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/Mochafile.txt000066400000000000000000000000021277752716200232760ustar00rootroot00000000000000d node-findup-sync-0.4.3/test/fixtures/a/b/c/d/d.txt000066400000000000000000000000021277752716200216320ustar00rootroot00000000000000d node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/000077500000000000000000000000001277752716200211025ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/Mochafile.txt000066400000000000000000000000021277752716200235220ustar00rootroot00000000000000e node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/e.txt000066400000000000000000000000021277752716200220570ustar00rootroot00000000000000e node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/000077500000000000000000000000001277752716200213275ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/Mochafile.txt000066400000000000000000000000021277752716200237470ustar00rootroot00000000000000f node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/f.txt000066400000000000000000000000021277752716200223050ustar00rootroot00000000000000f node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/file.txt000066400000000000000000000000021277752716200227770ustar00rootroot00000000000000f node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/000077500000000000000000000000001277752716200215555ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/Mochafile.txt000066400000000000000000000000021277752716200241750ustar00rootroot00000000000000g node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/file.txt000066400000000000000000000000021277752716200232250ustar00rootroot00000000000000g node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/g.txt000066400000000000000000000000021277752716200225340ustar00rootroot00000000000000g node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/000077500000000000000000000000001277752716200220045ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/Mochafile.txt000066400000000000000000000000021277752716200244240ustar00rootroot00000000000000h node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/file.txt000066400000000000000000000000021277752716200234540ustar00rootroot00000000000000h node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/h.txt000066400000000000000000000000021277752716200227640ustar00rootroot00000000000000h node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/000077500000000000000000000000001277752716200222345ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/Mochafile.txt000066400000000000000000000000021277752716200246540ustar00rootroot00000000000000i node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/file.txt000066400000000000000000000000021277752716200237040ustar00rootroot00000000000000i node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/i.txt000066400000000000000000000000021277752716200232150ustar00rootroot00000000000000i node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/j/000077500000000000000000000000001277752716200224655ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/j/Mochafile.txt000066400000000000000000000000021277752716200251050ustar00rootroot00000000000000j node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/j/file.txt000066400000000000000000000000021277752716200241350ustar00rootroot00000000000000j node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/j/j.txt000066400000000000000000000000021277752716200234470ustar00rootroot00000000000000j node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/j/package.json000066400000000000000000000000001277752716200247410ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/i/package.json000066400000000000000000000000001277752716200245100ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/h/package.json000066400000000000000000000000731277752716200242720ustar00rootroot00000000000000{ "name": "h", "description": "package.json from h." } node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/g/package.json000066400000000000000000000000731277752716200240430ustar00rootroot00000000000000{ "name": "g", "description": "package.json from g." } node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/f/package.json000066400000000000000000000000731277752716200236150ustar00rootroot00000000000000{ "name": "f", "description": "package.json from f." } node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/file.txt000066400000000000000000000000021277752716200225520ustar00rootroot00000000000000e node-findup-sync-0.4.3/test/fixtures/a/b/c/d/e/package.json000066400000000000000000000000731277752716200233700ustar00rootroot00000000000000{ "name": "e", "description": "package.json from e." } node-findup-sync-0.4.3/test/fixtures/a/b/c/d/file.txt000066400000000000000000000000021277752716200223260ustar00rootroot00000000000000d node-findup-sync-0.4.3/test/fixtures/a/b/c/d/one.txt000066400000000000000000000000001277752716200221660ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/c/d/package.json000066400000000000000000000000731277752716200231440ustar00rootroot00000000000000{ "name": "d", "description": "package.json from d." } node-findup-sync-0.4.3/test/fixtures/a/b/c/file.txt000066400000000000000000000000021277752716200221030ustar00rootroot00000000000000c node-findup-sync-0.4.3/test/fixtures/a/b/c/package.json000066400000000000000000000000731277752716200227210ustar00rootroot00000000000000{ "name": "c", "description": "package.json from c." } node-findup-sync-0.4.3/test/fixtures/a/b/c/two.txt000066400000000000000000000000001277752716200217730ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/file.txt000066400000000000000000000000021277752716200216610ustar00rootroot00000000000000b node-findup-sync-0.4.3/test/fixtures/a/b/one.txt000066400000000000000000000000001277752716200215210ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/b/package.json000066400000000000000000000000731277752716200224770ustar00rootroot00000000000000{ "name": "b", "description": "package.json from b." } node-findup-sync-0.4.3/test/fixtures/a/file.txt000066400000000000000000000000021277752716200214400ustar00rootroot00000000000000a node-findup-sync-0.4.3/test/fixtures/a/one.txt000066400000000000000000000000001277752716200213000ustar00rootroot00000000000000node-findup-sync-0.4.3/test/fixtures/a/package.json000066400000000000000000000000731277752716200222560ustar00rootroot00000000000000{ "name": "a", "description": "package.json from a." } node-findup-sync-0.4.3/test/fixtures/file.txt000066400000000000000000000000051277752716200212230ustar00rootroot00000000000000root node-findup-sync-0.4.3/test/fixtures/package.json000066400000000000000000000001131277752716200220310ustar00rootroot00000000000000{ "name": "fixtures", "description": "package.json from ./fixtures." } node-findup-sync-0.4.3/test/fixtures/root.txt000066400000000000000000000000051277752716200212670ustar00rootroot00000000000000root node-findup-sync-0.4.3/test/support/000077500000000000000000000000001277752716200174135ustar00rootroot00000000000000node-findup-sync-0.4.3/test/support/index.js000066400000000000000000000023671277752716200210700ustar00rootroot00000000000000'use strict'; var path = require('path'); var normalizePath = require('normalize-path'); var isAbsolute = require('is-absolute'); var resolve = require('resolve'); exports.normalize = function(filepath) { return filepath ? normalizePath(path.relative('.', filepath)) : null; }; exports.chdir = function(dir) { // store current cwd var orig = process.cwd(); // set cwd to the given `dir` process.chdir(dir); return function() { // restore original `cwd` process.chdir(orig); }; }; exports.npm = function npm(name) { return path.dirname(resolve.sync(name)); }; exports.assert = function(assert) { assert.isPath = function (filepath) { assert(filepath); assert.equal(typeof filepath, 'string'); }; assert.isAbsolute = function (filepath) { assert(filepath); assert.equal(typeof filepath, 'string'); assert(isAbsolute(filepath)); }; assert.basename = function (filepath, basename) { assert(filepath); assert.equal(typeof filepath, 'string'); assert.equal(path.basename(filepath), basename); }; assert.dirname = function (filepath, dirname) { assert(filepath); assert.equal(typeof filepath, 'string'); assert.equal(path.dirname(path.resolve(filepath)), path.resolve(dirname)); }; }; node-findup-sync-0.4.3/test/test.js000066400000000000000000000270121277752716200172160ustar00rootroot00000000000000'use strict'; require('mocha'); var fs = require('fs'); var path = require('path'); var assert = require('assert'); var support = require('./support'); support.assert(assert); var home = require('os-homedir'); var exists = require('fs-exists-sync'); var resolve = require('resolve'); var findup = require('../'); var normalize = support.normalize; var chdir = support.chdir; var npm = support.npm; var cwd; var actual; var isLinux = process.platform === 'linux'; describe('findup-sync', function () { before(function () { fs.writeFileSync(home() + '/_aaa.txt', ''); fs.writeFileSync(home() + '/_bbb.txt', ''); }); after(function () { fs.unlinkSync(home() + '/_aaa.txt'); fs.unlinkSync(home() + '/_bbb.txt'); }); it('should throw when the first arg is not a string or array:', function(cb) { try { findup(); cb(new Error('expected an error')); } catch (err) { assert.equal(err.message, 'findup-sync expects a string or array as the first argument.'); cb(); } }); it('should work when no cwd is given', function () { var actual = findup('package.json'); assert(actual); assert.dirname(actual, path.resolve(__dirname, '..')); assert.basename(actual, 'package.json'); assert.equal(normalize(findup('package.json')), 'package.json'); }); it('should find files in a child directory', function () { var expected = path.resolve(__dirname, 'fixtures/a/b/file.txt'); var restore = chdir(path.resolve(__dirname, 'fixtures/a/b/c/d/e/f/g/h')); var actual = findup('a/b/file.txt'); assert(actual); assert(exists(actual)); assert.equal(actual, expected); restore(); }); it('should find case sensitive files in a child directory', function () { var expected = path.resolve(__dirname, 'fixtures/a/b/', (isLinux ? 'Mochafile.txt' : 'mochafile.txt')); var restore = chdir(path.resolve(__dirname, 'fixtures/a/b/c/d/e/f/g/h')); var actual = findup('a/b/mochafile.txt', {nocase: true}); assert(actual); assert(exists(actual)); assert.equal(actual, expected); restore(); }); it('should find files in a child directory relative to a cwd', function () { var expectedFile = path.resolve(__dirname, 'fixtures/a/b/file.txt'); var expectedA = path.resolve(__dirname, 'fixtures/a/a.txt'); var tempDir = chdir(path.resolve(__dirname, 'fixtures')); var actualFile = findup('a/b/file.txt', {cwd: 'a/b/c/d'}); assert(actualFile); assert(exists(actualFile)); assert.equal(actualFile, expectedFile); var actualA = findup('a.txt', {cwd: 'a/b/c/d/e/f'}); assert(actualA); assert(exists(actualA)); assert.equal(actualA, expectedA); tempDir(); }); it('should find case sensitive files in a child directory relative to a cwd', function () { var expectedFile = path.resolve(__dirname, 'fixtures/a/b', (isLinux ? 'Mochafile.txt' : 'mochafile.txt')); var expectedA = path.resolve(__dirname, 'fixtures/a/a.txt'); var tempDir = chdir(path.resolve(__dirname, 'fixtures')); var actualFile = findup('a/b/mochafile.txt', {cwd: 'a/b/c/d', nocase: true}); assert(actualFile); assert(exists(actualFile)); assert.equal(actualFile, expectedFile); var actualA = findup('a.txt', {cwd: 'a/b/c/d/e/f'}); assert(actualA); assert(exists(actualA)); assert.equal(actualA, expectedA); tempDir(); }); it('should support normal (non-glob) file paths:', function () { var normPath = normalize(findup('package.json', {cwd: path.dirname(resolve.sync('normalize-path'))})); assert.equal(normPath, 'node_modules/normalize-path/package.json'); var isGlob = normalize(findup('package.json', {cwd: path.dirname(resolve.sync('is-glob'))})); assert.equal(isGlob, 'node_modules/is-glob/package.json'); cwd = path.dirname(resolve.sync('normalize-path')); var actual = findup('package.json', {cwd: cwd}); assert.dirname(actual, cwd); assert.basename(actual, 'package.json'); actual = findup('c/package.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'}); assert.basename(actual, 'package.json'); assert.dirname(actual, 'test/fixtures/a/b/c'); cwd = path.dirname(resolve.sync('is-glob')); actual = findup('package.json', {cwd: cwd}); assert.dirname(actual, cwd); assert.basename(actual, 'package.json'); }); it('should support normal (non-glob) case sensitive file paths:', function () { actual = findup('c/mochafile.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true}); assert.basename(actual, (isLinux ? 'Mochafile.txt' : 'mochafile.txt')); assert.dirname(actual, 'test/fixtures/a/b/c'); }); it('should support glob patterns', function() { assert.equal(normalize(findup('**/c/package.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/package.json'); assert.equal(normalize(findup('**/one.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/d/one.txt'); assert.equal(normalize(findup('**/two.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/two.txt'); var pkg = normalize(findup('p*.json', {cwd: npm('micromatch')})); assert.equal(pkg, 'node_modules/micromatch/package.json'); var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g'}; actual = findup('**/c/package.json', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'package.json'); actual = findup('c/package.json', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'package.json'); actual = findup('**/ONE.txt', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'ONE.txt'); actual = findup('**/two.txt', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'two.txt'); cwd = npm('is-glob'); actual = findup('p*.json', {cwd: cwd}); assert.dirname(actual, cwd); assert.basename(actual, 'package.json'); }); it('should support case sensitive glob patterns', function() { assert.equal(normalize(findup('**/c/mochafile.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true})), 'test/fixtures/a/b/c/Mochafile.txt'); assert.equal(normalize(findup('**/one.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true})), 'test/fixtures/a/b/c/d/one.txt'); assert.equal(normalize(findup('**/two.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true})), 'test/fixtures/a/b/c/two.txt'); assert.equal(normalize(findup('mocha*', {cwd: 'test/fixtures/a/b/c', nocase: true})), 'test/fixtures/a/b/c/Mochafile.txt'); var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true}; actual = findup('**/c/mochafile.txt', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'Mochafile.txt'); actual = findup('c/mochafile.txt', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, (isLinux ? 'Mochafile.txt' : 'mochafile.txt')); opts.nocase = false; actual = findup('**/ONE.txt', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'ONE.txt'); actual = findup('**/two.txt', opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'two.txt'); }); it('should support arrays of glob patterns', function() { assert.equal(normalize(findup(['**/c/package.json'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/package.json'); assert.equal(normalize(findup(['**/one.txt'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/d/one.txt'); assert.equal(normalize(findup(['**/two.txt'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/two.txt'); var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g'}; actual = findup(['lslsl', '**/c/package.json'], opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'package.json'); actual = findup(['lslsl', 'c/package.json'], opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'package.json'); actual = findup(['lslsl', '**/ONE.txt'], opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'ONE.txt'); actual = findup(['lslsl', '**/two.txt'], opts); assert.dirname(actual, 'test/fixtures/a/b/c'); assert.basename(actual, 'two.txt'); actual = findup(['lslsl', '**/blah.txt'], opts); assert(actual === null); cwd = npm('is-glob'); actual = findup(['lslsl', 'p*.json'], {cwd: cwd}); assert.dirname(actual, cwd); assert.basename(actual, 'package.json'); }); it('should support micromatch `matchBase` option:', function() { var opts = { matchBase: true, cwd: 'test/fixtures/a/b/c/d/e/f/g' }; assert.equal(normalize(findup('package.json', opts)), 'test/fixtures/a/b/c/d/e/f/g/package.json'); assert.equal(normalize(findup('one.txt', opts)), 'test/fixtures/a/b/c/d/one.txt'); assert.equal(normalize(findup('two.txt', opts)), 'test/fixtures/a/b/c/two.txt'); actual = findup('package.json', opts); assert.basename(actual, 'package.json'); assert.dirname(actual, 'test/fixtures/a/b/c/d/e/f/g'); actual = findup('one.txt', opts); assert.basename(actual, 'one.txt'); assert.dirname(actual, 'test/fixtures/a/b/c/d'); actual = findup('two.txt', opts); assert.basename(actual, 'two.txt'); assert.dirname(actual, 'test/fixtures/a/b/c'); }); it('should return `null` when no files are found:', function() { var dep = normalize(findup('*.foo', {cwd: path.dirname(resolve.sync('micromatch'))})); assert.equal(dep, null); assert.equal(findup('**/b*.json', {cwd: npm('is-glob')}), null); assert.equal(findup('foo.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'}), null); assert.equal(findup('foo.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g', matchBase: true}), null); }); it('should support finding file in immediate parent dir', function () { cwd = path.resolve(__dirname, 'fixtures/a/b/c'); var actual = findup('a.md', { cwd: cwd }); assert.dirname(actual, path.dirname(cwd)); assert.basename(actual, 'a.md'); }); it('should support micromatch `nocase` option:', function () { actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d' }); assert.basename(actual, 'ONE.txt'); assert.dirname(actual, 'test/fixtures/a/b/c'); actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d', nocase: true }); assert.basename(actual, 'one.txt'); assert.dirname(actual, 'test/fixtures/a/b/c/d'); }); it('should find files from absolute paths:', function () { var actual = findup('package.json', { cwd: __dirname }); assert.basename(actual, 'package.json'); assert.dirname(actual, path.resolve(__dirname, '..')); actual = findup('one.txt', { cwd: __dirname + '/fixtures/a' }); assert.basename(actual, 'one.txt'); assert.dirname(actual, 'test/fixtures/a'); actual = findup('two.txt', { cwd: __dirname + '/fixtures/a/b/c' }); assert.basename(actual, 'two.txt'); assert.dirname(actual, 'test/fixtures/a/b/c'); }); it('should find files in user home:', function () { var actual = findup('*', { cwd: home() }); assert.isPath(actual); assert(exists(actual)); assert.dirname(actual, home()); }); it('should find files in user home using tilde expansion:', function () { var actual = findup('*', { cwd: '~' }); assert.isPath(actual); assert(exists(actual)); assert.dirname(actual, home()); }); it('should match files in cwd before searching up', function() { var actual = findup(['a.txt', 'a.md'], { cwd: __dirname + '/fixtures/a/b' }); assert.basename(actual, 'a.md'); assert.dirname(actual, 'test/fixtures/a/b'); }); });