From 80fda88e0f005dcfef11ee2cf87c6cf27f6893de Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 18 Apr 2019 17:55:12 +0700 Subject: [PATCH] Require Node.js 8 --- .travis.yml | 1 - index.js | 36 ++++++++++++++++++------------------ package.json | 7 +++---- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc1ada6..2093010 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,3 @@ language: node_js node_js: - '10' - '8' - - '6' diff --git a/index.js b/index.js index 13fe765..1345264 100644 --- a/index.js +++ b/index.js @@ -2,31 +2,31 @@ const path = require('path'); const locatePath = require('locate-path'); -module.exports = (name, options = {}) => { - const startDirectory = path.resolve(options.cwd || ''); - const {root} = path.parse(startDirectory); - +module.exports = async (name, options = {}) => { + let directory = path.resolve(options.cwd || ''); + const {root} = path.parse(directory); const paths = [].concat(name); - return new Promise(resolve => { - (function find(directory) { - locatePath(paths, {cwd: directory}).then(foundPath => { - if (foundPath) { - resolve(path.join(directory, foundPath)); - } else if (directory === root) { - resolve(); - } else { - find(path.dirname(directory)); - } - }); - })(startDirectory); - }); + // eslint-disable-next-line no-constant-condition + while (true) { + // eslint-disable-next-line no-await-in-loop + const foundPath = await locatePath(paths, {cwd: directory}); + + if (foundPath) { + return path.join(directory, foundPath); + } + + if (directory === root) { + return; + } + + directory = path.dirname(directory); + } }; module.exports.sync = (name, options = {}) => { let directory = path.resolve(options.cwd || ''); const {root} = path.parse(directory); - const paths = [].concat(name); // eslint-disable-next-line no-constant-condition diff --git a/package.json b/package.json index 6d54402..fbd34c3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" @@ -35,17 +35,16 @@ "parents", "folder", "directory", - "dir", "walk", "walking", "path" ], "dependencies": { - "locate-path": "^3.0.0" + "locate-path": "^4.0.0" }, "devDependencies": { "ava": "^1.4.1", - "tempy": "^0.2.1", + "tempy": "^0.3.0", "tsd": "^0.7.2", "xo": "^0.24.0" }