Skip to content

fix(cli): propagate resolve hook to the alchemy converge child - #244

Draft
kristof-siket wants to merge 2 commits into
mainfrom
fix/cli-resolve-hook-in-converge
Draft

fix(cli): propagate resolve hook to the alchemy converge child#244
kristof-siket wants to merge 2 commits into
mainfrom
fix/cli-resolve-hook-in-converge

Conversation

@kristof-siket

Copy link
Copy Markdown
Contributor

What broke and why

When prisma-composer deploy runs under Node, the CLI registers a synchronous resolve hook (node:module registerHooks) so that .js-extension and extensionless specifiers resolve to .ts source files. That hook applies only to the CLI's own process.

run-alchemy.ts then spawns the workspace's installed alchemy bin as a separate Node child process. That child has no hook, so imports like:

import svc from "./service.js";  // only service.ts exists

fail with ERR_MODULE_NOT_FOUND inside the generated alchemy.run.ts stack file.

Repro: https://github.com/kristof-siket/next-stock/actions/runs/32148447586

Fix

Build src/register-entry-resolution.ts as a standalone entry (dist/register-entry-resolution.mjs) in both @internal/cli and @prisma/composer-cli. The module's only job is to call registerEntryResolution() at import time.

Pass it to the converge child via NODE_OPTIONS=--import=<file:// URL> in the spawn environment, appending to any existing NODE_OPTIONS value. Under Bun the env addition is skipped — Bun resolves .js.ts natively.

The URL is derived from import.meta.url of the running bundle, so it resolves to the correct file whether the CLI is run from @internal/cli/dist/ or @prisma/composer-cli/dist/.

Tests added

  • childNodeOptions() unit tests — exercise the Node path (no NODE_OPTIONS, existing NODE_OPTIONS preserved) and the Bun path (returns undefined), using the explicit isBunRuntime parameter so the suite works regardless of which runtime runs it.
  • Real-Node proof — spawns node --import=<register module> <driver> where the driver dynamically imports a fixture that uses ./js-ext-service.js (only .ts exists). Asserts exit 0. A paired test without --import asserts exit 1 with the module-not-found error, confirming the hook is what makes it work.

Checklist

  • pnpm --filter @internal/cli typecheck — clean
  • pnpm --filter @internal/cli test — 251 pass
  • pnpm --filter @internal/cli build — produces dist/register-entry-resolution.mjs
  • pnpm --filter @prisma/composer-cli build — produces dist/register-entry-resolution.mjs
  • pnpm lint — no errors

The resolve hook registered by `entry-resolution.ts` only applied inside
the CLI's own process. When `run-alchemy.ts` spawns the alchemy converge
child (a separate Node process), the child had no hook, so `.js`-extension
imports inside the user's entry graph failed with ERR_MODULE_NOT_FOUND.

Fix: ship `register-entry-resolution.ts` as a standalone dist entry
(`dist/register-entry-resolution.mjs`) in both `@internal/cli` and
`@prisma/composer-cli`. Inject it into the converge child via
`NODE_OPTIONS=--import=<file:// URL>` in the spawn env, appending to any
existing `NODE_OPTIONS` value. Under Bun the env addition is skipped —
Bun resolves `.js` → `.ts` natively without a hook.

Closes: repro at https://github.com/kristof-siket/next-stock/actions/runs/32148447586

Signed-off-by: Kristof Siket <siket@prisma.io>
…ge child

Signed-off-by: Kristof Siket <siket@prisma.io>
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a36ab1bc-0624-4593-a367-9ee568a4fbf8

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

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

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.

1 participant