JavaScript: setupSharedDependencies must search inside recipe directory itself#7515
Merged
Jenson3210 merged 1 commit intomainfrom Apr 29, 2026
Merged
Conversation
…ectory itself 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`.
42137ba to
47b6516
Compare
greg-at-moderne
approved these changes
Apr 29, 2026
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.
Why
Recipe authoring loop: edit, register the local path with
mod config recipes npm install /path/to/my-recipes, run against a fixture before publishing.Today this silently no-ops on
package.jsonfor anyScanningRecipe(UpgradeDependencyVersion,AddDependency, etc.).setupSharedDependenciesdoespath.dirname(targetModulePath), which for a directory path jumps to the parent — the upwardnode_moduleswalk never enters the recipe's ownnode_modules. The host→targetrequire.cachemapping is skipped, the recipe loads its own@openrewrite/rewriteinstance,recipe instanceof ScanningRecipereturns false invisit.ts, and thescan:phase is skipped. Editor still fires, butacc.projectsToUpdateis always empty.npm install <pkg@version>is unaffected becauserequire.resolvereturns a file path, and dirname/walk-up lands on the install dir's hoistednode_modules.Fix
When
targetModulePathis a directory, start the walk from the directory itself.Test plan
vitest run— 1821/1821 passUpgradeTo18now bumpspackage.jsonend-to-end. rpc.log changes fromCould not find @openrewrite/rewrite in target's node_modulestoMapped 132 modules for @openrewrite/rewrite.