Skip to content

Commit

Permalink
Correctly detect if np isn't run in a package (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
itaisteinherz authored Mar 4, 2020
1 parent d9848db commit b5a7dcf
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions source/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ const pMemoize = require('p-memoize');
const ow = require('ow');
const pkgDir = require('pkg-dir');

exports.readPkg = (packagePath = pkgDir.sync()) => {
exports.readPkg = packagePath => {
packagePath = packagePath ? pkgDir.sync(packagePath) : pkgDir.sync();

if (!packagePath) {
throw new Error('No `package.json` found. Make sure the current directory is a valid package.');
}

const {packageJson} = readPkgUp.sync({
cwd: packagePath
});

if (!packageJson) {
throw new Error(`No package.json found. Make sure ${packagePath} is a valid package`);
}

return packageJson;
};

Expand Down

0 comments on commit b5a7dcf

Please sign in to comment.