postgres({ config }) resolves from the working directory, but the guide says relative to the module file

Open
#469 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend, databases

Research direction

Read packages/1-prisma-cloud/1-extensions/target/src/orm-postgres.ts, then trace how config reaches resolveOrmConfig in packages/1-prisma-cloud/1-extensions/target/src/descriptors/orm-postgres.ts and loadConfig in packages/1-prisma-cloud/1-extensions/target/src/orm-config.ts. Compare that path handling with the guide and ADR-0004; the issue is resolved when module-relative behavior matches the documented rule or the guide is corrected. The report was inferred from source and was not reproduced.

Written by the indexing model from the issue text.

Description

Composer 0.40.0, prisma/orm 8.0.0-rc.25.

Inferred from source at v0.40.0; not reproduced.

  • The guide promises module-relative resolution: docs/guides/building-an-app.md lines 240-243, "naming the prisma.config.ts path (relative to the module file) so the deploy can reload the emitted contract.json and find migrations/". ADR-0004 ("paths resolve relative to the authoring file") states the same rule for authoring paths in general.
  • The code does not: PostgresResourceNode keeps config as given (packages/1-prisma-cloud/1-extensions/target/src/orm-postgres.ts). The lowering passes it unchanged, resolveOrmConfig(node.config) (packages/1-prisma-cloud/1-extensions/target/src/descriptors/orm-postgres.ts line 43), which calls loadConfig(configPath) with no cwd (packages/1-prisma-cloud/1-extensions/target/src/orm-config.ts line 51). The ORM resolves a relative path against process.cwd(): const cwd = options?.cwd ?? process.cwd(); const resolvedConfigPath = configPath ? resolve(cwd, configPath) : undefined; (prisma/orm v8.0.0-rc.25, packages/1-framework/3-tooling/config-loader/src/load.ts lines 276-277). prisma dev and prisma deploy converge with the working directory set to where the command ran (packages/0-framework/3-tooling/cli/src/operations/execute-dev.ts line 305, the DEV.WORKER_THREAD explanation; packages/0-framework/3-tooling/cli/src/converge-process.ts).
  • Composer's own nested example steps around it: examples/store/modules/catalog/src/module.ts line 20 builds an absolute path, const config = fileURLToPath(new URL('../prisma.config.ts', import.meta.url));.
  • Effect: a module in a subdirectory that passes config: './prisma.config.ts', meaning the file beside the module as the guide says, gets the prisma.config.ts in the directory the command runs from instead. A root module.ts beside prisma.config.ts, run from that directory, works under both readings.
  • Expected: config resolves relative to the file that calls postgres(), as the guide and ADR-0004 say, or the guide says otherwise.

Found while writing the Composer docs on prisma.io (prisma/web#8965). The docs do not work around this.

Dominant language
TypeScript
Stars
6
Forks
2
Avg merge
1d 2h
Merged PRs (30d)
33

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/composer

All issues in prisma/composer

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.