| 5 | const { spawnSync } = require('node:child_process') |
| 6 | |
| 7 | function tryResolveNativeBinaryFromOptionalDeps() { |
| 8 | const platform = process.platform |
| 9 | const arch = process.arch |
| 10 | |
| 11 | const candidates = [`@shareai-lab/kode-bin-${platform}-${arch}`] |
| 12 | |
| 13 | // Windows ARM64 can usually run x64 binaries via emulation, so offer a fallback. |
| 14 | if (platform === 'win32' && arch === 'arm64') { |
| 15 | candidates.push('@shareai-lab/kode-bin-win32-x64') |
| 16 | } |
| 17 | |
| 18 | for (const pkgName of candidates) { |
| 19 | try { |
| 20 | // eslint-disable-next-line import/no-dynamic-require |
| 21 | const mod = require(pkgName) |
| 22 | const binPath = mod?.kodePath |
| 23 | if (typeof binPath === 'string' && fs.existsSync(binPath)) { |
| 24 | return binPath |
| 25 | } |
| 26 | } catch {} |
| 27 | } |
| 28 | |
| 29 | return null |
| 30 | } |
| 31 | |
| 32 | function findPackageRoot(startDir) { |
| 33 | let dir = startDir |