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) { if (typeof entryPath !== 'string' || entryPath.trim().length === 0) {
return false; return false;
} }
if (typeof moduleUrl !== 'string' || moduleUrl.trim().length === 0) {
return false;
}
try { try {
const normalizedEntryPath = normalizeCliEntryPath(entryPath, realpath); const normalizedEntryPath = normalizeCliEntryPath(entryPath, realpath);
@@ -26,7 +34,16 @@ function isModuleCliExecution(entryPath = process.argv[1], moduleUrl = import.me
if (!normalizedEntryPath || !normalizedModulePath) { if (!normalizedEntryPath || !normalizedModulePath) {
return false; 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 { } catch {
return false; return false;
} }
+1 -1
View File
@@ -4616,7 +4616,7 @@ async function main() {
await commands[command](options); await commands[command](options);
} }
const isCliExecution = isModuleCliExecution(); const isCliExecution = isModuleCliExecution(process.argv[1], import.meta.url, fs.realpathSync, 'openchamber');
if (isCliExecution) { if (isCliExecution) {
let isHandlingSigint = false; let isHandlingSigint = false;
+9
View File
@@ -36,6 +36,15 @@ describe('cli entry detection', () => {
expect(isModuleCliExecution('', moduleUrl)).toBe(false); expect(isModuleCliExecution('', moduleUrl)).toBe(false);
}); });
it('returns false when module url is not provided', () => {
expect(isModuleCliExecution(modulePath)).toBe(false);
});
it('accepts wrapper binary name fallback when requested', () => {
const wrapperPath = '/home/user/.local/bin/openchamber';
expect(isModuleCliExecution(wrapperPath, moduleUrl, undefined, 'openchamber')).toBe(true);
});
it('normalizes direct paths when realpath fails', () => { it('normalizes direct paths when realpath fails', () => {
const unresolvedPath = './packages/web/bin/cli.js'; const unresolvedPath = './packages/web/bin/cli.js';
const realpath = () => { const realpath = () => {