fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r#10705
Merged
fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r#10705
pkgSnapshot in pnpm why -r#10705Conversation
0b51a64 to
bd7959a
Compare
Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during invokation of pkgSnapshotToResolution. This commit wraps resolution and integrity steps with if (pkgSnapshot). Also, added unit test for the same. Fixes pnpm#10700
bd7959a to
c51eb8b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a TypeError crash in pnpm why -r when pkgSnapshot is undefined during the resolution process. The issue occurred because the code attempted to access properties of an undefined pkgSnapshot object without proper null checking.
Changes:
- Added a null check to wrap the resolution and integrity extraction code when
pkgSnapshotmight be undefined - Added a unit test to verify the fix handles missing package snapshots without crashing
- Added a changeset documenting the fix
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| reviewing/dependencies-hierarchy/src/getPkgInfo.ts | Added conditional check to prevent accessing undefined pkgSnapshot properties |
| reviewing/dependencies-hierarchy/test/getPkgInfo.test.ts | Added test case for handling missing package snapshots |
| .changeset/famous-cloths-press.md | Added changeset entry for the patch fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| optional = pkgSnapshot.optional | ||
| if ('integrity' in pkgSnapshot.resolution) { | ||
| integrity = pkgSnapshot.resolution.integrity as string | ||
| if (pkgSnapshot){ |
There was a problem hiding this comment.
Missing space before opening brace. The codebase consistently uses if (pkgSnapshot) { with a space before the brace. This should be if (pkgSnapshot) { instead of if (pkgSnapshot){.
Suggested change
| if (pkgSnapshot){ | |
| if (pkgSnapshot) { |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
zkochan
approved these changes
Feb 27, 2026
pkgSnapshot in pnpm why -r
|
Congrats on merging your first pull request! 🎉🎉🎉 |
zkochan
added a commit
that referenced
this pull request
Mar 7, 2026
…why -r` (#10705) * fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during invokation of pkgSnapshotToResolution. This commit wraps resolution and integrity steps with if (pkgSnapshot). Also, added unit test for the same. close #10700 * fix: handle undefined pkgSnapshot in pnpm why -r * Apply suggestions from code review #10700 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Zoltan Kochan <z@kochan.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
zkochan
added a commit
that referenced
this pull request
Mar 7, 2026
…why -r` (#10705) * fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during invokation of pkgSnapshotToResolution. This commit wraps resolution and integrity steps with if (pkgSnapshot). Also, added unit test for the same. close #10700 * fix: handle undefined pkgSnapshot in pnpm why -r * Apply suggestions from code review #10700 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Zoltan Kochan <z@kochan.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during invokation of pkgSnapshotToResolution.
This PR wraps resolution and integrity steps with if (pkgSnapshot). Also, added unit test for the same.
Fixes #10700