Skip to content

Commit aef30f5

Browse files
authored
JavaScript: setupSharedDependencies must search inside the recipe directory itself (#7515)
When a recipe is installed by local path (e.g. `mod config recipes npm install /path/to/my-recipes`), `targetModulePath` is the package directory itself. `path.dirname(targetModulePath)` jumps to the parent and the upward `node_modules` walk never enters the package's own `node_modules`, so the target package root for shared dependencies (`@openrewrite/rewrite`, `vscode-jsonrpc`, `mutative`) is never found and the host→target require.cache mapping is skipped. The downstream symptom is the dual-package problem: the recipe ends up with its own `@openrewrite/rewrite` instance, distinct from the host's, so `recipe instanceof ScanningRecipe` in `rpc/request/visit.ts` returns `false`. The runtime then skips the `scan:` phase entirely. Editors are still invoked (~3000 times per cemex run in our reproducer), but every accumulator is empty, so `UpgradeDependencyVersion` silently returns `doc` from `package.json` and no version bumps land — even though the install in the temp dir would have succeeded. When `targetModulePath` resolves to a directory, start the `node_modules` walk from the directory itself; only fall back to `path.dirname` when it resolves to a file. Repro: any local-path-installed recipe set whose `package.json` declares `@openrewrite/rewrite` as a dependency. Before this change, rpc.log shows `Could not find @openrewrite/rewrite in target's node_modules`. After, it shows `Mapped <N> modules for @openrewrite/rewrite`.
1 parent ec7cf41 commit aef30f5

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

rewrite-javascript/rewrite/src/rpc/request/install-recipes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,15 @@ function preloadCoreModules(logger?: rpc.Logger) {
197197
*/
198198
function setupSharedDependencies(targetModulePath: string, logger?: rpc.Logger) {
199199
const sharedDeps = ['@openrewrite/rewrite', 'vscode-jsonrpc', 'mutative'];
200-
const targetDir = path.dirname(targetModulePath);
200+
// For local-path installs, targetModulePath is the package dir itself.
201+
let targetDir: string;
202+
try {
203+
targetDir = fs.statSync(targetModulePath).isDirectory()
204+
? targetModulePath
205+
: path.dirname(targetModulePath);
206+
} catch {
207+
targetDir = path.dirname(targetModulePath);
208+
}
201209

202210
sharedDeps.forEach(depName => {
203211
try {

0 commit comments

Comments
 (0)