Fix SDK embed ENOENT when package.json missing (closes #5226)
- Wrap package.json read in try/catch to handle missing file gracefully - Use defaults (APP_NAME=pi, CONFIG_DIR_NAME=.pi, etc.) when package.json not found - Preserves rebranding via piConfig when package.json exists - Only ignores ENOENT; other errors still throw
This commit is contained in:
@@ -452,7 +452,13 @@ interface PackageJson {
|
||||
};
|
||||
}
|
||||
|
||||
const pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8")) as PackageJson;
|
||||
let pkg: PackageJson = {};
|
||||
try {
|
||||
pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8")) as PackageJson;
|
||||
} catch (e: unknown) {
|
||||
const err = e as NodeJS.ErrnoException;
|
||||
if (err.code !== "ENOENT") throw e;
|
||||
}
|
||||
|
||||
const piConfigName: string | undefined = pkg.piConfig?.name;
|
||||
export const PACKAGE_NAME: string = pkg.name || "@earendil-works/pi-coding-agent";
|
||||
|
||||
Reference in New Issue
Block a user