Repository navigation
fix: handle pnpm deduped dependencies correctly in node module collector - #9618
Conversation
Newer pnpm versions mark deduped dependencies with `dedupedDependenciesCount` instead of including nested dependency subtrees. Fix several bugs in the dedup handling: - Use `tree.from` instead of `tree.name` for dedup lookup key, since child dependency objects don't have a `name` field in pnpm's JSON output - Skip deduped entries before calling `locatePackageVersion` to avoid wasted filesystem lookups - Add dedup skip check to optionalDependencies loop (was only in dependencies) - Remove dead `dedupedDependenciesCount: pkg?.dedupedDependenciesCount` that always evaluated to undefined and overwrote the correct spread value - Make `dedupedDependenciesCount` optional in PnpmDependency type since older pnpm versions and non-deduped entries don't have this field Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes pnpm dependency tree parsing for newer pnpm versions where deduped dependencies are represented via dedupedDependenciesCount instead of nested subtrees, ensuring the node module collector can still build a correct production dependency graph.
Changes:
- Add
dedupedDependenciesCount?: numbertoPnpmDependencyto support newer pnpm JSON output. - Resolve deduped pnpm dependency nodes by looking up the “real” dependency in
allDependenciesusingfrom/nameas the key. - Skip deduped dependency entries during dependency collection (both
dependenciesandoptionalDependencies) to avoid wasted filesystem lookups.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/app-builder-lib/src/node-module-collector/types.ts | Updates pnpm dependency typing to include optional dedupedDependenciesCount. |
| packages/app-builder-lib/src/node-module-collector/pnpmNodeModulesCollector.ts | Adds dedup handling + avoids unnecessary locatePackageVersion calls for deduped entries in both dependency loops. |
Comments suppressed due to low confidence (1)
packages/app-builder-lib/src/node-module-collector/pnpmNodeModulesCollector.ts:30
log.errorhere is using a templated string, whereas other errors in this subsystem use structured fields (e.g.,nodeModulesCollector.ts:142,traversalNodeModulesCollector.ts:116). Consider logging an object withdependencyId,depKey, andversionto make build logs easier to filter/diagnose, and keep the error message constant.
if (tree.dedupedDependenciesCount && tree.dedupedDependenciesCount > 0) {
const depKey = tree.from || tree.name
const realDep = this.allDependencies.get(`${depKey}@${tree.version}`)
if (realDep) {
tree = realDep
} else {
log.error(`Could not find real dependency for ${depKey}@${tree.version}`)
return
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mmaietta
left a comment
There was a problem hiding this comment.
Thank you @beyondkmp for putting this together!
🦋 Changeset detectedLatest commit: 0aec8dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
diogotcorreia
left a comment
There was a problem hiding this comment.
Small nitpick, feel free to ignore
Co-authored-by: Diogo Correia <[email protected]>
fix #9603
Newer pnpm versions mark deduped dependencies with
dedupedDependenciesCountinstead of including nested dependency subtrees. Fix several bugs in the dedup handling:tree.frominstead oftree.namefor dedup lookup key, since child dependency objects don't have anamefield in pnpm's JSON outputlocatePackageVersionto avoid wasted filesystem lookupsdedupedDependenciesCount: pkg?.dedupedDependenciesCountthat always evaluated to undefined and overwrote the correct spread valuededupedDependenciesCountoptional in PnpmDependency type since older pnpm versions and non-deduped entries don't have this field