-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
getVersion.ts
32 lines (26 loc) · 1020 Bytes
/
getVersion.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
import Debug from '@prisma/debug'
import type { NodeAPILibraryTypes } from '@prisma/engine-core'
import { getCliQueryEngineBinaryType } from '@prisma/engines'
import { BinaryType } from '@prisma/fetch-engine'
import { isNodeAPISupported } from '@prisma/get-platform'
import execa from 'execa'
import { resolveBinary } from '../resolveBinary'
import { load } from '../utils/load'
const debug = Debug('prisma:getVersion')
const MAX_BUFFER = 1_000_000_000
export async function getVersion(enginePath?: string, binaryName?: BinaryType): Promise<string> {
if (!binaryName) {
binaryName = getCliQueryEngineBinaryType()
}
enginePath = await resolveBinary(binaryName, enginePath)
if (binaryName === BinaryType.libqueryEngine) {
await isNodeAPISupported()
const QE = load<NodeAPILibraryTypes.Library>(enginePath)
return `libquery-engine ${QE.version().commit}`
} else {
const result = await execa(enginePath, ['--version'], {
maxBuffer: MAX_BUFFER,
})
return result.stdout
}
}