diff --git a/apps/frontend/scripts/postinstall.cjs b/apps/frontend/scripts/postinstall.cjs index 0e36f571..e4c02e6d 100644 --- a/apps/frontend/scripts/postinstall.cjs +++ b/apps/frontend/scripts/postinstall.cjs @@ -93,12 +93,40 @@ function runElectronRebuild() { * Check if node-pty is already built */ function isNodePtyBuilt() { - const buildDir = path.join(__dirname, '..', 'node_modules', 'node-pty', 'build', 'Release'); - if (!fs.existsSync(buildDir)) return false; + // Check traditional node-pty build location (local node_modules) + const localBuildDir = path.join(__dirname, '..', 'node_modules', 'node-pty', 'build', 'Release'); + if (fs.existsSync(localBuildDir)) { + const files = fs.readdirSync(localBuildDir); + if (files.some((f) => f.endsWith('.node'))) return true; + } - // Check for the main .node file - const files = fs.readdirSync(buildDir); - return files.some((f) => f.endsWith('.node')); + // Check root node_modules (for npm workspaces) + const rootBuildDir = path.join(__dirname, '..', '..', '..', 'node_modules', 'node-pty', 'build', 'Release'); + if (fs.existsSync(rootBuildDir)) { + const files = fs.readdirSync(rootBuildDir); + if (files.some((f) => f.endsWith('.node'))) return true; + } + + // Check for @lydell/node-pty with platform-specific prebuilts + const arch = os.arch(); + const platform = os.platform(); + const platformPkg = `@lydell/node-pty-${platform}-${arch}`; + + // Check local node_modules + const localLydellDir = path.join(__dirname, '..', 'node_modules', platformPkg); + if (fs.existsSync(localLydellDir)) { + const files = fs.readdirSync(localLydellDir); + if (files.some((f) => f.endsWith('.node'))) return true; + } + + // Check root node_modules (for npm workspaces) + const rootLydellDir = path.join(__dirname, '..', '..', '..', 'node_modules', platformPkg); + if (fs.existsSync(rootLydellDir)) { + const files = fs.readdirSync(rootLydellDir); + if (files.some((f) => f.endsWith('.node'))) return true; + } + + return false; } /**