Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: use `which bun` on macOS/Linux instead of hardcoded ~/.bun/bin/bun path

Andrew Breckenridgee2d0370e6a23
diff --git a/apps/screenpipe-app-tauri/scripts/pre_build.js b/apps/screenpipe-app-tauri/scripts/pre_build.js
index bedf65d08..93e825b23 100644
--- a/apps/screenpipe-app-tauri/scripts/pre_build.js
+++ b/apps/screenpipe-app-tauri/scripts/pre_build.js
@@ -165,13 +165,43 @@ async function copyBunBinary() {
bunDest1 = path.join(cwd, 'bun-x86_64-pc-windows-msvc.exe');
console.log('copying bun from:', bunSrc);
console.log('copying bun to:', bunDest1);
- } else if (platform === 'macos') {
- bunSrc = path.join(os.homedir(), '.bun', 'bin', 'bun');
- bunDest1 = path.join(cwd, 'bun-aarch64-apple-darwin');
- bunDest2 = path.join(cwd, 'bun-x86_64-apple-darwin');
- } else if (platform === 'linux') {
- bunSrc = path.join(os.homedir(), '.bun', 'bin', 'bun');
- bunDest1 = path.join(cwd, 'bun-x86_64-unknown-linux-gnu');
+ } else if (platform === 'macos' || platform === 'linux') {
+ const possibleBunPaths = [
+ path.join(os.homedir(), '.bun', 'bin', 'bun'),
+ ];
+
+ // Try to find bun via `which`
+ try {
+ const whichBun = (await $`which bun`.text()).trim();
+ if (whichBun) {
+ possibleBunPaths.unshift(whichBun);
+ }
+ } catch {
+ // which failed, rely on default paths
+ }
+
+ bunSrc = null;
+ for (const possiblePath of possibleBunPaths) {
+ try {
+ await fs.access(possiblePath);
+ console.log('found bun at:', possiblePath);
+ bunSrc = possiblePath;
+ break;
+ } catch {
+ continue;
+ }
+ }
+
+ if (!bunSrc) {
+ throw new Error('Could not find bun binary. Please check if bun is installed correctly');
+ }
+
+ if (platform === 'macos') {
+ bunDest1 = path.join(cwd, 'bun-aarch64-apple-darwin');
+ bunDest2 = path.join(cwd, 'bun-x86_64-apple-darwin');
+ } else {
+ bunDest1 = path.join(cwd, 'bun-x86_64-unknown-linux-gnu');
+ }
}
if (await fs.exists(bunDest1)) {