pax_global_header00006660000000000000000000000064135124533700014515gustar00rootroot0000000000000052 comment=9e523f59674e4b399b89cd3e0be8950666c99af4 findup-sync-4.0.0/000077500000000000000000000000001351245337000137555ustar00rootroot00000000000000findup-sync-4.0.0/.ci/000077500000000000000000000000001351245337000144265ustar00rootroot00000000000000findup-sync-4.0.0/.ci/.azure-pipelines-steps.yml000066400000000000000000000016541351245337000215050ustar00rootroot00000000000000steps: - task: NodeTool@0 inputs: versionSpec: '$(node_version)' displayName: Use Node $(node_version) - script: npm install displayName: npm install - script: npm test displayName: Run tests - script: npm run coveralls displayName: Run coveralls env: # Pretend to be AppVeyor for now APPVEYOR: true APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber) APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version) APPVEYOR_REPO_COMMIT: $(Build.SourceVersion) APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName) # Overwrite the AppVeyor Service Name COVERALLS_SERVICE_NAME: Azure Pipelines COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) COVERALLS_PARALLEL: true CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber) - script: npm run azure-pipelines displayName: Write tests to xml - task: PublishTestResults@2 inputs: testResultsFiles: '**/test.xunit' condition: succeededOrFailed() findup-sync-4.0.0/.ci/.azure-pipelines.yml000066400000000000000000000026651351245337000203540ustar00rootroot00000000000000trigger: - master - releases/* jobs: - job: Test_Linux displayName: Run Tests on Linux pool: vmImage: "Ubuntu 16.04" strategy: matrix: Node_v12: node_version: 12 Node_v10: node_version: 10 Node_v8: node_version: 8 steps: - template: .azure-pipelines-steps.yml - job: Test_Windows displayName: Run Tests on Windows pool: vmImage: vs2017-win2016 strategy: matrix: Node_v12: node_version: 12 Node_v10: node_version: 10 Node_v8: node_version: 8 steps: - template: .azure-pipelines-steps.yml - job: Test_MacOS displayName: Run Tests on MacOS pool: vmImage: macos-10.13 strategy: matrix: Node_v12: node_version: 12 Node_v10: node_version: 10 Node_v8: node_version: 8 steps: - template: .azure-pipelines-steps.yml - job: Notify_Coveralls displayName: Notify Coveralls that the parallel report is done pool: vmImage: "Ubuntu 16.04" dependsOn: - Test_Linux - Test_Windows - Test_MacOS steps: - script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done" env: COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) BUILD_NAME: $(Build.BuildNumber) findup-sync-4.0.0/.editorconfig000066400000000000000000000003261351245337000164330ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false findup-sync-4.0.0/.eslintignore000066400000000000000000000000171351245337000164560ustar00rootroot00000000000000test/fixtures/ findup-sync-4.0.0/.eslintrc000066400000000000000000000000301351245337000155720ustar00rootroot00000000000000{ "extends": "gulp" } findup-sync-4.0.0/.gitattributes000066400000000000000000000001411351245337000166440ustar00rootroot00000000000000# Enforce Unix newlines *.* text eol=lf *.jpg binary *.gif binary *.png binary *.jpeg binaryfindup-sync-4.0.0/.gitignore000066400000000000000000000017101351245337000157440ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env # next.js build output .next # Garbage files .DS_Store # Test results test.xunit findup-sync-4.0.0/.npmrc000066400000000000000000000000371351245337000150750ustar00rootroot00000000000000package-lock=false audit=false findup-sync-4.0.0/.travis.yml000066400000000000000000000001731351245337000160670ustar00rootroot00000000000000sudo: false language: node_js os: - linux - osx node_js: - '12' - '10' - '8' after_script: - npm run coveralls findup-sync-4.0.0/LICENSE000066400000000000000000000022321351245337000147610ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2013-2019 Ben Alman , Blaine Bublitz , and Eric Schoffstall 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. findup-sync-4.0.0/README.md000066400000000000000000000046401351245337000152400ustar00rootroot00000000000000

# findup-sync [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Find the first file matching a given pattern in the current directory or the nearest ancestor directory. Matching is done with [micromatch][micromatch], please report any matching related issues on that repository. ## 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}); ``` ## API ### `findup(patterns, [options])` * `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. ## License MIT [micromatch]: http://github.com/jonschlinkert/micromatch [downloads-image]: https://img.shields.io/npm/dm/findup-sync.svg [npm-url]: https://www.npmjs.com/package/findup-sync [npm-image]: https://img.shields.io/npm/v/findup-sync.svg [azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=7&branchName=master [azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/findup-sync?branchName=master [travis-url]: https://travis-ci.org/gulpjs/findup-sync [travis-image]: https://img.shields.io/travis/gulpjs/findup-sync.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/findup-sync [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/findup-sync.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/findup-sync [coveralls-image]: https://img.shields.io/coveralls/gulpjs/findup-sync/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg findup-sync-4.0.0/appveyor.yml000066400000000000000000000010741351245337000163470ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "8" - nodejs_version: "10" - nodejs_version: "12" platform: - x86 - x64 install: # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" findup-sync-4.0.0/index.js000066400000000000000000000037501351245337000154270ustar00rootroot00000000000000'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) { // Ignore error } return []; } findup-sync-4.0.0/package.json000066400000000000000000000026511351245337000162470ustar00rootroot00000000000000{ "name": "findup-sync", "version": "4.0.0", "description": "Find the first file matching a given pattern in the current directory or the nearest ancestor directory.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ "Ben Alman ", "Tyler Kellen ", "Jon Schlinkert ", "Blaine Bublitz " ], "repository": "gulpjs/findup-sync", "license": "MIT", "engines": { "node": ">= 8" }, "main": "index.js", "files": [ "index.js", "LICENSE" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha --async-only", "azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit", "coveralls": "nyc report --reporter=text-lcov | coveralls" }, "dependencies": { "detect-file": "^1.0.0", "is-glob": "^4.0.0", "micromatch": "^4.0.2", "resolve-dir": "^1.0.1" }, "devDependencies": { "coveralls": "github:phated/node-coveralls#2.x", "eslint": "^6.0.1", "eslint-config-gulp": "^3.0.1", "expect": "^1.20.2", "homedir-polyfill": "^1.0.1", "mocha": "^6.1.4", "normalize-path": "^3.0.0", "nyc": "^14.1.1", "resolve": "^1.4.0" }, "keywords": [ "file", "find", "find-up", "findup", "glob", "match", "pattern", "resolve", "search" ] } findup-sync-4.0.0/test/000077500000000000000000000000001351245337000147345ustar00rootroot00000000000000findup-sync-4.0.0/test/.eslintrc000066400000000000000000000000351351245337000165560ustar00rootroot00000000000000{ "extends": "gulp/test" } findup-sync-4.0.0/test/fixtures/000077500000000000000000000000001351245337000166055ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/Mochafile.txt000066400000000000000000000000051351245337000212300ustar00rootroot00000000000000root findup-sync-4.0.0/test/fixtures/a/000077500000000000000000000000001351245337000170255ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/Mochafile.txt000066400000000000000000000000021351245337000214450ustar00rootroot00000000000000a findup-sync-4.0.0/test/fixtures/a/a.txt000066400000000000000000000000021351245337000177760ustar00rootroot00000000000000a findup-sync-4.0.0/test/fixtures/a/b/000077500000000000000000000000001351245337000172465ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/.config/000077500000000000000000000000001351245337000205715ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/.config/waldo000066400000000000000000000000001351245337000216100ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/Mochafile.txt000066400000000000000000000000021351245337000216660ustar00rootroot00000000000000b findup-sync-4.0.0/test/fixtures/a/b/ONE.js000066400000000000000000000000001351245337000202130ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/a.md000066400000000000000000000000001351245337000177760ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/b.txt000066400000000000000000000000021351245337000202200ustar00rootroot00000000000000b findup-sync-4.0.0/test/fixtures/a/b/c/000077500000000000000000000000001351245337000174705ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/Mochafile.txt000066400000000000000000000000021351245337000221100ustar00rootroot00000000000000c findup-sync-4.0.0/test/fixtures/a/b/c/ONE.txt000066400000000000000000000000001351245337000206400ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/c.txt000066400000000000000000000000021351245337000204430ustar00rootroot00000000000000c findup-sync-4.0.0/test/fixtures/a/b/c/d/000077500000000000000000000000001351245337000177135ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/Mochafile.txt000066400000000000000000000000021351245337000223330ustar00rootroot00000000000000d findup-sync-4.0.0/test/fixtures/a/b/c/d/d.txt000066400000000000000000000000021351245337000206670ustar00rootroot00000000000000d findup-sync-4.0.0/test/fixtures/a/b/c/d/e/000077500000000000000000000000001351245337000201375ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/Mochafile.txt000066400000000000000000000000021351245337000225570ustar00rootroot00000000000000e findup-sync-4.0.0/test/fixtures/a/b/c/d/e/e.txt000066400000000000000000000000021351245337000211140ustar00rootroot00000000000000e findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/000077500000000000000000000000001351245337000203645ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/Mochafile.txt000066400000000000000000000000021351245337000230040ustar00rootroot00000000000000f findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/f.txt000066400000000000000000000000021351245337000213420ustar00rootroot00000000000000f findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/file.txt000066400000000000000000000000021351245337000220340ustar00rootroot00000000000000f findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/000077500000000000000000000000001351245337000206125ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/Mochafile.txt000066400000000000000000000000021351245337000232320ustar00rootroot00000000000000g findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/file.txt000066400000000000000000000000021351245337000222620ustar00rootroot00000000000000g findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/g.txt000066400000000000000000000000021351245337000215710ustar00rootroot00000000000000g findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/000077500000000000000000000000001351245337000210415ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/Mochafile.txt000066400000000000000000000000021351245337000234610ustar00rootroot00000000000000h findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/file.txt000066400000000000000000000000021351245337000225110ustar00rootroot00000000000000h findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/h.txt000066400000000000000000000000021351245337000220210ustar00rootroot00000000000000h findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/000077500000000000000000000000001351245337000212715ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/Mochafile.txt000066400000000000000000000000021351245337000237110ustar00rootroot00000000000000i findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/file.txt000066400000000000000000000000021351245337000227410ustar00rootroot00000000000000i findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/i.txt000066400000000000000000000000021351245337000222520ustar00rootroot00000000000000i findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/j/000077500000000000000000000000001351245337000215225ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/j/Mochafile.txt000066400000000000000000000000021351245337000241420ustar00rootroot00000000000000j findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/j/file.txt000066400000000000000000000000021351245337000231720ustar00rootroot00000000000000j findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/j/j.txt000066400000000000000000000000021351245337000225040ustar00rootroot00000000000000j findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/j/package.json000066400000000000000000000000001351245337000237760ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/i/package.json000066400000000000000000000000001351245337000235450ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/h/package.json000066400000000000000000000000731351245337000233270ustar00rootroot00000000000000{ "name": "h", "description": "package.json from h." } findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/g/package.json000066400000000000000000000000731351245337000231000ustar00rootroot00000000000000{ "name": "g", "description": "package.json from g." } findup-sync-4.0.0/test/fixtures/a/b/c/d/e/f/package.json000066400000000000000000000000731351245337000226520ustar00rootroot00000000000000{ "name": "f", "description": "package.json from f." } findup-sync-4.0.0/test/fixtures/a/b/c/d/e/file.txt000066400000000000000000000000021351245337000216070ustar00rootroot00000000000000e findup-sync-4.0.0/test/fixtures/a/b/c/d/e/package.json000066400000000000000000000000731351245337000224250ustar00rootroot00000000000000{ "name": "e", "description": "package.json from e." } findup-sync-4.0.0/test/fixtures/a/b/c/d/file.txt000066400000000000000000000000021351245337000213630ustar00rootroot00000000000000d findup-sync-4.0.0/test/fixtures/a/b/c/d/one.txt000066400000000000000000000000001351245337000212230ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/c/d/package.json000066400000000000000000000000731351245337000222010ustar00rootroot00000000000000{ "name": "d", "description": "package.json from d." } findup-sync-4.0.0/test/fixtures/a/b/c/file.txt000066400000000000000000000000021351245337000211400ustar00rootroot00000000000000c findup-sync-4.0.0/test/fixtures/a/b/c/package.json000066400000000000000000000000731351245337000217560ustar00rootroot00000000000000{ "name": "c", "description": "package.json from c." } findup-sync-4.0.0/test/fixtures/a/b/c/two.txt000066400000000000000000000000001351245337000210300ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/file.txt000066400000000000000000000000021351245337000207160ustar00rootroot00000000000000b findup-sync-4.0.0/test/fixtures/a/b/one.txt000066400000000000000000000000001351245337000205560ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/b/package.json000066400000000000000000000000731351245337000215340ustar00rootroot00000000000000{ "name": "b", "description": "package.json from b." } findup-sync-4.0.0/test/fixtures/a/file.txt000066400000000000000000000000021351245337000204750ustar00rootroot00000000000000a findup-sync-4.0.0/test/fixtures/a/one.txt000066400000000000000000000000001351245337000203350ustar00rootroot00000000000000findup-sync-4.0.0/test/fixtures/a/package.json000066400000000000000000000000731351245337000213130ustar00rootroot00000000000000{ "name": "a", "description": "package.json from a." } findup-sync-4.0.0/test/fixtures/file.txt000066400000000000000000000000051351245337000202600ustar00rootroot00000000000000root findup-sync-4.0.0/test/fixtures/package.json000066400000000000000000000001131351245337000210660ustar00rootroot00000000000000{ "name": "fixtures", "description": "package.json from ./fixtures." } findup-sync-4.0.0/test/fixtures/root.txt000066400000000000000000000000051351245337000203240ustar00rootroot00000000000000root findup-sync-4.0.0/test/support/000077500000000000000000000000001351245337000164505ustar00rootroot00000000000000findup-sync-4.0.0/test/support/index.js000066400000000000000000000022561351245337000201220ustar00rootroot00000000000000'use strict'; var path = require('path'); var normalizePath = require('normalize-path'); var resolve = require('resolve'); var expect = require('expect'); 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.expectExtras = { isPath: function() { var filepath = this.actual; expect(filepath).toExist(); expect(filepath).toBeA('string'); return this; }, toHaveBasename: function(basename) { var filepath = this.actual; expect(filepath).toExist(); expect(filepath).toBeA('string'); expect(path.basename(filepath)).toEqual(basename); return this; }, toHaveDirname: function(dirname) { var filepath = this.actual; expect(filepath).toExist(); expect(filepath).toBeA('string'); expect(path.dirname(path.resolve(filepath))).toEqual(path.resolve(dirname)); }, }; findup-sync-4.0.0/test/test.js000066400000000000000000000306571351245337000162640ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var path = require('path'); var expect = require('expect'); var home = require('homedir-polyfill'); var resolve = require('resolve'); var support = require('./support'); expect.extend(support.expectExtras); var findup = require('../'); var exists = fs.existsSync; var normalize = support.normalize; var chdir = support.chdir; var npm = support.npm; var isLinux = process.platform === 'linux'; var cwd, actual; describe('findup-sync', function() { before(function(done) { fs.writeFileSync(home() + '/_aaa.txt', ''); fs.writeFileSync(home() + '/_bbb.txt', ''); done(); }); after(function(done) { fs.unlinkSync(home() + '/_aaa.txt'); fs.unlinkSync(home() + '/_bbb.txt'); done(); }); 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) { expect(err.message).toEqual('findup-sync expects a string or array as the first argument.'); cb(); } }); it('should work when no cwd is given', function(done) { var actual = findup('package.json'); expect(actual).toExist(); expect(actual).toHaveDirname(path.resolve(__dirname, '..')); expect(actual).toHaveBasename('package.json'); expect(normalize(findup('package.json'))).toEqual('package.json'); done(); }); it('should find files in a child directory', function(done) { 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'); expect(actual).toExist(); expect(exists(actual)).toExist(); expect(actual).toEqual(expected); restore(); done(); }); it('should find case sensitive files in a child directory', function(done) { 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 }); expect(actual).toExist(); expect(exists(actual)).toExist(); expect(actual).toEqual(expected); restore(); done(); }); it('should find files in a child directory relative to a cwd', function(done) { 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' }); expect(actualFile).toExist(); expect(exists(actualFile)).toExist(); expect(actualFile).toEqual(expectedFile); var actualA = findup('a.txt', { cwd: 'a/b/c/d/e/f' }); expect(actualA).toExist(); expect(exists(actualA)).toExist(); expect(actualA).toEqual(expectedA); tempDir(); done(); }); it('should find case sensitive files in a child directory relative to a cwd', function(done) { 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 }); expect(actualFile).toExist(); expect(exists(actualFile)).toExist(); expect(actualFile).toEqual(expectedFile); var actualA = findup('a.txt', { cwd: 'a/b/c/d/e/f' }); expect(actualA).toExist(); expect(exists(actualA)).toExist(); expect(actualA).toEqual(expectedA); tempDir(); done(); }); it('should support normal (non-glob) file paths:', function(done) { var normPath = normalize(findup('package.json', { cwd: path.dirname(resolve.sync('normalize-path')) })); expect(normPath).toEqual('node_modules/normalize-path/package.json'); var isGlob = normalize(findup('package.json', { cwd: path.dirname(resolve.sync('is-glob')) })); expect(isGlob).toEqual('node_modules/is-glob/package.json'); cwd = path.dirname(resolve.sync('normalize-path')); var actual = findup('package.json', { cwd: cwd }); expect(actual).toHaveDirname(cwd); expect(actual).toHaveBasename('package.json'); actual = findup('c/package.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }); expect(actual).toHaveBasename('package.json'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); cwd = path.dirname(resolve.sync('is-glob')); actual = findup('package.json', { cwd: cwd }); expect(actual).toHaveDirname(cwd); expect(actual).toHaveBasename('package.json'); done(); }); it('should support normal (non-glob) case sensitive file paths:', function(done) { actual = findup('c/mochafile.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }); expect(actual).toHaveBasename(isLinux ? 'Mochafile.txt' : 'mochafile.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); done(); }); it('should support glob patterns', function(done) { expect(normalize(findup('**/c/package.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/package.json'); expect(normalize(findup('**/one.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/d/one.txt'); expect(normalize(findup('**/two.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/two.txt'); var pkg = normalize(findup('p*.json', { cwd: npm('micromatch') })); expect(pkg).toEqual('node_modules/micromatch/package.json'); var opts = { cwd: 'test/fixtures/a/b/c/d/e/f/g' }; actual = findup('**/c/package.json', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('package.json'); actual = findup('c/package.json', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('package.json'); actual = findup('**/ONE.txt', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('ONE.txt'); actual = findup('**/two.txt', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('two.txt'); cwd = npm('is-glob'); actual = findup('p*.json', { cwd: cwd }); expect(actual).toHaveDirname(cwd); expect(actual).toHaveBasename('package.json'); done(); }); it('should support case sensitive glob patterns', function(done) { expect(normalize(findup('**/c/mochafile.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }))).toEqual('test/fixtures/a/b/c/Mochafile.txt'); expect(normalize(findup('**/one.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }))).toEqual('test/fixtures/a/b/c/d/one.txt'); expect(normalize(findup('**/two.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }))).toEqual('test/fixtures/a/b/c/two.txt'); expect(normalize(findup('mocha*', { cwd: 'test/fixtures/a/b/c', nocase: true }))).toEqual('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); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('Mochafile.txt'); actual = findup('c/mochafile.txt', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename(isLinux ? 'Mochafile.txt' : 'mochafile.txt'); opts.nocase = false; actual = findup('**/ONE.txt', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('ONE.txt'); actual = findup('**/two.txt', opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('two.txt'); done(); }); it('should support arrays of glob patterns', function(done) { expect(normalize(findup(['**/c/package.json'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/package.json'); expect(normalize(findup(['**/one.txt'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/d/one.txt'); expect(normalize(findup(['**/two.txt'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('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); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('package.json'); actual = findup(['lslsl', 'c/package.json'], opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('package.json'); actual = findup(['lslsl', '**/ONE.txt'], opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('ONE.txt'); actual = findup(['lslsl', '**/two.txt'], opts); expect(actual).toHaveDirname('test/fixtures/a/b/c'); expect(actual).toHaveBasename('two.txt'); actual = findup(['lslsl', '**/blah.txt'], opts); expect(actual === null).toExist(); cwd = npm('is-glob'); actual = findup(['lslsl', 'p*.json'], { cwd: cwd }); expect(actual).toHaveDirname(cwd); expect(actual).toHaveBasename('package.json'); done(); }); it('should support micromatch `matchBase` option:', function(done) { var opts = { matchBase: true, cwd: 'test/fixtures/a/b/c/d/e/f/g' }; expect(normalize(findup('package.json', opts))).toEqual('test/fixtures/a/b/c/d/e/f/g/package.json'); expect(normalize(findup('one.txt', opts))).toEqual('test/fixtures/a/b/c/d/one.txt'); expect(normalize(findup('two.txt', opts))).toEqual('test/fixtures/a/b/c/two.txt'); actual = findup('package.json', opts); expect(actual).toHaveBasename('package.json'); expect(actual).toHaveDirname('test/fixtures/a/b/c/d/e/f/g'); actual = findup('one.txt', opts); expect(actual).toHaveBasename('one.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c/d'); actual = findup('two.txt', opts); expect(actual).toHaveBasename('two.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); done(); }); it('should return `null` when no files are found:', function(done) { var dep = normalize(findup('*.foo', { cwd: path.dirname(resolve.sync('micromatch')) })); expect(dep).toEqual(null); expect(findup('**/b*.json', { cwd: npm('is-glob') })).toEqual(null); expect(findup('foo.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' })).toEqual(null); expect(findup('foo.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g', matchBase: true })).toEqual(null); done(); }); it('should support finding file in immediate parent dir', function(done) { cwd = path.resolve(__dirname, 'fixtures/a/b/c'); var actual = findup('a.md', { cwd: cwd }); expect(actual).toHaveDirname(path.dirname(cwd)); expect(actual).toHaveBasename('a.md'); done(); }); it('should support micromatch `nocase` option:', function(done) { actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d' }); expect(actual).toHaveBasename('ONE.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d', nocase: true }); expect(actual).toHaveBasename('one.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c/d'); done(); }); it('should find files from absolute paths:', function(done) { var actual = findup('package.json', { cwd: __dirname }); expect(actual).toHaveBasename('package.json'); expect(actual).toHaveDirname(path.resolve(__dirname, '..')); actual = findup('one.txt', { cwd: __dirname + '/fixtures/a' }); expect(actual).toHaveBasename('one.txt'); expect(actual).toHaveDirname('test/fixtures/a'); actual = findup('two.txt', { cwd: __dirname + '/fixtures/a/b/c' }); expect(actual).toHaveBasename('two.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); done(); }); it('should find files in user home:', function(done) { var actual = findup('*', { cwd: home() }); expect(actual).isPath(); expect(exists(actual)).toExist(); expect(actual).toHaveDirname(home()); done(); }); it('should find files in user home using tilde expansion:', function(done) { var actual = findup('*', { cwd: '~' }); expect(actual).isPath(); expect(exists(actual)).toExist(); expect(actual).toHaveDirname(home()); done(); }); it('should match files in cwd before searching up', function(done) { var actual = findup(['a.txt', 'a.md'], { cwd: __dirname + '/fixtures/a/b' }); expect(actual).toHaveBasename('a.md'); expect(actual).toHaveDirname('test/fixtures/a/b'); done(); }); });