()
| 84 | } |
| 85 | |
| 86 | export function locateBinary(): string { |
| 87 | const override = process.env.CMDOP_CORE_BINARY; |
| 88 | if (override) { |
| 89 | if (!existsSync(override)) { |
| 90 | throw new Error(`CMDOP_CORE_BINARY points at a missing file: ${override}`); |
| 91 | } |
| 92 | makeExecutable(override); |
| 93 | return override; |
| 94 | } |
| 95 | |
| 96 | const key = `${process.platform}-${process.arch}`; |
| 97 | if (!SUPPORTED_PLATFORMS.has(key)) { |
| 98 | throw new Error( |
| 99 | `cmdop-core has no prebuilt binary for ${key}. ` + |
| 100 | "Set CMDOP_CORE_BINARY to a `go build -o /path/cmdop-core ./cmd/cmdop-core` output.", |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | const binPath = join(packageBinDir(), binaryName()); |
| 105 | if (!existsSync(binPath)) { |
| 106 | throw new Error( |
| 107 | `cmdop-core binary not found at ${binPath}. ` + |
| 108 | "Reinstall @cmdop/sdk (the 5 baked binaries ship in its bin/ dir), " + |
| 109 | "or set CMDOP_CORE_BINARY to a local `go build` output.", |
| 110 | ); |
| 111 | } |
| 112 | makeExecutable(binPath); |
| 113 | return binPath; |
| 114 | } |
| 115 | |
| 116 | function makeExecutable(path: string): void { |
| 117 | if (process.platform === "win32") return; |
no test coverage detected