Skip to content

Commit

Permalink
Closes #254
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Nov 7, 2019
1 parent 48c3f80 commit dcda90c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/engine-core/src/NodeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface DatasourceOverwrite {

export interface EngineConfig {
cwd?: string
datamodel: string
datamodelPath: string
debug?: boolean
prismaPath?: string
fetcher?: (query: string) => Promise<{ data?: any; error?: any }>
Expand Down Expand Up @@ -60,7 +60,7 @@ export class NodeEngine extends Engine {
managementApiEnabled: boolean = false
datamodelJson?: string
cwd: string
datamodel: string
datamodelPath: string
prismaPath?: string
url: string
ready: boolean = false
Expand All @@ -76,11 +76,11 @@ export class NodeEngine extends Engine {
lastError?: RustLog
startPromise?: Promise<any>

constructor({ cwd, datamodel, prismaPath, generator, datasources, ...args }: EngineConfig) {
constructor({ cwd, datamodelPath, prismaPath, generator, datasources, ...args }: EngineConfig) {
super()
this.cwd = this.resolveCwd(cwd)
this.debug = args.debug || false
this.datamodel = datamodel
this.datamodelPath = datamodelPath
this.prismaPath = prismaPath
this.platform = process.env.PRISMA_QUERY_ENGINE_BINARY
this.generator = generator
Expand Down Expand Up @@ -283,7 +283,7 @@ ${chalk.dim("In case we're mistaken, please report this to us 🙏.")}`)
this.port = await this.getFreePort()

const env: any = {
PRISMA_DML: this.datamodel,
PRISMA_DML_PATH: this.datamodelPath,
PORT: String(this.port),
RUST_BACKTRACE: '1',
RUST_LOG: 'info',
Expand Down
1 change: 1 addition & 0 deletions packages/photon/src/__tests__/generation/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('generator', () => {
"index.d.ts",
"index.js",
"runtime",
"schema.prisma",
]
`)
generator.stop()
Expand Down
11 changes: 2 additions & 9 deletions packages/photon/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const commonCode = (runtimePath: string, version?: string) => `import {
*/
import path = require('path')
import fs = require('fs')
const debug = debugLib('photon')
Expand Down Expand Up @@ -133,7 +134,6 @@ class PhotonFetcher {
interface TSClientOptions {
version?: string
document: DMMF.Document
datamodel: string
runtimePath: string
browser?: boolean
datasources: InternalDatasource[]
Expand All @@ -147,7 +147,6 @@ interface TSClientOptions {
export class TSClient {
protected readonly dmmf: DMMFClass
protected readonly document: DMMF.Document
protected readonly datamodel: string
protected readonly runtimePath: string
protected readonly browser: boolean
protected readonly outputDir: string
Expand All @@ -159,7 +158,6 @@ export class TSClient {
protected readonly schemaDir?: string
constructor({
document,
datamodel,
runtimePath,
browser = false,
datasources,
Expand All @@ -170,7 +168,6 @@ export class TSClient {
outputDir,
}: TSClientOptions) {
this.document = document
this.datamodel = datamodel
this.runtimePath = runtimePath
this.browser = browser
this.internalDatasources = datasources
Expand Down Expand Up @@ -199,7 +196,6 @@ ${this.platforms ? this.platforms.map(p => `path.join(__dirname, 'runtime/query-
${new PhotonClientClass(
this.dmmf,
this.datamodel,
this.internalDatasources,
this.outputDir,
this.browser,
Expand Down Expand Up @@ -261,7 +257,6 @@ ${indent(sources.map(s => `${s.name}?: string`).join('\n'), 2)}
class PhotonClientClass {
constructor(
protected readonly dmmf: DMMFClass,
protected readonly datamodel: string,
protected readonly internalDatasources: InternalDatasource[],
protected readonly outputDir: string,
protected readonly browser?: boolean,
Expand Down Expand Up @@ -303,7 +298,6 @@ export class Photon {
private fetcher: PhotonFetcher
private readonly dmmf: DMMFClass
private readonly engine: Engine
private readonly datamodel: string
private connectionPromise?: Promise<any>
constructor(options: PhotonOptions = {}) {
const useDebug = options.debug === true ? true : typeof options.debug === 'object' ? Boolean(options.debug.library) : false
Expand All @@ -313,7 +307,6 @@ export class Photon {
const debugEngine = options.debug === true ? true : typeof options.debug === 'object' ? Boolean(options.debug.engine) : false
// datamodel = datamodel without datasources + printed datasources
this.datamodel = ${JSON.stringify(this.datamodel)}
const predefinedDatasources = ${
this.sqliteDatasourceOverrides
Expand All @@ -330,7 +323,7 @@ export class Photon {
this.engine = new Engine({
cwd: engineConfig.cwd || ${getRelativePathResolveStatement(this.outputDir, this.cwd)},
debug: debugEngine,
datamodel: this.datamodel,
datamodelPath: path.resolve(__dirname, 'schema.prisma'),
prismaPath: engineConfig.binaryPath || undefined,
datasources,
generator: ${this.generator ? JSON.stringify(this.generator) : 'undefined'},
Expand Down
11 changes: 6 additions & 5 deletions packages/photon/src/generation/generateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const copyFile = promisify(fs.copyFile)

export interface GenerateClientOptions {
datamodel: string
datamodelPath?: string
datamodelPath: string
browser?: boolean
schemaDir?: string
transpile?: boolean
Expand Down Expand Up @@ -68,7 +68,6 @@ export async function buildClient({

const client = new TSClient({
document,
datamodel,
runtimePath,
browser,
datasources: resolveDatasources(datasources, schemaDir, outputDir),
Expand Down Expand Up @@ -163,13 +162,13 @@ export async function generateClient({
runtimePath = runtimePath || './runtime'
const { photonDmmf, fileMap } = await buildClient({
datamodel,
datamodelPath,
schemaDir,
transpile,
runtimePath,
browser,
outputDir,
generator,
datamodelPath,
version,
dmmf,
datasources,
Expand All @@ -193,7 +192,7 @@ export async function generateClient({
}),
)
const inputDir = testMode
? eval(`require('path').join(__dirname, '../../runtime')`)
? eval(`require('path').join(__dirname, '../../runtime')`) // tslint:disable-line
: eval(`require('path').join(__dirname, '../runtime')`) // tslint:disable-line

await copy({
Expand All @@ -215,7 +214,9 @@ export async function generateClient({
await copyFile(filePath, target)
}

await writeFile(path.join(outputDir, '/runtime/index.d.ts'), backup)
await copyFile(datamodelPath, path.join(outputDir, 'schema.prisma'))

await writeFile(path.join(outputDir, 'runtime/index.d.ts'), backup)
}

const backup = `export { DMMF } from './dmmf-types'
Expand Down
1 change: 1 addition & 0 deletions packages/photon/src/utils/generateInFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function generateInFolder({
runtimePath: useLocalRuntime ? path.relative(outputDir, path.join(__dirname, '../runtime')) : undefined,
transpile,
testMode: true,
datamodelPath: schemaPath,
})

const after = performance.now()
Expand Down

0 comments on commit dcda90c

Please sign in to comment.