8000 Correctly detect if np isn't run in a package (#512) · JavaScriptExpert/np@b5a7dcf · GitHub
[go: up one dir, main page]

Skip to content

Commit b5a7dcf

Browse files
Correctly detect if np isn't run in a package (sindresorhus#512)
1 parent d9848db commit b5a7dcf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

source/util.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ const pMemoize = require('p-memoize');
77
const ow = require('ow');
88
const pkgDir = require('pkg-dir');
99

10-
exports.readPkg = (packagePath = pkgDir.sync()) => {
10+
exports.readPkg = packagePath => {
11+
packagePath = packagePath ? pkgDir.sync(packagePath) : pkgDir.sync();
12+
13+
if (!packagePath) {
14+
throw new Error('No `package.json` found. Make sure the current directory is a valid package.');
15+
}
16+
1117
const {packageJson} = readPkgUp.sync({
1218
cwd: packagePath
1319
});
1420

15-
if (!packageJson) {
16-
throw new Error(`No package.json found. Make sure ${packagePath} is a valid package`);
17-
}
18-
1921
return packageJson;
2022
};
2123

0 commit comments

Comments
 (0)
0