-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
getEngineVersion.ts
35 lines (29 loc) · 1.24 KB
/
getEngineVersion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { NodeAPILibraryTypes } from '@prisma/engine-core'
import { getCliQueryEngineBinaryType } from '@prisma/engines'
import { BinaryType } from '@prisma/fetch-engine'
import { getPlatformWithOSResult, isNodeAPISupported } from '@prisma/get-platform'
import execa from 'execa'
import * as TE from 'fp-ts/TaskEither'
import { resolveBinary } from '../resolveBinary'
import { loadLibrary } from '../utils/load'
export async function getEngineVersion(enginePath?: string, binaryName?: BinaryType): Promise<string> {
if (!binaryName) {
binaryName = getCliQueryEngineBinaryType()
}
enginePath = await resolveBinary(binaryName, enginePath)
const platformInfo = await getPlatformWithOSResult()
if (binaryName === BinaryType.QueryEngineLibrary) {
await isNodeAPISupported()
const QE = loadLibrary<NodeAPILibraryTypes.Library>(enginePath, platformInfo)
return `${BinaryType.QueryEngineLibrary} ${QE.version().commit}`
} else {
const result = await execa(enginePath, ['--version'])
return result.stdout
}
}
export function safeGetEngineVersion(enginePath?: string, binaryName?: BinaryType): TE.TaskEither<Error, string> {
return TE.tryCatch(
() => getEngineVersion(enginePath, binaryName),
(error) => error as Error,
)
}