-
Notifications
You must be signed in to change notification settings - Fork 6
Fix pnpm compatibility by replacing build-time path manipulation with runtime detection #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… with runtime detection - Remove brittle replace-in-file build step that broke with pnpm's symlinked structure - Implement dynamic project root detection using first /node_modules/ split - Add runtime module discovery for convex directory scanning - Maintain backward compatibility with user-provided modules parameter 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
ianmacartney
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for putting this up! I agree the hardcoded lookup is so brittle & confusing for folks. hopefully this can be a big jump forward for pnpm users as well as other custom function location users
| function findConvexFiles( | ||
| projectRoot: string, | ||
| ): Record<string, () => Promise<any>> { | ||
| const convexDir = join(projectRoot, "convex"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally, we could also see if there's a convex.json in the project root that has a functions path, which is used to point to custom function locations.
| : "If your Convex functions aren't defined in a directory " + | ||
| 'called "convex" sibling to your node_modules, ' + | ||
| "provide the second argument to `convexTest`"), | ||
| : "convex-test automatically detected your project root and convex directory. " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could say where we tried to find them (show the project root path e.g.)
| "provide the second argument to `convexTest`"), | ||
| : "convex-test automatically detected your project root and convex directory. " + | ||
| "If your Convex functions are in a non-standard location, " + | ||
| "provide the modules parameter to `convexTest` with your custom `import.meta.glob` pattern."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit: |
Summary
Fixes pnpm compatibility by replacing brittle build-time string replacement with robust runtime path detection. This allows
convex-testto work seamlessly with pnpm's symlinked node_modules structure.Problem
The current build process uses
replace-in-fileto change"./convex/**/*.*s"to"../../../convex/**/*.*s"in the compiled JavaScript. This hardcoded path assumes npm's nested node_modules structure but breaks with pnpm's unique layout:npm/yarn structure:
pnpm structure:
Pnpm is also stricter on peer dependency resolution. Although we import vitest, the import meta URL and import meta glob APIs are from Vite's core library, which weren't present when installing worked with pnpm. The first commit fixes this.
Solution
Replaced build-time path manipulation with runtime path detection:
Removed brittle dependencies:
replace-in-filebuild step and dependencyAdded dynamic project root detection:
Implemented runtime module discovery:
Key Changes
findProjectRoot(): Detects project root by splitting on first/node_modules/findConvexFiles(): Recursively scans convex directory at runtimemoduleCache(): Uses runtime detection instead of staticimport.meta.globtsccompilation without string replacementTesting
To test this locally, I:
convexTestand PNPM.convex-testfrom my local branch and used that tarball as the source in my problematic PNPM project, and saw that the tests now pass.Benefits
process.cwd()if path detection fails🤖 Generated with Claude Code
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.