[Pkg-javascript-commits] [node-find-up] 01/05: New upstream version 2.1.0

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Thu Dec 7 15:42:53 UTC 2017


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 516639df3af0d977016e1d1a6cda7aed980d2f96
Author: Pirate Praveen <praveen at debian.org>
Date:   Thu Dec 7 17:41:31 2017 +0530

    New upstream version 2.1.0
---
 fixture/qux.js |  0
 index.js       | 20 +++++++++++---------
 package.json   |  4 ++--
 readme.md      | 27 ++++++++++++++++++++-------
 test.js        | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 86 insertions(+), 20 deletions(-)

diff --git a/fixture/qux.js b/fixture/qux.js
new file mode 100644
index 0000000..e69de29
diff --git a/index.js b/index.js
index 020550a..939c955 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,6 @@
 'use strict';
 const path = require('path');
-const pathExists = require('path-exists');
+const locatePath = require('locate-path');
 
 module.exports = (filename, opts) => {
 	opts = opts || {};
@@ -8,13 +8,13 @@ module.exports = (filename, opts) => {
 	const startDir = path.resolve(opts.cwd || '');
 	const root = path.parse(startDir).root;
 
+	const filenames = [].concat(filename);
+
 	return new Promise(resolve => {
 		(function find(dir) {
-			const fp = path.join(dir, filename);
-
-			pathExists(fp).then(exists => {
-				if (exists) {
-					resolve(fp);
+			locatePath(filenames, {cwd: dir}).then(file => {
+				if (file) {
+					resolve(path.join(dir, file));
 				} else if (dir === root) {
 					resolve(null);
 				} else {
@@ -31,12 +31,14 @@ module.exports.sync = (filename, opts) => {
 	let dir = path.resolve(opts.cwd || '');
 	const root = path.parse(dir).root;
 
+	const filenames = [].concat(filename);
+
 	// eslint-disable-next-line no-constant-condition
 	while (true) {
-		const fp = path.join(dir, filename);
+		const file = locatePath.sync(filenames, {cwd: dir});
 
-		if (pathExists.sync(fp)) {
-			return fp;
+		if (file) {
+			return path.join(dir, file);
 		} else if (dir === root) {
 			return null;
 		}
diff --git a/package.json b/package.json
index aa081e2..7ec85bb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "find-up",
-  "version": "2.0.0",
+  "version": "2.1.0",
   "description": "Find a file by walking up parent directories",
   "license": "MIT",
   "repository": "sindresorhus/find-up",
@@ -40,7 +40,7 @@
     "path"
   ],
   "dependencies": {
-    "path-exists": "^2.0.0"
+    "locate-path": "^2.0.0"
   },
   "devDependencies": {
     "ava": "*",
diff --git a/readme.md b/readme.md
index cf858e1..b5ad694 100644
--- a/readme.md
+++ b/readme.md
@@ -15,12 +15,12 @@ $ npm install --save find-up
 ```
 /
 └── Users
-    └── sindresorhus
-        ├── unicorn.png
-        └── foo
-            └── bar
-                ├── baz
-                └── example.js
+		└── sindresorhus
+				├── unicorn.png
+				└── foo
+						└── bar
+								├── baz
+								└── example.js
 ```
 
 ```js
@@ -31,6 +31,11 @@ findUp('unicorn.png').then(filepath => {
 	console.log(filepath);
 	//=> '/Users/sindresorhus/unicorn.png'
 });
+
+findUp(['rainbow.png', 'unicorn.png']).then(filepath => {
+	console.log(filepath);
+	//=> '/Users/sindresorhus/unicorn.png'
+});
 ```
 
 
@@ -40,10 +45,18 @@ findUp('unicorn.png').then(filepath => {
 
 Returns a `Promise` for the filepath or `null`.
 
+### findUp([filenameA, filenameB], [options])
+
+Returns a `Promise` for the first filepath found (by respecting the order) or `null`.
+
 ### findUp.sync(filename, [options])
 
 Returns a filepath or `null`.
 
+### findUp.sync([filenameA, filenameB], [options])
+
+Returns the first filepath found (by respecting the order) or `null`.
+
 #### filename
 
 Type: `string`
@@ -54,7 +67,7 @@ Filename of the file to find.
 
 ##### cwd
 
-Type: `string`  
+Type: `string`<br>
 Default: `process.cwd()`
 
 Directory to start from.
diff --git a/test.js b/test.js
index bc1917f..557afe2 100644
--- a/test.js
+++ b/test.js
@@ -8,7 +8,8 @@ const name = {
 	pkgDir: 'find-up',
 	pkg: 'package.json',
 	fixtureDir: 'fixture',
-	baz: 'baz.js'
+	baz: 'baz.js',
+	qux: 'qux.js'
 };
 
 // These paths are relative to the project root
@@ -16,6 +17,7 @@ const rel = {
 	fixtureDir: name.fixtureDir
 };
 rel.baz = path.join(rel.fixtureDir, name.baz);
+rel.qux = path.join(rel.fixtureDir, name.qux);
 rel.barDir = path.join(rel.fixtureDir, 'foo', 'bar');
 
 const abs = {
@@ -24,10 +26,11 @@ const abs = {
 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.qux = path.join(abs.fixtureDir, name.qux);
 abs.barDir = path.join(abs.fixtureDir, 'foo', 'bar');
 
 // Create a disjoint directory, used for the not-found tests
-test.beforeEach(async t => {
+test.beforeEach(t => {
 	const tmpDir = tempfile();
 	fs.mkdirSync(tmpDir);
 	t.context.disjoint = tmpDir;
@@ -77,6 +80,54 @@ test('sync (child file, custom cwd)', t => {
 	t.is(filePath, abs.baz);
 });
 
+test('async (child file, array, custom cwd)', async t => {
+	const filePath = await fn([name.baz], {
+		cwd: rel.fixtureDir
+	});
+
+	t.is(filePath, abs.baz);
+});
+
+test('sync (child file, array, custom cwd)', t => {
+	const filePath = fn.sync([name.baz], {
+		cwd: rel.fixtureDir
+	});
+
+	t.is(filePath, abs.baz);
+});
+
+test('async (first child file, array, custom cwd)', async t => {
+	const filePath = await fn([name.qux, name.baz], {
+		cwd: rel.fixtureDir
+	});
+
+	t.is(filePath, abs.qux);
+});
+
+test('sync (first child file, array, custom cwd)', t => {
+	const filePath = fn.sync([name.qux, name.baz], {
+		cwd: rel.fixtureDir
+	});
+
+	t.is(filePath, abs.qux);
+});
+
+test('async (second child file, array, custom cwd)', async t => {
+	const filePath = await fn(['fake', name.baz], {
+		cwd: rel.fixtureDir
+	});
+
+	t.is(filePath, abs.baz);
+});
+
+test('sync (second child file, array, custom cwd)', t => {
+	const filePath = fn.sync(['fake', name.baz], {
+		cwd: rel.fixtureDir
+	});
+
+	t.is(filePath, abs.baz);
+});
+
 test('async (cwd)', async t => {
 	const filePath = await fn(name.pkgDir, {
 		cwd: abs.pkgDir

-- 
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