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 understanding the repository structure and the issue at hand. The issue is about false positives for pnpm package source aliases in the
fallow dead-codecommand.Let me first explore the repository structure and understand the codebase.
Assistant
This is a Rust project (fallow). Let me explore the crates directory to understand the structure.
Assistant
Let me explore the core crate since it likely contains the logic for dependency analysis and dead-code detection
Assistant
The issue is about dead-code analysis for pnpm package source aliases. Let me look at the relevant files, particularly around unused deps and package resolution
Assistant
Let me look at the pnpm plugin and the unused_deps module:
Assistant
Now let me look at the unused_deps module where the main logic for detecting unused/unlisted dependencies lives
Assistant
Let me see the rest of this file and understand the complete picture
Assistant
Let me see the remaining parts of the file, especially the functions around
find_unused_dependenciesand any functions dealing with package_usage.Assistant
Let me look at the resolver module to understand how package names are resolved
Assistant
Let me explore the resolve module.
Assistant
Let me look at the resolver types to understand the data
Assistant
Now let me look at the specifier.rs to understand how package names are resolved for pnpm catalog entries
Assistant
Let me look at the specific section around lines 1003-1007 in specifier.rs
Assistant
Let me look at the pnpm workspace fallback resolution in fallbacks.rs
Assistant
Let me look at how the resolver extracts package names from node_modules paths
Assistant
Let me find the
extract_package_name_from_node_modules_pathfunctionAssistant
Let me look at the
extract_package_name_from_node_modules_pathfunctionAssistant
Let me examine the main resolution path more
Assistant
Let me look at the full specifier.rs more closely to understand how package names get resolved for npm packages
Assistant
Let me look at the
extract_package_namefunction and how bare specifiers are resolvedAssistant
Let me look at the path_info.rs to understand extract_package_name
Assistant
Let me look at the existing integration tests for pnpm catalog
Assistant
Let me look at the fixture for this test to understand the test setup
Assistant
Let me look at these fixture files:
Assistant
Let me look at how package names are resolved for package.json-based name extraction
Assistant
Let me look at how the resolver resolves bare specifiers - specifically the part where it resolves through
Assistant
Let me look at the
resolve_file_with_tsconfig_fallbackfunctionAssistant
Let me look at the resolver
Assistant
Let me look at the graph build module to understand how package_usage is
Assistant
Let me look at all the places where
NpmPackageis created in the resolve moduleAssistant
Let me see all the NpmPackage creation sites in specifier.rs in context
Assistant
Let me look at the function around line 930-985 in specifier.rs to understand another NpmPackage creation path
Assistant
Now I understand the issue. Let me look at the relevant code in specifier.rs to plan my changes. Let me first reproduce the issue by creating a temporary test.
Assistant
Let me run the relevant test suites for the resolve module
Assistant
Let me run the specifier tests
Assistant
Let me look at the tests for specifier resolution - the test file tests.rs
Assistant
Let me look at the test for resolve_specifier_node_modules
Assistant
Let me look at the test to understand the test
Assistant
Let me now look at how the integration tests work with the fixtures approach. Let me look at the existing test helpers.
Assistant
Now I have a thorough understanding of the issue. Let me look at the exact code I need to modify in specifier.rs:
Assistant
The file can't be opened this way. Let me use the
opencommand properly.Assistant
Let me use the open command with the correct syntax - the file path and line number as positional arguments.
Assistant
Let me use the open command as described in the system prompt:
Assistant
Let me see the rest of the resolve function:
Assistant
Let me use goto via a shell command
Assistant
Now I have a clear understanding of the issue. The problem is in
resolve_specifierfunction whereextract_package_name_from_node_modules_pathis used to determine the package name forNpmPackage. When pnpm uses package source aliases (likenpm:unstorage-nightlyforunstorage, orjsr:1.0.6for@std/csv), the path-based name reflects pnpm's internal structure (unstorage-nightlyor@jsr/std__csv) rather than the declared name (unstorageor@std/csv).For bare specifiers, we should use
extract_package_name(specifier)which gives the user-declared package name.Let me implement the fix:
Assistant
I need to use the
editcommand with proper syntax. Let me use the heredoc syntaxAssistant
Now apply the same fix to the error path case at lines 1199-1214:
Assistant
I see an extra closing brace on line 1221. Let me fix that:
Assistant
Let me fix this by using the correct edit syntax with replacement text:
Assistant
Now let me check if there are similar patterns that need fixing in other places, particularly in
fallbacks.rs:Assistant
Let me look at those two locations in fallbacks.rs
Assistant
Let me see the
try_path_alias_fallbackfunctionAssistant
Let me check the second occurrence in fallbacks.rs:
Assistant
Let me check the
try_style_condition_package_resolutionfunction in specifier.rs for similar patterns:Assistant
Let me now compile the project to verify my changes are correct:
Assistant
The code compiles. Now let me run the tests for the graph crate:
Assistant
Let me also run the core tests:
Assistant
Now let me think about whether there are other places that need to be updated. Let me also look at the
find_unused_dependenciesfunction more closely to see if it also needs changes:Assistant
Let me look at the
find_unused_dependenciesfunction to understand how it uses package namesAssistant
Let me also check for
InternalPackageModulewhich also has apackage_namefieldAssistant
Let me look at these
InternalPackageModulecreation sites in fallbacks.rs to see if they could be affectedAssistant
Let me also check the other InternalPackageModule creation sites:
Assistant
Let me run the full test suite to make sure nothing is broken:
Assistant
Good, all tests pass. Now let me verify my understanding is correct by also checking the integration test related to pnpm catalogs and dependencies:
Assistant
All the dependency tests pass. Let me also run the full test suite to make sure nothing else is broken:
Assistant
The one test failure (
fix_batch_aborts_when_a_target_directory_is_read_only) is pre-existing and unrelated to my change. Let me run the resolver-specific tests and the core dependency tests to confirm everything works:Assistant
All resolver tests pass. Let me look at the diff of my changes to verify:
Assistant
The changes look correct. Let me also run the integration tests that are specifically related to pnpm catalog issues:
Assistant
Let me also run a few more related tests:
Assistant
Let me run them separately
Assistant
All tests pass. Let me now also verify with a few more test suites to make sure everything is working:
Assistant
Let me search for any tests related to package sources or aliases:
Assistant
Let me do a final check to make sure the core tests still pass:
Assistant
All 3557 tests pass with 0 failures. Let me now review the changes one more time and submit.
Let me verify the final state of my
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.