fix(cli): restore openchamber startup under npm/bun global shims

This commit is contained in:
Bohdan Triapitsyn
2026-03-13 11:33:23 +02:00
parent 875491c438
commit d160263f4f
3 changed files with 29 additions and 3 deletions
+19 -2
View File
@@ -15,10 +15,18 @@ function normalizeCliEntryPath(filePath, realpath = fs.realpathSync) {
}
}
function isModuleCliExecution(entryPath = process.argv[1], moduleUrl = import.meta.url, realpath = fs.realpathSync) {
function isModuleCliExecution(
entryPath = process.argv[1],
moduleUrl,
realpath = fs.realpathSync,
expectedBinName,
) {
if (typeof entryPath !== 'string' || entryPath.trim().length === 0) {
return false;
}
if (typeof moduleUrl !== 'string' || moduleUrl.trim().length === 0) {
return false;
}
try {
const normalizedEntryPath = normalizeCliEntryPath(entryPath, realpath);
@@ -26,7 +34,16 @@ function isModuleCliExecution(entryPath = process.argv[1], moduleUrl = import.me
if (!normalizedEntryPath || !normalizedModulePath) {
return false;
}
return pathToFileURL(normalizedEntryPath).href === pathToFileURL(normalizedModulePath).href;
if (pathToFileURL(normalizedEntryPath).href === pathToFileURL(normalizedModulePath).href) {
return true;
}
if (typeof expectedBinName === 'string' && expectedBinName.trim().length > 0) {
const parsedEntryName = path.parse(normalizedEntryPath).name.toLowerCase();
return parsedEntryName === expectedBinName.trim().toLowerCase();
}
return false;
} catch {
return false;
}