Fix pnpm compatibility by replacing build-time path manipulation with runtime detection #49
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.
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.