Skip to content

Commit

Permalink
fix(client): env-var loading (prisma#7669)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 authored and Andrew-Colman committed Aug 7, 2021
1 parent c52aeaf commit 881800b
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/packages/client/src/generation/TSClient/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,17 @@ export class TSClient implements Generatable {
this.dmmf = new DMMFClass(klona(options.document))
}
public toJS(): string {
const {
generator,
sqliteDatasourceOverrides,
outputDir,
schemaDir,
projectRoot,
} = this.options
const { generator, sqliteDatasourceOverrides, outputDir, schemaDir } =
this.options
const schemaPath = path.join(schemaDir, 'prisma.schema')
const envPaths = getEnvPaths(schemaPath, { cwd: projectRoot })
const envPaths = getEnvPaths(schemaPath, { cwd: outputDir })

const relativeEnvPaths = {
rootEnvPath:
envPaths.rootEnvPath &&
path.relative(projectRoot, envPaths.rootEnvPath),
envPaths.rootEnvPath && path.relative(outputDir, envPaths.rootEnvPath),
schemaEnvPath:
envPaths.schemaEnvPath &&
path.relative(projectRoot, envPaths.schemaEnvPath),
path.relative(outputDir, envPaths.schemaEnvPath),
}

const config: Omit<GetPrismaClientOptions, 'document' | 'dirname'> = {
Expand Down Expand Up @@ -148,8 +142,8 @@ config.dirname = dirname
* loading of env variable occurs in getPrismaClient
*/
const envPaths = {
rootEnvPath: config.relativeEnvPaths.rootEnvPath && path.resolve(process.cwd(), config.relativeEnvPaths.rootEnvPath),
schemaEnvPath: config.relativeEnvPaths.schemaEnvPath && path.resolve(process.cwd(), config.relativeEnvPaths.schemaEnvPath)
rootEnvPath: config.relativeEnvPaths.rootEnvPath && path.resolve(dirname, config.relativeEnvPaths.rootEnvPath),
schemaEnvPath: config.relativeEnvPaths.schemaEnvPath && path.resolve(dirname, config.relativeEnvPaths.schemaEnvPath)
}
warnEnvConflicts(envPaths)
Expand Down

0 comments on commit 881800b

Please sign in to comment.