diff --git a/.travis.yml b/.travis.yml index 2ae9d62..f3fa8cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,3 @@ language: node_js node_js: - '10' - '8' - - '6' diff --git a/index.js b/index.js index d880fee..dfc4fa2 100644 --- a/index.js +++ b/index.js @@ -3,26 +3,28 @@ const path = require('path'); const findUp = require('find-up'); const readPkg = require('read-pkg'); -module.exports = options => { - return findUp('package.json', options).then(fp => { - if (!fp) { - return {}; - } +module.exports = async options => { + const filePath = await findUp('package.json', options); - return readPkg(Object.assign({}, options, {cwd: path.dirname(fp)})) - .then(pkg => ({pkg, path: fp})); - }); + if (!filePath) { + return {}; + } + + return { + pkg: await readPkg({...options, cwd: path.dirname(filePath)}), + path: filePath + }; }; module.exports.sync = options => { - const fp = findUp.sync('package.json', options); + const filePath = findUp.sync('package.json', options); - if (!fp) { + if (!filePath) { return {}; } return { - pkg: readPkg.sync(Object.assign({}, options, {cwd: path.dirname(fp)})), - path: fp + pkg: readPkg.sync({...options, cwd: path.dirname(filePath)}), + path: filePath }; }; diff --git a/package.json b/package.json index d3a3f67..bc93b80 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "test": "xo && ava" @@ -48,10 +48,10 @@ ], "dependencies": { "find-up": "^3.0.0", - "read-pkg": "^4.0.1" + "read-pkg": "^5.0.0" }, "devDependencies": { - "ava": "*", - "xo": "*" + "ava": "^1.3.1", + "xo": "^0.24.0" } } diff --git a/test.js b/test.js index a67c3d1..fa7357d 100644 --- a/test.js +++ b/test.js @@ -1,26 +1,26 @@ import path from 'path'; import test from 'ava'; -import m from '.'; +import readPkgUp from '.'; const cwd = 'fixture'; const pkgPath = path.resolve('.', 'package.json'); test('async', async t => { - const x = await m({cwd}); - t.is(x.pkg.name, 'read-pkg-up'); - t.is(x.path, pkgPath); + const result = await readPkgUp({cwd}); + t.is(result.pkg.name, 'read-pkg-up'); + t.is(result.path, pkgPath); - const y = await m({cwd: '/'}); - t.is(y.pkg, undefined); - t.is(y.path, undefined); + const result2 = await readPkgUp({cwd: '/'}); + t.is(result2.pkg, undefined); + t.is(result2.path, undefined); }); test('sync', t => { - const x = m.sync({cwd}); - t.is(x.pkg.name, 'read-pkg-up'); - t.is(x.path, pkgPath); + const result = readPkgUp.sync({cwd}); + t.is(result.pkg.name, 'read-pkg-up'); + t.is(result.path, pkgPath); - const y = m.sync({cwd: '/'}); - t.is(y.pkg, undefined); - t.is(y.path, undefined); + const result2 = readPkgUp.sync({cwd: '/'}); + t.is(result2.pkg, undefined); + t.is(result2.path, undefined); });