(generators: GeneratorConfig[])
| 348 | } |
| 349 | |
| 350 | async function validateGenerators(generators: GeneratorConfig[]): Promise<void> { |
| 351 | const binaryTarget = await getBinaryTargetForCurrentPlatform() |
| 352 | |
| 353 | for (const generator of generators) { |
| 354 | if (generator.binaryTargets) { |
| 355 | const binaryTargets = |
| 356 | generator.binaryTargets && generator.binaryTargets.length > 0 |
| 357 | ? generator.binaryTargets |
| 358 | : [{ fromEnvVar: null, value: 'native' }] |
| 359 | |
| 360 | const resolvedBinaryTargets: string[] = binaryTargets |
| 361 | .flatMap((object) => parseBinaryTargetsEnvValue(object)) |
| 362 | .map((p) => (p === 'native' ? binaryTarget : p)) |
| 363 | |
| 364 | for (const resolvedBinaryTarget of resolvedBinaryTargets) { |
| 365 | if (oldToNewBinaryTargetsMapping[resolvedBinaryTarget]) { |
| 366 | throw new Error( |
| 367 | `Binary target ${red(bold(resolvedBinaryTarget))} is deprecated. Please use ${green( |
| 368 | bold(oldToNewBinaryTargetsMapping[resolvedBinaryTarget]), |
| 369 | )} instead.`, |
| 370 | ) |
| 371 | } |
| 372 | if (!knownBinaryTargets.includes(resolvedBinaryTarget as BinaryTarget)) { |
| 373 | throw new Error( |
| 374 | `Unknown binary target ${red(resolvedBinaryTarget)} in generator ${bold(generator.name)}. |
| 375 | Possible binaryTargets: ${green(knownBinaryTargets.join(', '))}`, |
| 376 | ) |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | // Only show warning if resolvedBinaryTargets |
| 381 | // is missing current platform |
| 382 | if (!resolvedBinaryTargets.includes(binaryTarget)) { |
| 383 | const originalBinaryTargetsConfig = getOriginalBinaryTargetsValue(generator.binaryTargets) |
| 384 | |
| 385 | console.log(`${yellow('Warning:')} Your current platform \`${bold( |
| 386 | binaryTarget, |
| 387 | )}\` is not included in your generator's \`binaryTargets\` configuration ${JSON.stringify( |
| 388 | originalBinaryTargetsConfig, |
| 389 | )}. |
| 390 | To fix it, use this generator config in your ${bold('schema.prisma')}: |
| 391 | ${green( |
| 392 | printGeneratorConfig({ |
| 393 | ...generator, |
| 394 | binaryTargets: fixBinaryTargets(generator.binaryTargets, binaryTarget), |
| 395 | }), |
| 396 | )} |
| 397 | ${gray( |
| 398 | `Note, that by providing \`native\`, Prisma Client automatically resolves \`${binaryTarget}\`. |
| 399 | Read more about deploying Prisma Client: ${underline( |
| 400 | 'https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/generators', |
| 401 | )}`, |
| 402 | )}\n`) |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 |
no test coverage detected