Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/build/src/extensions/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export class PrismaExtension implements BuildExtension {

context.logger.debug(`PrismaExtension is generating the Prisma client for version ${version}`);

const usingSchemaFolder = dirname(this._resolvedSchemaPath).endsWith("schema");
// Auto-detect schema folder by checking for multiple .prisma files
const schemaDir = dirname(this._resolvedSchemaPath);
const prismaFilesInDir = await readdir(schemaDir)
.then((files) => files.filter((file) => file.endsWith(".prisma")))
.catch(() => []);
const usingSchemaFolder = prismaFilesInDir.length > 1;

const commands: string[] = [];

Expand Down Expand Up @@ -155,13 +160,11 @@ export class PrismaExtension implements BuildExtension {
}

if (usingSchemaFolder) {
const schemaDir = dirname(this._resolvedSchemaPath);

prismaDir = dirname(schemaDir);

context.logger.debug(`Using the schema folder: ${schemaDir}`);

// Find all the files in schemaDir that end with .prisma (excluding the schema.prisma file)
// Find all the files in schemaDir that end with .prisma
const prismaFiles = await readdir(schemaDir).then((files) =>
files.filter((file) => file.endsWith(".prisma"))
);
Expand All @@ -183,10 +186,14 @@ export class PrismaExtension implements BuildExtension {
await cp(source, destination);
}

// Prisma 6.6+ requires --schema flag for schema folders
const [major, minor] = version.split(".").map(Number);
const requiresSchemaFlag = major > 6 || (major === 6 && minor >= 6);

commands.push(
`${binaryForRuntime(
manifest.runtime
)} node_modules/prisma/build/index.js generate ${generatorFlags.join(" ")}` // Don't add the --schema flag or this will fail
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate${
requiresSchemaFlag ? " --schema=./prisma/schema" : ""
} ${generatorFlags.join(" ")}`
Comment on lines +190 to +196
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix version parsing before gating --schema.

If version comes from a range (e.g. ^6.6.0, workspace:*), version.split(".").map(Number) yields NaN, so requiresSchemaFlag stays false and we skip --schema. On Prisma 6.6+ folder builds that omission breaks prisma generate. Extract the numeric major/minor safely before deciding.

-      const [major, minor] = version.split(".").map(Number);
-      const requiresSchemaFlag = major > 6 || (major === 6 && minor >= 6);
+      const versionMatch = version.match(/(\d+)(?:\.(\d+))?/);
+      const major = versionMatch ? Number(versionMatch[1]) : undefined;
+      const minor = versionMatch && versionMatch[2] ? Number(versionMatch[2]) : 0;
+      const requiresSchemaFlag =
+        major !== undefined && (major > 6 || (major === 6 && minor >= 6));
🤖 Prompt for AI Agents
In packages/build/src/extensions/prisma.ts around lines 190 to 196, the current
version parsing uses version.split(".").map(Number) which yields NaN for range
specifiers like "^6.6.0" or "workspace:*", so the requiresSchemaFlag is
incorrectly false; update the parsing to first extract the numeric major and
minor via a regex (e.g. match the first occurrence of digits separated by a dot
like /(\d+)\.(\d+)/), convert those capture groups to numbers with safe fallback
(0) and then compute requiresSchemaFlag as major > 6 || (major === 6 && minor >=
6); this ensures --schema is included for Prisma 6.6+ even when version strings
contain ranges or non-numeric prefixes.

);
} else {
prismaDir = dirname(this._resolvedSchemaPath);
Expand Down