Skip to content

Commit

Permalink
Upgrade read-pkg to v4 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudeofawesome authored and sindresorhus committed Nov 1, 2018
1 parent ecb0795 commit 5bb0a79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const path = require('path');
const findUp = require('find-up');
const readPkg = require('read-pkg');

Expand All @@ -8,7 +9,8 @@ module.exports = options => {
return {};
}

return readPkg(fp, options).then(pkg => ({pkg, path: fp}));
return readPkg(Object.assign({}, options, {cwd: path.dirname(fp)}))
.then(pkg => ({pkg, path: fp}));
});
};

Expand All @@ -20,7 +22,7 @@ module.exports.sync = options => {
}

return {
pkg: readPkg.sync(fp, options),
pkg: readPkg.sync(Object.assign({}, options, {cwd: path.dirname(fp)})),
path: fp
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"dependencies": {
"find-up": "^3.0.0",
"read-pkg": "^3.0.0"
"read-pkg": "^4.0.1"
},
"devDependencies": {
"ava": "*",
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ test('async', async t => {
const x = await m({cwd});
t.is(x.pkg.name, 'read-pkg-up');
t.is(x.path, pkgPath);

const y = await m({cwd: '/'});
t.is(y.pkg, undefined);
t.is(y.path, undefined);
});

test('sync', t => {
const x = m.sync({cwd});
t.is(x.pkg.name, 'read-pkg-up');
t.is(x.path, pkgPath);

const y = m.sync({cwd: '/'});
t.is(y.pkg, undefined);
t.is(y.path, undefined);
});

0 comments on commit 5bb0a79

Please sign in to comment.