Repository navigation
fix(cli): CLI.SECOND_PACKAGE_COPY gives the bin path of the project's prisma unless it is installed in the current folder - #424
Merged
Conversation
… bin path when the package manager's runner would run another one From a folder with no package.json inside a pnpm workspace package, the advice `pnpm exec prisma ...` ran the workspace root's prisma and was refused again. pnpm 10 looks only in the current directory's node_modules/.bin and then the workspace root's; pnpm 11 needs a package.json in the current directory. The runner form is now given only when the project's prisma is installed in the current directory and that directory has a package.json; otherwise the advice is the bin's path from the current directory, such as `../../node_modules/.bin/prisma contract emit`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
…ere it found prisma On Windows the advised bin path is written with backslashes and left unquoted (`..\..\node_modules\.bin\prisma`), which cmd.exe and PowerShell both run; it holds only `.`, `..`, `node_modules`, `.bin` and `prisma`, so it never needs quoting. The platform comes from the host process, so both forms are tested on any host. The project-package finder now returns the node_modules folder it found the package in, and both the runner decision and the bin path are derived from it. Tried with pnpm 10.27 in a workspace: from a folder with a package.json and no prisma, `pnpm exec prisma` ran the workspace root's prisma; from a folder with node_modules but no package.json it failed with ERR_PNPM_RECURSIVE_EXEC_NO_PACKAGE. The earlier commit called that pnpm 11; it was 10.27, and the claim is gone from the error reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What the user sees
prismarefuses an ORM or Composer command withCLI.SECOND_PACKAGE_COPYwhen theprismayou ran would load a different copy of the ORM packages than your project's own. The refusal is right: values made by one copy are rejected by the other. Its advice is to run the project's ownprismainstead. In one case that advice did not work.In prisma/pdp-control-plane, a pnpm monorepo, a user ran the workspace root's
prisma contract emitinservices/control-plane/scripts/usage-testing/. That folder has nopackage.json. The project's ownprismathere isservices/control-plane/node_modules/prisma, two folders up:On Windows the path is
..\..\node_modules\.bin\prisma, which cmd.exe and PowerShell both run.Why
The error finds the project's
prismathe way Node does: it walks up from the current folder to the nearestnode_modules/prisma. The advice then ranprismathrough the package manager (pnpm exec,npx --no-install,yarn exec,bunx --no-install), and the package managers do not all look in the same place:node_modules/.binand then the workspace root's, skipping the folders between. So it ran the root'sprisma.node_modulesbut nopackage.json.package.json, which usually finds the right one. Yarn was not tried.A path to the bin runs the right
prismawith every package manager. The runner form runs it with every package manager only when the project'sprismais installed in the current folder and that folder has apackage.json. So the advice now uses the runner form only in that case, and the path otherwise. That gives npm and Bun users a path in some folders where their runner would also have worked. We accept that: the advice must work wherever it is given, and the error cannot tell which runner's search the user's version does.What changes
packages/cli/src/second-copy.ts: the rule above. The advice keeps any--configthe user gave. The platform is passed in, so the tests check both path forms on any machine.packages/cli/src/lib/package-copies.ts: the finder also returns thenode_modulesfolder it foundprismain. The bin path is built from that folder as found, not from the package's real path, because under pnpm the real path is insidenode_modules/.pnpm, which has no.bin.docs/reference/error-reference.md: theCLI.SECOND_PACKAGE_COPYentry states the rule. It also corrects two runners it named wrongly (yarn runandbun run; the code usesyarn execandbunx --no-install).How it was checked
tests/second-copy.test.tscover the incident's layout,--config, aprismain a folder with nopackage.json, apackage.jsonwithprismaonly further up, and the Windows form. Removing either condition of the rule fails a test.tests/second-copy.test.tsandtests/package-copies.test.tspass. Typecheck and lint are clean.Alternatives considered
pnpm exec prismais the form users know, and it reads the same on every system.pnpm --filter <package> exec). Rejected: the folder may belong to no package, as in the incident, and each package manager needs its own form.Agent: cobain-55
🤖 Generated with Claude Code