Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 97f8242

Browse files
author
sw-yx
committed
minor bugfix
1 parent f749d38 commit 97f8242

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/detectors/utils/jsdetect.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ let pkgJSON = null,
99

1010
/** hold package.json in a singleton so we dont do expensive parsing repeatedly */
1111
function getPkgJSON() {
12-
if (pkgJSON) return pkgJSON;
13-
else return JSON.parse(readFileSync("package.json", { encoding: "utf8" }));
12+
if (pkgJSON) {
13+
return pkgJSON;
14+
} else {
15+
if (!existsSync("package.json"))
16+
throw new Error(
17+
"dont call this method unless you already checked for pkg json"
18+
);
19+
pkgJSON = JSON.parse(readFileSync("package.json", { encoding: "utf8" }));
20+
return pkgJSON;
21+
}
1422
}
1523
function getYarnOrNPMCommand() {
1624
if (!yarnExists) {

0 commit comments

Comments
 (0)