Skip to content

Commit 1257846

Browse files
committed
fix: bugs
1 parent 4a4701e commit 1257846

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/cli/utils/packageJsonConfig.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ export async function resolvePackageJsonConfig(startDir: string) {
77

88
let currentDirPath = path.resolve(startDir);
99
while (true) {
10-
const packageJsonPath = path.join(currentDirPath, "package.json");
11-
try {
12-
if (await fs.pathExists(packageJsonPath))
13-
applyConfig(currentConfig, await readPackageJsonConfig(packageJsonPath));
14-
} catch (err) {
15-
// do nothing
16-
}
10+
applyConfig(currentConfig, await readPackageJsonConfig(path.join(currentDirPath, "package.json")));
1711

1812
const parentDirPath = path.dirname(currentDirPath);
1913
if (parentDirPath === currentDirPath)
@@ -22,6 +16,10 @@ export async function resolvePackageJsonConfig(startDir: string) {
2216
currentDirPath = parentDirPath;
2317
}
2418

19+
const npmPackageJsonPath = process.env["npm_package_json"] ?? "";
20+
if (npmPackageJsonPath !== "")
21+
applyConfig(currentConfig, await readPackageJsonConfig(npmPackageJsonPath));
22+
2523
return currentConfig;
2624
}
2725

@@ -45,9 +43,12 @@ export type NlcPackageJsonConfig = {
4543
nodeLlamaCppPostinstall?: NodeLlamaCppPostinstallBehavior
4644
};
4745

48-
function readPackageJsonConfig(packageJsonPath: string) {
46+
async function readPackageJsonConfig(packageJsonPath: string) {
4947
try {
50-
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
48+
if (!(await fs.pathExists(packageJsonPath)))
49+
return {};
50+
51+
const packageJsonContent = await fs.readFile(packageJsonPath, "utf8");
5152
const packageJson = JSON.parse(packageJsonContent);
5253
const config = packageJson?.config;
5354
if (typeof config === "object")

0 commit comments

Comments
 (0)