fix(migrate,cli): import from @prisma/internals's public entry, not its src/ - #29836
Conversation
…ts src/ Several tab-completion files (added in prisma#28351) imported types and values from @prisma/internals/src/..., a source path that only resolves inside the monorepo via workspace symlinks. The published @prisma/internals package ships dist/, not src/, so requiring @prisma/migrate (or @prisma/cli) from an installed node_modules threw MODULE_NOT_FOUND before any of their APIs could be used. @prisma/internals's public entry already re-exports every value and type these files need, so this switches all of them to import from '@prisma/internals' directly, matching how the rest of the codebase already imports from that package. Closes prisma#29772
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (27)
📝 WalkthroughWalkthroughCLI and migrate completion modules now import Prisma internals types and constants through the public ChangesPublic internals imports
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
aqrln
left a comment
There was a problem hiding this comment.
whoops, I'm surprised this even built with the production tsconfig.build.json at all, thanks so much
…ew ones (#29842) Follow-up to #29836, which fixed the deep `@prisma/internals/src/...` imports that made `@prisma/migrate` 7.9.0 unloadable (#29772). ## The remaining instance `packages/cli/src/completions/completion-definitions.ts` still reached into `@prisma/migrate/src/commands/*` — twelve imports of the same shape. This one never reached a published artifact, because the CLI bundles migrate rather than requiring it (`packages/cli/build` contains no `require("@prisma/migrate")`), but it was the last instance in code that ships. All twelve symbols are already re-exported from `packages/migrate/src/index.ts`, and `tsconfig.build.bundle.json` maps `@prisma/migrate` to `packages/migrate/src`, so the bundler resolves the same module graph either way. Measured A/B on an identical base: | | before | after | |-|-|-| | `build/completion.js` | 55,184 B | 55,187 B | | `build/cli.js` | 2,744,937 B | 2,744,948 B | | `prisma complete -- migrate d` | ~53 ms | ~53 ms | `build/completion.js` is a separate, deliberately small esbuild entry, so I checked this before assuming the deep imports were merely untidy rather than load-bearing for tab-completion startup. They are not — esbuild tree-shakes migrate's entry down to the same result. ## The guard A `no-restricted-imports` pattern for `@prisma/*/src/**`, so the next one is caught at lint time rather than by a user on npm. Verified against the pre-fix file: it flags all fourteen imports that constituted the incident. Two exemptions: - **Tests** (`*.test.ts`, `*.vitest.ts`, `__tests__/`, `tests/`) — never published, and nine of them import `@prisma/get-platform/src/test-utils/*` for helpers the package entry does not export. - **`@prisma/*-wasm`** — wasm-pack output, published to npm with `src/` intact, so a deep import there resolves fine and the rule's rationale does not apply. Without this the message would give actively wrong advice for those packages. The rule covers import declarations only, so `require.resolve` and jest config strings are untouched: the Wasm asset lookup in `packages/cli/helpers/build.ts` and the snapshot-serializer paths in the jest presets keep working. ## Verification - `pnpm lint` across the repo: exit 0. - Rule fires on the pre-fix `completion-definitions.ts` (14 errors), stays silent on a test file with the same import, and stays silent on `@prisma/prisma-schema-wasm/src/...`. - `pnpm --filter prisma tsc`: clean. `pnpm --filter prisma test completion`: 5/5. - Rebuilt `@prisma/migrate` and `prisma` from scratch: no `@prisma/*/src/*` anywhere in the output, `require` of migrate returns 31 exports, and `prisma complete -- migrate d` gives the same three suggestions as before. ## Scope One import statement, one lint rule, one line of `AGENTS.md`. No behaviour changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved command completion reliability by updating migration command integrations. * **Documentation** * Added guidance for using supported package entry points instead of internal source paths. * **Chores** * Added linting checks to prevent unsupported internal imports, with appropriate exceptions for tests and specific tooling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ts src/ (prisma#29836) ## Description `@prisma/migrate` 7.9.0 fails immediately on `require`/`import` with `MODULE_NOT_FOUND`, before any of its APIs can be used: ``` Error: Cannot find module '@prisma/internals/src/cli/completion-values' Require stack: - node_modules/@prisma/migrate/dist/chunk-WA2SOLDQ.js - node_modules/@prisma/migrate/dist/index.js ``` The tab-completion files added in prisma#28351 (`*-completion.ts` in `packages/migrate` and `packages/cli`, plus a couple of related command files) import types and values from deep `@prisma/internals/src/...` paths — source paths that only resolve inside the monorepo via workspace symlinks. The published `@prisma/internals` package ships `dist/`, not `src/`, so this breaks as soon as `@prisma/migrate`/`@prisma/cli` are installed from npm as independent packages, which is exactly what the published `prisma` CLI does. I found this affects 4 distinct deep-import paths across 27 files, not just the one path in the original report: - `@prisma/internals/src/cli/completion-values` - `@prisma/internals/src/cli/types` - `@prisma/internals/src/cli/utils` - `@prisma/internals/src/cli/Help` - `@prisma/internals/src/utils/validatePrismaConfigWithDatasource` All of these are already re-exported from `@prisma/internals`'s public entry (`packages/internals/src/index.ts`), so this switches every occurrence to import from `'@prisma/internals'` directly — matching how the rest of the codebase already imports from that package (e.g. `DbCommand.ts`, `Format.ts`). Closes prisma#29772 ## Test plan - Reproduced the exact failure from the issue: built `packages/migrate` and confirmed `require('./dist/index.js')` failed with `MODULE_NOT_FOUND` before the fix, and loads successfully (31 exports) after it. - `pnpm run test completion` in `packages/cli` — 5/5 passing. - `pnpm run test DbCommand MigrateCommand` in `packages/migrate` — 8/8 passing. - `eslint` on all changed files — no errors (some files ended up with the value and type imports as two separate `import`/`import type` statements from `@prisma/internals`, which `eslint --fix` normalizes and the project's lint config accepts). - Confirmed via `grep` that no `@prisma/internals/src/...` import remains anywhere in the codebase. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Standardized CLI completion and migration command imports through the public internals package interface. * Preserved all existing command options, completion definitions, and runtime behavior. * **Compatibility** * Improved resilience to internal module structure changes without altering the command-line experience. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ew ones (prisma#29842) Follow-up to prisma#29836, which fixed the deep `@prisma/internals/src/...` imports that made `@prisma/migrate` 7.9.0 unloadable (prisma#29772). ## The remaining instance `packages/cli/src/completions/completion-definitions.ts` still reached into `@prisma/migrate/src/commands/*` — twelve imports of the same shape. This one never reached a published artifact, because the CLI bundles migrate rather than requiring it (`packages/cli/build` contains no `require("@prisma/migrate")`), but it was the last instance in code that ships. All twelve symbols are already re-exported from `packages/migrate/src/index.ts`, and `tsconfig.build.bundle.json` maps `@prisma/migrate` to `packages/migrate/src`, so the bundler resolves the same module graph either way. Measured A/B on an identical base: | | before | after | |-|-|-| | `build/completion.js` | 55,184 B | 55,187 B | | `build/cli.js` | 2,744,937 B | 2,744,948 B | | `prisma complete -- migrate d` | ~53 ms | ~53 ms | `build/completion.js` is a separate, deliberately small esbuild entry, so I checked this before assuming the deep imports were merely untidy rather than load-bearing for tab-completion startup. They are not — esbuild tree-shakes migrate's entry down to the same result. ## The guard A `no-restricted-imports` pattern for `@prisma/*/src/**`, so the next one is caught at lint time rather than by a user on npm. Verified against the pre-fix file: it flags all fourteen imports that constituted the incident. Two exemptions: - **Tests** (`*.test.ts`, `*.vitest.ts`, `__tests__/`, `tests/`) — never published, and nine of them import `@prisma/get-platform/src/test-utils/*` for helpers the package entry does not export. - **`@prisma/*-wasm`** — wasm-pack output, published to npm with `src/` intact, so a deep import there resolves fine and the rule's rationale does not apply. Without this the message would give actively wrong advice for those packages. The rule covers import declarations only, so `require.resolve` and jest config strings are untouched: the Wasm asset lookup in `packages/cli/helpers/build.ts` and the snapshot-serializer paths in the jest presets keep working. ## Verification - `pnpm lint` across the repo: exit 0. - Rule fires on the pre-fix `completion-definitions.ts` (14 errors), stays silent on a test file with the same import, and stays silent on `@prisma/prisma-schema-wasm/src/...`. - `pnpm --filter prisma tsc`: clean. `pnpm --filter prisma test completion`: 5/5. - Rebuilt `@prisma/migrate` and `prisma` from scratch: no `@prisma/*/src/*` anywhere in the output, `require` of migrate returns 31 exports, and `prisma complete -- migrate d` gives the same three suggestions as before. ## Scope One import statement, one lint rule, one line of `AGENTS.md`. No behaviour changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved command completion reliability by updating migration command integrations. * **Documentation** * Added guidance for using supported package entry points instead of internal source paths. * **Chores** * Added linting checks to prevent unsupported internal imports, with appropriate exceptions for tests and specific tooling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Description
@prisma/migrate7.9.0 fails immediately onrequire/importwithMODULE_NOT_FOUND, before any of its APIs can be used:The tab-completion files added in #28351 (
*-completion.tsinpackages/migrateandpackages/cli, plus a couple of related command files) import types and values from deep@prisma/internals/src/...paths — source paths that only resolve inside the monorepo via workspace symlinks. The published@prisma/internalspackage shipsdist/, notsrc/, so this breaks as soon as@prisma/migrate/@prisma/cliare installed from npm as independent packages, which is exactly what the publishedprismaCLI does.I found this affects 4 distinct deep-import paths across 27 files, not just the one path in the original report:
@prisma/internals/src/cli/completion-values@prisma/internals/src/cli/types@prisma/internals/src/cli/utils@prisma/internals/src/cli/Help@prisma/internals/src/utils/validatePrismaConfigWithDatasourceAll of these are already re-exported from
@prisma/internals's public entry (packages/internals/src/index.ts), so this switches every occurrence to import from'@prisma/internals'directly — matching how the rest of the codebase already imports from that package (e.g.DbCommand.ts,Format.ts).Closes #29772
Test plan
packages/migrateand confirmedrequire('./dist/index.js')failed withMODULE_NOT_FOUNDbefore the fix, and loads successfully (31 exports) after it.pnpm run test completioninpackages/cli— 5/5 passing.pnpm run test DbCommand MigrateCommandinpackages/migrate— 8/8 passing.eslinton all changed files — no errors (some files ended up with the value and type imports as two separateimport/import typestatements from@prisma/internals, whicheslint --fixnormalizes and the project's lint config accepts).grepthat no@prisma/internals/src/...import remains anywhere in the codebase.Summary by CodeRabbit