Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

Teach the Vite plugin to watch authoritative inputs and avoid self-trigger loops - #357

Closed
jkomyno wants to merge 11 commits into
tml-2276-authoritative-watch-inputsfrom
apr-vp3-02-vite-plugin-watch-behavior
Closed

jkomyno wants to merge 11 commits into
tml-2276-authoritative-watch-inputsfrom
apr-vp3-02-vite-plugin-watch-behavior

Conversation

@jkomyno

@jkomyno jkomyno commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • teach the Vite plugin to re-emit on authoritative input add and unlink events, not only change
  • treat path-based TS contract entries as module-graph roots so their transitive imports are watched too
  • mark the built-in Postgres and Mongo .ts facades with watchStrategy: "moduleGraph" and cover the new behavior in plugin/facade tests

Why

The watch-input work from PR #356 closed the PSL/config gap, but two dev-loop cases were still stale:

  • chokidar add/unlink events on authoritative inputs never scheduled re-emit
  • defineConfig({ contract: "./contract.ts" }) only watched the entry file, so helper imports could change without re-emitting

This PR closes those follow-up gaps so the Vite plugin reacts to authoritative file lifecycle events and follows TS contract module graphs rooted at declared watch inputs.

Verification

  • pnpm --filter @prisma-next/vite-plugin-contract-emit exec vitest run test/plugin.test.ts
  • pnpm --filter @prisma-next/integration-tests exec vitest run test/vite-plugin.hmr.e2e.test.ts
  • pnpm --filter @prisma-next/vite-plugin-contract-emit build
  • pnpm --filter @prisma-next/cli build
  • pnpm --filter @prisma-next/config build
  • pnpm --filter @prisma-next/sql-contract-psl build
  • pnpm --filter @prisma-next/sql-contract-ts build
  • pnpm --filter @prisma-next/postgres build
  • pnpm --filter @prisma-next/mongo-contract-psl build
  • pnpm --filter @prisma-next/mongo-contract-ts build
  • pnpm exec biome check on the touched files

Notes

  • This PR is stacked on top of PR Keep @prisma-next/config path-agnostic for contract sources #356 (tml-2276-authoritative-watch-inputs).
  • @prisma-next/postgres package-local Vitest and @prisma-next/mongo package-local build/test scripts are still blocked in this checkout by the same pre-existing workspace resolution / missing local node_modules issues seen earlier, so I verified the facade change via buildable packages and direct runtime checks instead.

@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 41406fd8-461d-40df-a44b-ba283f871394

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch apr-vp3-02-vite-plugin-watch-behavior

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Apr 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-runtime@357

@prisma-next/family-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-mongo@357

@prisma-next/sql-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-runtime@357

@prisma-next/family-sql

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-sql@357

@prisma-next/middleware-telemetry

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/middleware-telemetry@357

@prisma-next/mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo@357

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-paradedb@357

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-pgvector@357

@prisma-next/postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/postgres@357

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-orm-client@357

@prisma-next/sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sqlite@357

@prisma-next/target-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-mongo@357

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-mongo@357

@prisma-next/driver-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-mongo@357

@prisma-next/contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract@357

@prisma-next/utils

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/utils@357

@prisma-next/config

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/config@357

@prisma-next/errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/errors@357

@prisma-next/framework-components

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/framework-components@357

@prisma-next/operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/operations@357

@prisma-next/contract-authoring

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract-authoring@357

@prisma-next/ids

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ids@357

@prisma-next/psl-parser

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-parser@357

@prisma-next/psl-printer

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-printer@357

@prisma-next/cli

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/cli@357

@prisma-next/emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/emitter@357

@prisma-next/migration-tools

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/migration-tools@357

prisma-next

npm i https://pkg.pr.new/prisma/prisma-next@357

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/vite-plugin-contract-emit@357

@prisma-next/runtime-executor

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/runtime-executor@357

@prisma-next/mongo-codec

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-codec@357

@prisma-next/mongo-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract@357

@prisma-next/mongo-value

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-value@357

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-psl@357

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-ts@357

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-emitter@357

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-schema-ir@357

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-query-ast@357

@prisma-next/mongo-orm

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-orm@357

@prisma-next/mongo-pipeline-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-pipeline-builder@357

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-lowering@357

@prisma-next/mongo-wire

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-wire@357

@prisma-next/sql-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract@357

@prisma-next/sql-errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-errors@357

@prisma-next/sql-operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-operations@357

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-schema-ir@357

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-psl@357

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-ts@357

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-emitter@357

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-lane-query-builder@357

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-relational-core@357

@prisma-next/sql-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-builder@357

@prisma-next/target-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-postgres@357

@prisma-next/target-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-sqlite@357

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-postgres@357

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-sqlite@357

@prisma-next/driver-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-postgres@357

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-sqlite@357

commit: e50178e

Comment on lines +224 to +236
try {
// Load the config module and any declared module-graph roots through Vite's SSR loader
// so they appear in the module graph before we crawl their dependencies.
for (const root of moduleGraphRoots) {
try {
await viteServer.ssrLoadModule(root);
} catch (error) {
if (root === absoluteConfigPath) {
throw error;
}
log(`Skipped module-graph root after load failure: ${root}`, 'debug');
}
}

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.

This is one of those areas where I would really like to use Effect or better-result to avoid having nested try blocks.

@jkomyno
jkomyno force-pushed the apr-vp3-02-vite-plugin-watch-behavior branch from c5e478d to e50178e Compare April 20, 2026 09:14
@jkomyno
jkomyno force-pushed the tml-2276-authoritative-watch-inputs branch 2 times, most recently from 6b128c6 to 9edc5ed Compare April 21, 2026 14:05
@jkomyno jkomyno closed this Apr 21, 2026
jkomyno added a commit that referenced this pull request Apr 22, 2026
## Summary
- finalize `contract.output` in the CLI loader for plain-object configs
so the Vite plugin always receives resolved absolute paths
- make the Vite plugin consume loader-resolved inputs and emitted
artifact paths, update watched files as config/module-graph inputs
change, and warn once when it must fall back to config-only watching
- refresh plugin docs and align integration coverage with the default
output behavior

## Testing
- pnpm test -- test/plugin.test.ts
- pnpm test -- test/config-loader.test.ts
- pnpm test -- test/cli.emit-command.test.ts
test/vite-plugin.hmr.e2e.test.ts
- rg "resolve\(configDir"
packages/1-framework/3-tooling/vite-plugin-contract-emit/src/
- rg "slice\(0, -5\)"
packages/1-framework/3-tooling/vite-plugin-contract-emit/src/

## Notes
- Stacked on #356
- Replaces the older attempt in #357
- Refs TML-2277

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Contract configs now get a consistent default output path when
omitted.

* **Bug Fixes**
* More precise validation for optional contract fields; clearer errors
when modules lack expected exports.

* **Improvements**
* CLI always finalizes contract output and resolves input paths; Vite
plugin watch/emission behavior improved with fallback warnings and fewer
redundant emits.

* **Tests**
* Expanded and reorganized unit and integration tests to cover provider
shapes, path resolution, watch fallback, and emit flows.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: jkomyno <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant