fix(function): resolve nodePaths under an isolated store - #875
Merged
Conversation
`nodePaths` tells isolated-function which dependencies a snippet requires are already on disk, so it can skip installing them. It was derived by walking two levels up from `@cloudflare/puppeteer`, which lands on the consumer's `node_modules` only under a flat install. With pnpm it lands inside `node_modules/.pnpm/@cloudflare+puppeteer@1.2.0/node_modules`, which holds that package's own dependencies and nothing else: entries: @cloudflare @puppeteer debug devtools-protocol ws So the check never matched and every snippet paid a full install of a package already present — measured at ~400ms per cold compile, three rounds, consistent. `module.paths` is the resolution chain Node itself would use from this file, so it reaches the consumer under either layout. The original entry is kept ahead of it, leaving a flat install byte-identical. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YKVuh1R8HtB7SX7eKa7UsJ
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesDependency resolution
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2 tasks
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.
Problem
nodePathstellsisolated-functionwhich dependencies a snippet requires are already on disk, so it can skip installing them (compile/index.js→dependenciesfilter).It was derived by walking two levels up from
@cloudflare/puppeteer:That lands on the consumer's
node_modulesonly under a flat (npm/yarn) install. Under pnpm it lands inside the isolated store:which holds that package's own dependencies and nothing else. The check never matches, so every snippet installs a package that is already present.
Measured
Compiling a snippet that requires
cheerio, clean tmpdir each round:This repo installs with pnpm, so it is hitting this too — the existing
interact with npm modulestest reinstallslodash, a devDependency of this package, on every run.Fix
module.pathsis the resolution chain Node itself would use from this file, so it reaches the consumer under either layout. The original entry is kept ahead of it, which leaves a flat install byte-identical.Test
a dependency already present is not installed againassertsprofiling.phases.install === 0for a snippet requiringlodash.420.096458vs expected0— failspackages/functionsuite: 36 passedNote
Low Risk
Localized change to how install skip paths are computed; no auth, security, or API surface changes.
Overview
Fixes redundant npm installs when user snippets
require()packages that are already on disk under pnpm (and keeps flat npm/yarn behavior unchanged).nodePathspassed toisolated-functionis expanded from a single path (two levels up from@cloudflare/puppeteer) to a deduped list that still leads with that path and also includesmodule.paths, so dependency checks reach the consumer’snode_modulesinstead of stopping inside pnpm’s isolated store.Adds a test that a snippet requiring
lodash(already a devDependency) reportsprofiling.phases.install === 0.Reviewed by Cursor Bugbot for commit dbdeb20. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit