Skip to content

Commit

Permalink
fix(client): version. Closes #696
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jun 18, 2020
1 parent 7fedf3a commit 4b5ca67
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/packages/client/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ const {
const path = require('path')
const debug = debugLib('prisma-client')
debug("Client Version ${clientVersion}")
debug("Engine Version ${engineVersion}")
/**
* Prisma Client JS version: ${clientVersion}
* Query Engine version: ${engineVersion}
Expand Down Expand Up @@ -268,6 +265,7 @@ export class TSClient implements Generatable {
relativePath: path.relative(outputDir, schemaDir),
internalDatasources: datasources,
clientVersion: this.options.clientVersion,
engineVersion: this.options.engineVersion,
}

return `${commonCodeJS(this.options)}
Expand Down
16 changes: 15 additions & 1 deletion src/packages/client/src/runtime/getPrismaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface GetPrismaClientOptions {
dirname: string
internalDatasources: InternalDatasource[]
clientVersion?: string
engineVersion?: string
}

// TODO: We **may** be able to get real types. However, we have both a bootstrapping
Expand Down Expand Up @@ -307,7 +308,20 @@ export function getPrismaClient(config: GetPrismaClientOptions): any {
if (this.connectionPromise) {
return this.connectionPromise
}
this.connectionPromise = this.engine.start()
this.connectionPromise = (async () => {
await this.engine.start()

let { engineVersion, clientVersion } = config
if (
this.engineConfig.prismaPath ||
process.env.QUERY_ENGINE_BINARY_PATH ||
!engineVersion
) {
engineVersion = await this.engine.version()
}
debug(`Client Version ${clientVersion}`)
debug(`Engine Version ${engineVersion}`)
})()
return this.connectionPromise
}
/**
Expand Down
1 change: 1 addition & 0 deletions src/packages/engine-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"bent": "^7.1.2",
"chalk": "^3.0.0",
"cross-fetch": "^3.0.4",
"execa": "^4.0.2",
"fast-json-stringify": "^2.0.0",
"get-stream": "^5.1.0",
"indent-string": "^4.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/packages/engine-core/src/NodeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { spawn, ChildProcessWithoutNullStreams } from 'child_process'
import byline from './byline'
import { H1Client } from './h1client'
import pRetry from 'p-retry'
import execa from 'execa'

const debug = debugLib('engine')
const exists = promisify(fs.exists)
Expand Down Expand Up @@ -724,6 +725,18 @@ ${this.lastErrorLog.fields.file}:${this.lastErrorLog.fields.line}:${this.lastErr
})
}

async version() {
const prismaPath = await this.getPrismaPath()

const result = await execa(prismaPath, ['--version'], {
env: {
...process.env,
},
})

return result.stdout
}

async request<T>(query: string): Promise<T> {
await this.start()

Expand Down
2 changes: 2 additions & 0 deletions src/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b5ca67

Please sign in to comment.