ISSUE DESCRIPTION False positives for pnpm package source aliases What happened? fallow…
- User
ISSUE DESCRIPTION
False positives for pnpm package source aliases
What happened?
fallow dead-codereports incorrect unused/unlisted dependency findings when pnpm package sources are used through catalogs.Example
pnpm-workspace.yaml:yamlpackages: - apps/* catalog: '@std/csv': jsr:1.0.6 unstorage: npm:unstorage-nightly@2.0.0-alpha.5The package manifests depend on the declared names:
json{ "dependencies": { "@std/csv": "catalog:" } }json{ "dependencies": { "unstorage": "catalog:" } }Source imports also use the declared names:
tsimport { stringify } from '@std/csv/stringify';tsimport { createStorage } from 'unstorage';But Fallow can report the declared package names as unused:
json{ "package_name": "@std/csv", "location": "dependencies", "path": "apps/cli/package.json" }json{ "package_name": "unstorage", "location": "dependencies", "path": "apps/native/package.json" }And report the resolved package-source names as unlisted:
json{ "package_name": "@jsr/std__csv", "imported_from": [ { "path": "apps/cli/src/output.ts" } ] }json{ "package_name": "unstorage-nightly", "imported_from": [ { "path": "apps/native/src/storage.ts" } ] }This seems to conflate the manifest/import package name with pnpm’s resolved package-source name.
pnpm documents that packages can be installed from alternate sources:
Assistant
Let me start by understanding the repository structure and the issue. The issue is about false positives for pnpm package source aliases in a tool called "fallow" (likely a dead-code detection tool for JavaScript/TypeScript projects). Let me explore the repository structure first.
The key problem:
- When pnpm uses package sources (like
jsr:ornpm:<name>@<version>), the declared package name inpackage.jsonand imports differs from the resolved package name that pnpm uses internally. - For example,
@std/csvis declared inpackage.jsonand used in imports, but pnpm resolves it to@jsr/std__csvinternally. - Fallow incorrectly reports
@std/csvas unused and@jsr/std__csvas unlisted.
Let me start by exploring the repository.
- When pnpm uses package sources (like
Assistant
This is a Rust project. Let me explore the
cratesdirectory and understand the structureAssistant
Let me explore the relevant crates - particularly
coreandgraphwhich likely handle dependency analysisAssistant
Let me run one command at a time.
Assistant
Let me look at the key files. The issue is about pnpm package source aliases in dependency analysis.
Assistant
Let me look at more specific areas related to pnpm package sources
Assistant
Let me look at the key files for understanding how packages are resolved
Assistant
Let me look at how packages are resolved, starting with the graph crate
Assistant
Let me look at how package names are resolved from lockfiles and catalogs
Assistant
Let me look at the workspace module structure
Assistant
Let me look at
pnpm_catalog.rssince that's where catalog parsing happens, and thenpackage_json.rsfor how dependencies are resolved.Assistant
Now let me look at how packages from pnpm lockfiles are resolved and how the name mapping works
Assistant
Let me search for how lockfile package names are resolved in the graph crate
Assistant
Let me look at the
unused_deps.rsfile to understand how dependency usage is analyzedAssistant
Let me look at the relevant sections, particularly around how pnpm workspace and node_modules paths are used to extract package names. Let me also look for how
pnpmlockfiles are parsed.Assistant
Let me look at the
extract_package_name_from_node_modules_pathfunction and surrounding codeAssistant
Let me view the relevant section of the file
Assistant
Let me search for where jSR packages are handled (the
@jsr/prefix)Assistant
Let me look at how the
npm:scheme is handled in specifier resolutionAssistant
Let me look at how
unused_deps.rscollects and analyzes dependenciesAssistant
Let me look at the
collect_unusedfunction and the dependency analysis flowAssistant
Let me look at the graph's
package_usagefield and how it's populatedAssistant
Let me look at the
package_usage_namefunction and theresolve/types.rsfileAssistant
Let me look at how bare specifiers are resolved to NpmPackage in the specifier resolution
Assistant
Let me look at how bare specifier resolution picks up the package name from node_modules
Assistant
Let me look at the
collect_workspace_used_packagesandfind_unused_dependenciesfunctions moreAssistant
Let me look at
find_unlisted_dependenciesto understand the unlisted detectionAssistant
Let me look at
extract_package_name_from_node_modules_pathand understand how it handles pnpm pathsAssistant
Let me look at the
extract_package_namefunctionAssistant
Let me look at that function.
Assistant
Let me look at the test for issue 624 (supabase edge) to understand the existing handling
Assistant
Let me look at how the resolver is configured
Assistant
Let me look at the
create_resolverfunction.Assistant
Let me look at the
create_resolverfunction.Assistant
Let me look at the full
resolve_specifierfunction, focusing on the bare specifier resolutionAssistant
Let me look at the full resolution function to understand where the package name is determined
Assistant
Now I have a good understanding of the issue. Let me create a reproduction script first, and then implement the fix
Assistant
Let me create reproduction
Assistant
Let me look more carefully at the resolution flow and identify the exact fix. Let me also look at the existing test for issue 624 which may give me hints
Assistant
Let me look at lines 1163-1215 of specifier.rs
Assistant
Let me look for any existing helper that checks for
.pnpmin a pathAssistant
Now I understand the issue. Let me implement the fix. The problem is in
crates/graph/src/resolve/specifier.rswhere the package name is extracted from the node_modules path for.pnpmpaths. When pnpm uses package source aliases (likejsr:ornpm:<name>), the internal package name in.pnpmdiffers from the declared/imported name. Let me create the fix:Assistant
Let me get a comprehensive view of the resolution function to plan my
Assistant
Now I have a clear understanding. Let me implement the fix. The issue is that when the resolver follows symlinks into pnpm's
.pnpmvirtual store,extract_package_name_from_node_modules_pathreturns the internal package name (like@jsr/std__csv) instead of the user-facing name from the import specifier (like@std/csv).I need to modify the resolution to use the specifier's package name when the resolved path goes through
.pnpm. Let me implement this:Assistant
Let me add a helper function and modify the resolution code. First let me open the file:
Assistant
Let me try using the edit command directly. First, add a helper function for pnpm store path
Assistant
Let me add a helper function after
is_node_modules_path.Assistant
Now let me modify the three places where package names are extracted. First, let me update
try_style_condition_package_resolution:Assistant
Now let me modify the main
resolve_specifierfunction. First, let me look at the canonical pathAssistant
Now let me apply the fixes. First, update the fast path inline
.pnpmcheck to use our helper functionAssistant
Let me use
gototo see the exact text at that lineAssistant
The
gotocommand doesn't have a--fileoption. Let me useopenfollowed bygoto.Assistant
Let me use
editwith line numbers for the replacementAssistant
The edit went wrong. Let me fix the malformed condition block:
Assistant
Good. Now let me modify the canonical path to use specifier name for
.pnpmpaths. The key change is to compute the correct package name based on whether we're in a.pnpmpathAssistant
I need to check if there's an extra brace. Let me look at the area around line 1197 more carefully
Assistant
I see there's an extra closing brace at line 1197. Let me remove it
Assistant
I have a duplicate
} else {. Let me fix the blockAssistant
Now let me fix the error path similarly. Let me look at the current state of lines 1210-123
Assistant
Now let me also fix the error path:
Assistant
I have another duplicate block. Let me fix this
Assistant
Good, that's fixed. Now let me also update
try_style_condition_package_resolutionand then try to build. First let me look at the current state of that function:Assistant
Let me also update
try_style_condition_package_resolutionfor consistency. I need to fix three locations in this function:Assistant
I have an extra brace again. Let me fix it:
Assistant
Now fix the canonical path and error path in `try_style_condition_package_res
Assistant
Now fix the error path in
try_style_condition_package_resolution:Assistant
Now let me try to build the project to see if the code compiles
Assistant
The build is still downloading dependencies. Let me wait for it to complete.
Assistant
The code compiles. Now let me run the existing tests to ensure nothing is broken.
Assistant
All graph tests pass. Let me also run the core tests, especially the dependency-related ones:
Assistant
All 545 tests pass! Let me also run the config tests and the full test suite to make sure:
Assistant
Let me also verify the specific integration tests related to the issue area are passing:
Assistant
Let me try with proper test name filtering
Assistant
All relevant tests pass. Let me now run the full test suite to make sure nothing else is broken:
Assistant
Let me check if the failing test is pre-existing and not related to my
Assistant
Good - the failing test is pre-existing and not related to my changes. Let me restore my changes:
Assistant
Let me review my changes to make sure they're correct:
Assistant
Let me also verify there are no other call sites of
extract_package_name_from_node_modules_paththat need similar treatmentAssistant
Let me check the other call sites to see if they need similar treatment
Assistant
Let me check
external_style_usage.rsto see if it needs the fix tooAssistant
Let me check the fallbacks.rs call sites briefly
Assistant
The main fix is in the critical path. Let me now run the full test suite to ensure everything passes (excluding the pre-existing failure):
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.