fix(registryClient): fix wrong location for the cli config file (#10812)

fix(registryClient): handle relative file paths more robustly

First attempt to resolve relative paths against current working directory before falling back to rootPath. This provides better flexibility when files are not located relative to rootPath.
This commit is contained in:
ian 2026-03-25 02:21:49 +08:00 • committed by GitHub
parent 594049eae2
commit 29a8a33b84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,9 +48,16 @@ export class RegistryClient implements Registry {
return fs.readFileSync(new URL(filepath), "utf8");
} else if (path.isAbsolute(filepath)) {
return fs.readFileSync(filepath, "utf8");
} else if (this.rootPath) {
return fs.readFileSync(path.join(this.rootPath, filepath), "utf8");
} else {
// Try to resolve relative to current working directory first
const resolvedPath = path.resolve(filepath);
if (fs.existsSync(resolvedPath)) {
return fs.readFileSync(resolvedPath, "utf8");
}
// Fall back to rootPath if file doesn't exist relative to cwd
if (this.rootPath) {
return fs.readFileSync(path.join(this.rootPath, filepath), "utf8");
}
throw new Error("No rootPath provided for relative file path");
}
}