fix(cli): restore openchamber startup under npm/bun global shims
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -4616,7 +4616,7 @@ async function main() {
|
||||
await commands[command](options);
|
||||
}
|
||||
|
||||
const isCliExecution = isModuleCliExecution();
|
||||
const isCliExecution = isModuleCliExecution(process.argv[1], import.meta.url, fs.realpathSync, 'openchamber');
|
||||
|
||||
if (isCliExecution) {
|
||||
let isHandlingSigint = false;
|
||||
|
||||
@@ -36,6 +36,15 @@ describe('cli entry detection', () => {
|
||||
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', () => {
|
||||
const unresolvedPath = './packages/web/bin/cli.js';
|
||||
const realpath = () => {
|
||||
|
||||
Reference in New Issue
Block a user