(binaryName: BinaryType)
| 70 | } |
| 71 | |
| 72 | export async function resolveEngine(binaryName: BinaryType): Promise<EngineInfo> { |
| 73 | const pathFromEnvOption = O.fromNullable(getBinaryEnvVarPath(binaryName)) |
| 74 | |
| 75 | /** |
| 76 | * Read the binary path, preferably from the environment, or resolving the canonical path |
| 77 | * from the given `binaryName`. |
| 78 | */ |
| 79 | |
| 80 | const fromEnvVarOption: O.Option<string> = pipe( |
| 81 | pathFromEnvOption, |
| 82 | O.map((p) => p.fromEnvVar), |
| 83 | ) |
| 84 | |
| 85 | const enginePathEither: E.Either<Error, string> = await pipe( |
| 86 | pathFromEnvOption, |
| 87 | O.fold( |
| 88 | () => safeResolveBinary(binaryName), |
| 89 | (pathFromEnv) => TE.right(pathFromEnv.path), |
| 90 | ), |
| 91 | )() |
| 92 | |
| 93 | /** |
| 94 | * Read the version from the engine, but only if the enginePath is valid. |
| 95 | */ |
| 96 | |
| 97 | const versionEither: E.Either<Error, string> = await pipe( |
| 98 | enginePathEither, |
| 99 | TE.fromEither, |
| 100 | TE.chain((enginePath) => { |
| 101 | return safeGetEngineVersion(enginePath, binaryName) |
| 102 | }), |
| 103 | )() |
| 104 | |
| 105 | const engineInfo: EngineInfo = { |
| 106 | path: enginePathEither, |
| 107 | version: versionEither, |
| 108 | fromEnvVar: fromEnvVarOption, |
| 109 | } |
| 110 | |
| 111 | return engineInfo |
| 112 | } |
no test coverage detected