Skip to content

Commit

Permalink
fix: print getConfig warnings (#4124)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Nov 2, 2020
1 parent b26d836 commit d1e2e15
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 0 deletions.
@@ -0,0 +1 @@
!dev.db
Binary file not shown.
@@ -0,0 +1,37 @@
datasource db {
provider = ["postgresql", "sqlite"]
url = "file:./dev.db"
default = true
}

generator client {
provider = "prisma-client-js"
}

// / User model comment
model User {
id String @id @default(uuid())
email String @unique
// / name comment
name String?
posts Post[]
profile Profile?
}

model Profile {
id String @id @default(cuid())
bio String?
user User @relation(fields: [userId], references: [id])
userId String @unique
}

model Post {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean
title String
content String?
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
}
@@ -0,0 +1,30 @@
import { getTestClient } from '../../../../utils/getTestClient'

test('provider-array', async () => {
const warnings: any[] = []
const oldWarn = console.warn
console.warn = (...args) => {
warnings.push(args)
}
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
const users = await prisma.user.findMany()
await prisma.$disconnect()
expect(users).toMatchInlineSnapshot(`
Array [
Object {
email: a@a.de,
id: 576eddf9-2434-421f-9a86-58bede16fd95,
name: Alice,
},
]
`)
expect(warnings).toMatchInlineSnapshot(`
Array [
Array [
warn Using multiple providers is now deprecated. You should use a single provider instead. Read more at https://pris.ly/multi-provider-deprecation,
],
]
`)
console.warn = oldWarn
})
3 changes: 3 additions & 0 deletions src/packages/client/src/utils/getTestClient.ts
Expand Up @@ -5,6 +5,7 @@ import {
getConfig,
extractPreviewFeatures,
mapPreviewFeatures,
printConfigWarnings,
} from '@prisma/sdk'
import { getDMMF } from '../generation/getDMMF'
import { promisify } from 'util'
Expand All @@ -28,6 +29,8 @@ export async function getTestClient(schemaDir?: string): Promise<any> {
const schemaPath = await getRelativeSchemaPath(schemaDir)
const datamodel = await readFile(schemaPath!, 'utf-8')
const config = await getConfig({ datamodel, ignoreEnvVarErrors: true })
printConfigWarnings(config.warnings)

const generator = config.generators.find(
(g) => g.provider === 'prisma-client-js',
)
Expand Down
1 change: 1 addition & 0 deletions src/packages/sdk/src/engineCommands.ts
Expand Up @@ -15,6 +15,7 @@ const MAX_BUFFER = 1000_000_000
export interface ConfigMetaFormat {
datasources: DataSource[]
generators: GeneratorConfig[]
warnings: string[]
}

export type GetDMMFOptions = {
Expand Down
3 changes: 3 additions & 0 deletions src/packages/sdk/src/getGenerators.ts
Expand Up @@ -29,6 +29,7 @@ import { extractPreviewFeatures } from './utils/extractPreviewFeatures'
import { mapPreviewFeatures } from './utils/mapPreviewFeatures'
import { engineVersions } from './getAllVersions'
import { enginesVersion } from '@prisma/engines'
import { printConfigWarnings } from './utils/printConfigWarnings'


export type ProviderAliases = { [alias: string]: GeneratorPaths }
Expand Down Expand Up @@ -103,6 +104,8 @@ export async function getGenerators({
ignoreEnvVarErrors: true,
})

printConfigWarnings(config.warnings)

// TODO: This needs a better abstraction, but we don't have any better right now
const experimentalFeatures = mapPreviewFeatures(
extractPreviewFeatures(config),
Expand Down
3 changes: 3 additions & 0 deletions src/packages/sdk/src/index.ts
@@ -1,3 +1,4 @@

export { pick } from './pick'

export { keyBy } from './keyBy'
Expand Down Expand Up @@ -80,3 +81,5 @@ export {
createDatabase,
dropDatabase,
} from './migrateEngineCommands'

export { printConfigWarnings } from './utils/printConfigWarnings'
8 changes: 8 additions & 0 deletions src/packages/sdk/src/utils/printConfigWarnings.ts
@@ -0,0 +1,8 @@
import chalk from "chalk"

export function printConfigWarnings(warnings: string[]) {
if (warnings && warnings.length > 0) {
const message = warnings.map(warning => `${chalk.yellow('warn')} ${warning}`).join('\n')
console.warn(message)
}
}

0 comments on commit d1e2e15

Please sign in to comment.