Browse Source

fix: use package name instead of temp path when running via bunx/npx

When running `bunx oh-my-opencode-slim@latest install`, the plugin
entry was being set to a file:// URL pointing to /tmp/bunx-... which
gets deleted after reboot. This caused the plugin to stop working.

Now we detect when running from a temporary directory (bunx/npx) and
use the package name 'oh-my-opencode-slim' instead, which resolves
correctly from the actual installed location.

Fixes #293
Alvin Real 2 days ago
parent
commit
50a0fee997
1 changed files with 25 additions and 0 deletions
  1. 25 0
      src/cli/config-io.ts

+ 25 - 0
src/cli/config-io.ts

@@ -31,6 +31,25 @@ function isPluginEntry(entry: string): boolean {
   );
 }
 
+function isRunningFromTempDir(cliEntryPath: string): boolean {
+  // Detect bunx temporary directories (e.g., /tmp/bunx-...)
+  const bunxPatterns = [
+    /[\\/]tmp[\\/]bunx-[^\\/]+[\\/]/,
+    /[\\/]tmp[\\/]\.bunx[\\/]/,
+  ];
+
+  // Detect npx temporary directories
+  const npxPatterns = [
+    /[\\/]\.npm[\\/]_npx[\\/]/,
+    /[\\/]tmp[\\/]npx[\\/]/,
+    /[\\/]npx-cache[\\/]/,
+  ];
+
+  return [...bunxPatterns, ...npxPatterns].some((pattern) =>
+    pattern.test(cliEntryPath),
+  );
+}
+
 function getPluginEntry(): string {
   const cliEntryPath = process.argv[1];
 
@@ -38,6 +57,12 @@ function getPluginEntry(): string {
     return PACKAGE_NAME;
   }
 
+  // When running via bunx/npx, the package is in a temp directory that gets cleaned up
+  // Use the package name instead so it resolves from the actual installed location
+  if (isRunningFromTempDir(cliEntryPath)) {
+    return PACKAGE_NAME;
+  }
+
   try {
     const pluginEntryPath = cliEntryPath.match(
       /[\\/]dist[\\/]cli[\\/]index\.js$/,