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:packages: - apps/* catalog: '@std/csv': jsr:1.0.6 unstorage: npm:unstorage-nightly@2.0.0-alpha.5The package manifests depend on the declared names:
{ "dependencies": { "@std/csv": "catalog:" } }{ "dependencies": { "unstorage": "catalog:" } }Source imports also use the declared names:
import { stringify } from '@std/csv/stringify';import { createStorage } from 'unstorage';But Fallow can report the declared package names as unused:
{ "package_name": "@std/csv", "location": "dependencies", "path": "apps/cli/package.json" }{ "package_name": "unstorage", "location": "dependencies", "path": "apps/native/package.json" }And report the resolved package-source names as unlisted:
{ "package_name": "@jsr/std__csv", "imported_from": [ { "path": "apps/cli/src/output.ts" } ] }{ "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:
jsr:installs from the JSR registrynpm:<name>@<version>can resolve a declared dependency through a different npm package name- package sources are part of pnpm’s supported dependency model, not separate source imports
So if
@std/csvis declared and imported, Fallow should credit@std/csv, even if pnpm resolves it to@jsr/std__csvinternally. Same forunstorageresolving tounstorage-nightly.Reproduction
Create
pnpm-workspace.yaml: Assistant
Let me start by exploring the repository structure to understand the codebase and then reproduce the issue.
The issue is about false positives when using pnpm package source aliases. Let me first understand the structure of the repository.
Assistant
This looks like a Rust project (Cargo.toml, crates directory). The tool is called "fallow" (or maybe "knope"?). Let me explore more.
Assistant
Let me look at the core crate since that's likely where the dead-code analysis logic lives.
Assistant
Let me search for relevant code about dead-code detection and package resolution
Assistant
Let me look at the unused_deps analysis and the discover directory:
Assistant
I need to make a single command call. Let me try with a single command.
Assistant
Let me look at the unused_deps analysis file and the discover module to understand how packages are resolved.
Assistant
Let me look at the graph module and how package usage names are determined.
Assistant
Let me look at the resolve directory and the graph lib.
Assistant
Let me look at
fallbacks.rsandspecifier.rsfor the package name resolution logic:Assistant
Let me look at how
package_usage_nameis defined and how it handles JSR and npm: prefixes.Assistant
Let me look at the
package_usage_namefunction and the resolve types:Assistant
Now let me look at specifier.rs around the JSR and npm: handling
Assistant
Let me look at the full specifier.rs from the beginning to understand how JSR and npm: are handled:
Assistant
Let me look at the key part of specifier.rs that handles JSR and npm: prefixes:
Assistant
Let me look at how package names are extracted from node_modules resolution:
Assistant
Let me look at
extract_package_name_from_node_modules_pathfunction:Assistant
Let me look at how resolution determines the package name from node_modules paths (around line 950):
Assistant
Let me look at the
extract_package_namefunction andis_bare_specifierin path_info.rs:Assistant
Let me look at
graph/build.rsto understand how package usage is recorded:Assistant
Let me find all the places where
extract_package_name_from_node_modules_pathis used to createNpmPackage:Assistant
Let me look at lines around 1135-1210 in specifier.rs to understand the full context:
Assistant
Let me now look at the existing tests to understand how to test
Assistant
Let me find all callers of
extract_package_name_from_node_modules_path:Assistant
Let me check the call sites in fallbacks.rs:
Assistant
Let me check the other call site in fallbacks.rs around line 363:
Assistant
Let me look at the context of the fallbacks.rs call site at line 68 more closely:
Assistant
Let me look at the function signatures around line 363:
Assistant
Now I have a clear plan. Let me implement the fix:
- Add a helper function in
fallbacks.rsthat resolves the correct package name for dependency tracking - Modify call sites in
specifier.rsto use this helper - Modify call sites in
fallbacks.rswhere needed
Let me start by adding the helper function.
- Add a helper function in
Assistant
Now let me add the helper function. First, let me see the exact location after
extract_package_name_from_node_modules_path:Assistant
Let me check what's exported from the resolve module:
Assistant
Let me now implement the fix. First, let me add the helper function in `fallbacks.rs
Assistant
Now I'll add the helper function. Let me edit the file
Assistant
Let me fix the missing blank line:
Assistant
Now let me export the new function and update
mod.rs:Assistant
Now let me update
specifier.rsto use the new function. Let me open it and look at the import section:Assistant
First, update the import in `specifier
Assistant
Let me use the inline edit syntax instead:
Assistant
Now I need to update the call sites. Let me look at the first one in
try_style_condition_package_resolution:Assistant
Let me look at the context around lines 948-985
Assistant
Let me check the function signature of `try_style_condition_package_resolution
Assistant
Now let me update each call site. First, line 951:
Assistant
The edit got corrupted due to bash history expansion. Let me fix it:
Assistant
Let me re-do the import addition first, then do each replacement carefully:
Assistant
Let me add the import and modify call sites using
replace:Assistant
Let me verify:
Assistant
Let me check the current line numbers:
Assistant
Let me replace each call site carefully using sed with line numbers:
Assistant
Let me check the current state:
Assistant
Now the remaining four:
Assistant
Let me verify:
Assistant
Now let me also update the call sites in
fallbacks.rs:Assistant
Let me check the context around line 68 in fallbacks.rs:
Assistant
Let me check line 363 in fallbacks.rs:
Assistant
Now let me update both call sites in fallbacks.rs:
Assistant
Let me verify:
Assistant
Let me check
external_style_usage.rs:Assistant
Let me check upgrades.rs:
Assistant
Now let me try to build the project to check for compilation errors:
Assistant
The build is downloading dependencies. Let me wait for it to complete:
Assistant
The build succeeded with only one warning. Let me clean up the unused import:
Assistant
Now let me rebuild and run tests:
Assistant
Now let me run the relevant tests:
Assistant
All graph tests pass. Now let me run the core tests, especially unused_deps:
Assistant
The tests pass. Let me also run a broader set of tests to make sure nothing is broken:
Assistant
All tests pass. Let me also run the CLI tests:
Assistant
Let me check if this test failure is related to my changes:
Assistant
Let me check if this test failure is pre-existing and not related to my changes:
Assistant
The test failure is pre-existing and not related to my changes. Let me restore my changes:
Assistant
Let me look at the
try_path_alias_fallbackmore carefully to ensure we use the right specifier:Assistant
Let me revert the changes in
fallbacks.rssince those functions deal with path aliases and SCSS, not the main bare specifier resolution path:Assistant
Now let me re-add the
resolve_package_usage_namefunction that was lost by the checkout:Assistant
The function was lost after git checkout. Let me add it back:
Assistant
I need to add the function after line 810 (after
extract_package_name_from_node_modules_pathcloses) and before line 812 (/// Try to map a pnpm virtual store...). Let me do it with sed:Assistant
Let me verify:
Assistant
Let me rebuild and run tests:
Assistant
Clean build. Let me run the relevant tests:
Assistant
All graph tests pass. Let me also run the core tests:
Assistant
All tests pass. Let me now look at the final diff of all my changes:
Assistant
Let me verify there are no remaining call sites in the resolution path that I might have missed:
Assistant
All call sites in specifier.rs are updated. Let me do a final verification build:
Assistant
Everything looks good. Let me now verify the final state of all my
Assistant
Good. Let me review my changes one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.