[Pkg-javascript-commits] [node-find-up] 01/03: Import Upstream version 2.0.0
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Wed Oct 26 17:07:01 UTC 2016
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-find-up.
commit 71168f666e9f85524db567be9869ab762b7b2c32
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date: Wed Oct 26 22:17:55 2016 +0530
Import Upstream version 2.0.0
---
.editorconfig | 12 +++
.gitattributes | 2 +
.gitignore | 1 +
.travis.yml | 7 ++
appveyor.yml | 20 +++++
fixture/baz.js | 0
fixture/foo/bar/.gitkeep | 0
index.js | 46 +++++++++++
license | 21 +++++
package.json | 53 +++++++++++++
readme.md | 72 +++++++++++++++++
test.js | 196 +++++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 430 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..391f0a4
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* text=auto
+*.js text eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..bd9dc67
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+os:
+ - linux
+ - osx
+language: node_js
+node_js:
+ - '6'
+ - '4'
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..bdcf273
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,20 @@
+environment:
+ matrix:
+ - nodejs_version: '6'
+ - nodejs_version: '4'
+install:
+ - ps: Install-Product node $env:nodejs_version
+ - set CI=true
+ - npm -g install npm at latest
+ - set PATH=%APPDATA%\npm;%PATH%
+ - npm install
+matrix:
+ fast_finish: true
+build: off
+version: '{build}'
+shallow_clone: true
+clone_depth: 1
+test_script:
+ - node --version
+ - npm --version
+ - npm test
diff --git a/fixture/baz.js b/fixture/baz.js
new file mode 100644
index 0000000..e69de29
diff --git a/fixture/foo/bar/.gitkeep b/fixture/foo/bar/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..020550a
--- /dev/null
+++ b/index.js
@@ -0,0 +1,46 @@
+'use strict';
+const path = require('path');
+const pathExists = require('path-exists');
+
+module.exports = (filename, opts) => {
+ opts = opts || {};
+
+ const startDir = path.resolve(opts.cwd || '');
+ const root = path.parse(startDir).root;
+
+ return new Promise(resolve => {
+ (function find(dir) {
+ const fp = path.join(dir, filename);
+
+ pathExists(fp).then(exists => {
+ if (exists) {
+ resolve(fp);
+ } else if (dir === root) {
+ resolve(null);
+ } else {
+ find(path.dirname(dir));
+ }
+ });
+ })(startDir);
+ });
+};
+
+module.exports.sync = (filename, opts) => {
+ opts = opts || {};
+
+ let dir = path.resolve(opts.cwd || '');
+ const root = path.parse(dir).root;
+
+ // eslint-disable-next-line no-constant-condition
+ while (true) {
+ const fp = path.join(dir, filename);
+
+ if (pathExists.sync(fp)) {
+ return fp;
+ } else if (dir === root) {
+ return null;
+ }
+
+ dir = path.dirname(dir);
+ }
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+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.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..aa081e2
--- /dev/null
+++ b/package.json
@@ -0,0 +1,53 @@
+{
+ "name": "find-up",
+ "version": "2.0.0",
+ "description": "Find a file by walking up parent directories",
+ "license": "MIT",
+ "repository": "sindresorhus/find-up",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus at gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "find",
+ "up",
+ "find-up",
+ "findup",
+ "look-up",
+ "look",
+ "file",
+ "search",
+ "match",
+ "package",
+ "resolve",
+ "parent",
+ "parents",
+ "folder",
+ "directory",
+ "dir",
+ "walk",
+ "walking",
+ "path"
+ ],
+ "dependencies": {
+ "path-exists": "^2.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "tempfile": "^1.1.1",
+ "xo": "*"
+ },
+ "xo": {
+ "esnext": true
+ }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..cf858e1
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,72 @@
+# find-up [![Build Status: Linux and macOS](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/l0cyjmvh5lq72vq2/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/find-up/branch/master)
+
+> Find a file by walking up parent directories
+
+
+## Install
+
+```
+$ npm install --save find-up
+```
+
+
+## Usage
+
+```
+/
+└── Users
+ └── sindresorhus
+ ├── unicorn.png
+ └── foo
+ └── bar
+ ├── baz
+ └── example.js
+```
+
+```js
+// example.js
+const findUp = require('find-up');
+
+findUp('unicorn.png').then(filepath => {
+ console.log(filepath);
+ //=> '/Users/sindresorhus/unicorn.png'
+});
+```
+
+
+## API
+
+### findUp(filename, [options])
+
+Returns a `Promise` for the filepath or `null`.
+
+### findUp.sync(filename, [options])
+
+Returns a filepath or `null`.
+
+#### filename
+
+Type: `string`
+
+Filename of the file to find.
+
+#### options
+
+##### cwd
+
+Type: `string`
+Default: `process.cwd()`
+
+Directory to start from.
+
+
+## Related
+
+- [find-up-cli](https://github.com/sindresorhus/find-up-cli) - CLI for this module
+- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
+- [pkg-dir](https://github.com/sindresorhus/pkg-dir) - Find the root directory of an npm package
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..bc1917f
--- /dev/null
+++ b/test.js
@@ -0,0 +1,196 @@
+import fs from 'fs';
+import path from 'path';
+import test from 'ava';
+import tempfile from 'tempfile';
+import fn from './';
+
+const name = {
+ pkgDir: 'find-up',
+ pkg: 'package.json',
+ fixtureDir: 'fixture',
+ baz: 'baz.js'
+};
+
+// These paths are relative to the project root
+const rel = {
+ fixtureDir: name.fixtureDir
+};
+rel.baz = path.join(rel.fixtureDir, name.baz);
+rel.barDir = path.join(rel.fixtureDir, 'foo', 'bar');
+
+const abs = {
+ pkgDir: __dirname
+};
+abs.pkg = path.join(abs.pkgDir, name.pkg);
+abs.fixtureDir = path.join(abs.pkgDir, name.fixtureDir);
+abs.baz = path.join(abs.fixtureDir, name.baz);
+abs.barDir = path.join(abs.fixtureDir, 'foo', 'bar');
+
+// Create a disjoint directory, used for the not-found tests
+test.beforeEach(async t => {
+ const tmpDir = tempfile();
+ fs.mkdirSync(tmpDir);
+ t.context.disjoint = tmpDir;
+});
+
+test.afterEach(t => {
+ fs.rmdirSync(t.context.disjoint);
+});
+
+test('async (child file)', async t => {
+ const filePath = await fn(name.pkg);
+
+ t.is(filePath, abs.pkg);
+});
+
+test('sync (child file)', t => {
+ const filePath = fn.sync(name.pkg);
+
+ t.is(filePath, abs.pkg);
+});
+
+test('async (child dir)', async t => {
+ const filePath = await fn(name.fixtureDir);
+
+ t.is(filePath, abs.fixtureDir);
+});
+
+test('sync (child dir)', t => {
+ const filePath = fn.sync(name.fixtureDir);
+
+ t.is(filePath, abs.fixtureDir);
+});
+
+test('async (child file, custom cwd)', async t => {
+ const filePath = await fn(name.baz, {
+ cwd: rel.fixtureDir
+ });
+
+ t.is(filePath, abs.baz);
+});
+
+test('sync (child file, custom cwd)', t => {
+ const filePath = fn.sync(name.baz, {
+ cwd: rel.fixtureDir
+ });
+
+ t.is(filePath, abs.baz);
+});
+
+test('async (cwd)', async t => {
+ const filePath = await fn(name.pkgDir, {
+ cwd: abs.pkgDir
+ });
+
+ t.is(filePath, abs.pkgDir);
+});
+
+test('sync (cwd)', t => {
+ const filePath = fn.sync(name.pkgDir, {
+ cwd: abs.pkgDir
+ });
+
+ t.is(filePath, abs.pkgDir);
+});
+
+test('async (cousin file, custom cwd)', async t => {
+ const filePath = await fn(name.baz, {
+ cwd: rel.barDir
+ });
+
+ t.is(filePath, abs.baz);
+});
+
+test('sync (cousin file, custom cwd)', t => {
+ const filePath = fn.sync(name.baz, {
+ cwd: rel.barDir
+ });
+
+ t.is(filePath, abs.baz);
+});
+
+test('async (nested descendant file)', async t => {
+ const filePath = await fn(rel.baz);
+
+ t.is(filePath, abs.baz);
+});
+
+test('sync (nested descendant file)', t => {
+ const filePath = fn.sync(rel.baz);
+
+ t.is(filePath, abs.baz);
+});
+
+test('async (nested descendant dir)', async t => {
+ const filePath = await fn(rel.barDir);
+
+ t.is(filePath, abs.barDir);
+});
+
+test('sync (nested descendant dir)', t => {
+ const filePath = fn.sync(rel.barDir);
+
+ t.is(filePath, abs.barDir);
+});
+
+test('async (nested cousin dir, custom cwd)', async t => {
+ const filePath = await fn(rel.barDir, {
+ cwd: rel.fixtureDir
+ });
+
+ t.is(filePath, abs.barDir);
+});
+
+test('sync (nested cousin dir, custom cwd)', t => {
+ const filePath = fn.sync(rel.barDir, {
+ cwd: rel.fixtureDir
+ });
+
+ t.is(filePath, abs.barDir);
+});
+
+test('async (ancestor dir, custom cwd)', async t => {
+ const filePath = await fn(name.fixtureDir, {
+ cwd: rel.barDir
+ });
+
+ t.is(filePath, abs.fixtureDir);
+});
+
+test('sync (ancestor dir, custom cwd)', t => {
+ const filePath = fn.sync(name.fixtureDir, {
+ cwd: rel.barDir
+ });
+
+ t.is(filePath, abs.fixtureDir);
+});
+
+test('async (not found)', async t => {
+ const filePath = await fn('somenonexistentfile.js');
+
+ t.is(filePath, null);
+});
+
+test('sync (not found)', t => {
+ const filePath = fn.sync('somenonexistentfile.js');
+
+ t.is(filePath, null);
+});
+
+// Both tests start in a disjoint directory. `package.json` should not be found
+// and `null` should be returned.
+test('async (not found, custom cwd)', async t => {
+ const filePath = await fn(name.pkg, {
+ cwd: t.context.disjoint
+ });
+
+ t.is(filePath, null);
+});
+
+test('sync (not found, custom cwd)', t => {
+ const filePath = fn.sync(name.pkg, {
+ cwd: t.context.disjoint
+ });
+
+ t.is(filePath, null);
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-find-up.git
More information about the Pkg-javascript-commits
mailing list