Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 21, 2019
1 parent 5bb0a79 commit 4412fe2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- '10'
- '8'
- '6'
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -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"
}
}
26 changes: 13 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 4412fe2

Please sign in to comment.