Skip to content

fix(api-server): ignore Prisma generator output in dev watcher#1780

Draft
bellcoTech wants to merge 1 commit into
cedarjs:mainfrom
bellcoTech:fix-watch-ignore-prisma-output-no-test
Draft

fix(api-server): ignore Prisma generator output in dev watcher#1780
bellcoTech wants to merge 1 commit into
cedarjs:mainfrom
bellcoTech:fix-watch-ignore-prisma-output-no-test

Conversation

@bellcoTech
Copy link
Copy Markdown
Contributor

The dev watcher already ignores the directory containing schema.prisma (api/db by default), but if a project configures the generator output to point outside that directory — e.g. output = "../src/lib/db/generated" — the watcher sees every regenerated file and schedules another rebuild, trapping the dev server in an infinite build loop.

Resolves the generator output path from the Prisma config and appends it to chokidar's ignore list. When the output is undeclared or schema parsing fails, falls back to the existing behavior.

The dev watcher already ignores the directory containing schema.prisma
(api/db by default), but if a project configures the generator output
to point outside that directory — e.g. output = "../src/lib/db/generated"
— the watcher sees every regenerated file and schedules another rebuild,
trapping the dev server in an infinite build loop.

Resolves the generator output path from the Prisma config and appends
it to chokidar's ignore list. When the output is undeclared or schema
parsing fails, falls back to the existing behavior.
@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2026

👷 Deploy request for cedarjs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7d17ec9

@github-actions github-actions Bot added this to the next-release-patch milestone May 14, 2026
@bellcoTech
Copy link
Copy Markdown
Contributor Author

@Tobbe
Totally up to you whether to take this — happy if you'd rather close
it.

Hit this during a 4.1 → 4.2 upgrade where my project still had the
older Prisma layout (output = "../src/lib/db/generated"). Dev server
went into an infinite build loop — prisma generate writes →
chokidar fires → rebuild → prisma generate writes again. Took me a
while to spot.

Fixed it for myself by moving the output to api/db/generated to
match the 4.2 template, so I'm unblocked. Nothing's broken on the
happy path — anyone following the current docs / new template is
fine.

Just thought it'd be a nice safety net for anyone else upgrading from
the older layout, or for folks who legitimately want the output
somewhere custom (TS path aliases, sharing across workspaces, etc.).
Defensive ignore, costs nothing if the output is inside dbDir
already.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR fixes an infinite rebuild loop in cedar dev that occurs when a project configures the Prisma generator output to a directory outside the default schema directory (api/db). Chokidar was watching those generated files and triggering rebuilds that re-generated those same files.

  • Adds a new getPrismaGeneratorOutputPath export in project-config/src/prisma.ts backed by two private helpers (getPrismaClientGenerator, resolveGeneratorOutputPath) that eliminate the duplication that existed in the previous resolveGeneratedPrismaClient implementation.
  • In api-server/src/watchPaths.ts, apiIgnorePaths now resolves the generator output directory and appends it to the chokidar ignore list, falling back gracefully (no entry added) when the schema cannot be parsed.

Confidence Score: 5/5

Safe to merge — the change is additive, falls back gracefully when the schema is unreadable, and mirrors the existing pattern used for dbDir.

Both changed files follow the established patterns in the codebase. The new getPrismaClientGenerator helper silently swallows errors just as the original resolveGeneratedPrismaClient did, undefined is returned when output is unset (preserving the previous ignore-list behavior), and the path resolution uses the same path.isAbsolute / path.resolve approach already used elsewhere. The refactor also fixes the duplication that was flagged in the prior review thread.

No files require special attention.

Important Files Changed

Filename Overview
packages/project-config/src/prisma.ts Extracts shared generator-lookup logic into private getPrismaClientGenerator and resolveGeneratorOutputPath helpers, adds public getPrismaGeneratorOutputPath, and refactors resolveGeneratedPrismaClient to use them — eliminating prior duplication cleanly.
packages/api-server/src/watchPaths.ts Imports and calls getPrismaGeneratorOutputPath in apiIgnorePaths, appending the resolved path to chokidar's ignore list only when a non-default output is configured — consistent with how dbDir is handled.

Reviews (2): Last reviewed commit: "fix(api-server): ignore Prisma generator..." | Re-trigger Greptile

Comment on lines +163 to +190
* Resolves the absolute path the Prisma client generator writes to.
* Returns `undefined` if the schema or generator can't be read.
*/
export async function getPrismaGeneratorOutputPath(): Promise<
string | undefined
> {
try {
const prismaInternalsMod = await import('@prisma/internals')
const { getConfig } = prismaInternalsMod.default || prismaInternalsMod

const { schemas, schemaRootDir } = await getPrismaSchemas()
const config = await getConfig({ datamodel: schemas })
const generator =
config.generators.find((entry) => entry.name === 'client') ??
config.generators[0]
const output = generator?.output?.value

if (!output) {
return undefined
}

return path.isAbsolute(output)
? output
: path.resolve(schemaRootDir, output)
} catch {
return undefined
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Duplicated generator-path resolution logic

getPrismaGeneratorOutputPath performs the same @prisma/internals import, getPrismaSchemas() call, getConfig invocation, generator lookup, and path.resolve that already exists verbatim in resolveGeneratedPrismaClient (lines 196–222). If the resolution logic ever changes — e.g. different generator-name heuristics or a new schemaRootDir lookup — both functions will need the same update and it's easy to miss one. Consider refactoring resolveGeneratedPrismaClient to call getPrismaGeneratorOutputPath() and layer its extra ext / existence-checking logic on top.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looking at this now

Copy link
Copy Markdown
Contributor Author

@bellcoTech bellcoTech May 14, 2026

Choose a reason for hiding this comment

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

Agreed, but to combine needs to affect more internal code. This PR may not even go in - not worth rewriting a lot for a potential non-issue

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 14, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 7d17ec9

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ❌ Failed 3m 25s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 2s View ↗
nx run-many -t build ✅ Succeeded 2s View ↗
nx run-many -t test:types ✅ Succeeded 11s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-14 13:57:07 UTC

@bellcoTech bellcoTech marked this pull request as draft May 14, 2026 13:37
@bellcoTech bellcoTech force-pushed the fix-watch-ignore-prisma-output-no-test branch from 7b30458 to 7d17ec9 Compare May 14, 2026 13:37
@Tobbe
Copy link
Copy Markdown
Member

Tobbe commented May 14, 2026

I have a plan for related work here: https://github.com/cedarjs/cedar/blob/main/docs/implementation-plans/unified-prisma-db-module-plan.md

So your reported issue is definitely something I want to fix :)

@bellcoTech
Copy link
Copy Markdown
Contributor Author

Oh haha, Ok I was very unsure about this one but this makes more sense. I didn't see the doc. Happy to close and leave it with you if you'd like

@Tobbe
Copy link
Copy Markdown
Member

Tobbe commented May 14, 2026

Oh haha, Ok I was very unsure about this one but this makes more sense. I didn't see the doc. Happy to close and leave it with you if you'd like

Leave it open for now. I'll take a closer look later and get back to you with how I want to handle this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants