Skip to content

Commit f7aa5dc

Browse files
committed
feat: do not crash if package.json doesn't exist
1 parent bd36e1b commit f7aa5dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/private/update-package-json.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ const { resolve } = require("path")
55
, writeFile = require("fs2/write-file");
66

77
const resolveIndentationString = async packageJsonPath => {
8-
const match = String(await readFile(packageJsonPath)).match(/^(\s+)[^\s]/u);
9-
return (match && match[1]) || " ";
8+
const packageJsonString = await readFile(packageJsonPath, { loose: true, encoding: "utf8" });
9+
if (packageJsonString) {
10+
const match = packageJsonString.match(/^(\s+)[^\s]/u);
11+
if (match) return match[1];
12+
}
13+
return " ";
1014
};
1115

1216
module.exports = async (path, packageJson) => {

0 commit comments

Comments
 (0)