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 exploring the repository structure to understand what Fallow is and how it works. This is a tool called "fallow" that detects dead code. The issue is about false positives when pnpm package source aliases are used.
Let me first explore the repository structure.
Assistant
This is a Rust project. Let me explore the crates directory and understand the structure better
Assistant
Let me explore the core crate, which likely contains the dead-code detection logic:
Assistant
Let me look at the source files for the core crate, particularly for dead code detection and package resolution.
Assistant
Let me search for files related to pnpm, catalog, and package resolution:
Assistant
Let me look at the analyze directory which likely contains the dead code detection
Assistant
Let me look at the key files. First, let's look at
unused_deps.rs:Assistant
Let me search for relevant terms related to the issue - pnpm catalog, jsr, package sources
Assistant
Let me look at the pnpm plugin and catalog-related files:
Assistant
Let me look at the pnpm catalog handling and the discover/walk module
Assistant
Now let me look at the workspace parsers to understand how pnpm-workspace.yaml is parsed
Assistant
Let me look at the workspace module and pnpm_over
Assistant
Let me look at the graph resolve module to understand how package imports are resolved:
Assistant
Let me look at the resolve directory:
Assistant
Let me look at the resolve types to understand how resolved modules work
Assistant
Let me look at the discover module to understand package discovery
Assistant
Let me look at the graph module, specifically the module graph to understand how
package_usageis builtAssistant
Let me look at the graph build module to understand how package_usage is built:
Assistant
Let me look at the specifier resolution to understand how packages are resolved
Assistant
Let me look at the specifier.rs around those key lines
Assistant
Let me just use grep to look at the relevant sections:
Assistant
Let me search for how catalog references are resolved
Assistant
Let me look at the resolve specifier more closely to understand how packages are resolved from imports
Assistant
Let me find the
extract_package_name_from_node_modules_pathfunction:Assistant
Let me search recursively:
Assistant
Let me look at the
extract_package_name_from_node_modules_pathfunction:Assistant
Let me look at the pnpm_overrides module to understand if there's existing parsing for version specifiers:
Assistant
Let me look at the resolve module's main entry to understand how resolution is invoked
Assistant
Let me look at how the resolver is configured and whether it follows symlinks:
Assistant
Let me look at the resolver creation and how it handles symlinks:
Assistant
Let me look at the
create_resolverfunction:Assistant
Let me look at the existing test for pnpm catalog issues
Assistant
Let me look at the test fixtures for this issue:
Assistant
Let me look at the fixture structure:
Assistant
Let me also check the unused_deps test file to understand the test data structure
Assistant
Let me look at the PackageJson type to understand its structure:
Assistant
Let me find where
resolve_all_importsis called:Assistant
Let me look at the relevant parts of lib.rs where
resolve_all_importsis called:Assistant
Let me look more broadly at the lib.rs to understand the analysis pipeline
Assistant
Let me look at the unused_catalog.rs to understand the catalog state:
Assistant
Let me look at the fixture structure more carefully to understand how tests are set up:
Assistant
Let me look at
extract_package_namein path_info.rs:Assistant
Let me check how re-exports handle package name extraction
Assistant
Let me look at static_imports:
Assistant
Let me look at the specifier.rs more carefully to find the function containing the NpmPackage creation
Assistant
Let me look at the function that contains these NpmPackage creations
Assistant
Let me look at the full
resolve_specifierfunction:Assistant
Let me look at the
extract_package_namefunction:Assistant
Let me look at the imports in specifier.rs:
Assistant
Let me check
is_valid_package_name:Assistant
Let me look at it:
Assistant
Let me look at
is_bare_specifierAssistant
Now I have a comprehensive understanding of the code. Let me implement the fix.
The issue is that when pnpm uses package source aliases (JSR, npm aliases), the package name extracted from
node_modulespaths differs from the declared name inpackage.jsonand import statements. The fix should use the import specifier's package name for dependency tracking, not the name from thenode_modulespath.Let me first create a helper function and then apply it at all the relevant call
Assistant
Let me look at the full specifier.rs file size and plan my edits:
Assistant
Let me look at the appropriate section to add the helper function
Assistant
Let me find a good insertion point. Let me look at lines 920-930
Assistant
Now let me implement the fix. First, I'll add a helper function that resolves the correct package name for usage tracking
Assistant
Let me use sed to make the edit. Let me first read the exact content around line 921 to ensure I get the replacement right
Assistant
Let me use a Python script to make the edits
Assistant
Good. Now let me verify the helper function was added correctly and then replace all call sites
Assistant
Now let me replace the call sites. Let me look at the first one in
try_style_condition_package_resolutionAssistant
Now let me replace all the call sites using Python
Assistant
Let me look at each call site with more context
Assistant
Now let me do all the replacements using Python
Assistant
Let me verify the changes
Assistant
Line 12 is the import and line 941 is the fallback inside our new helper function. Both should remain.
Let me also verify the new calls:
Assistant
Let me check if there are other places outside specifier.rs that use
extract_package_name_from_node_modules_pathto createNpmPackage:Assistant
Let me also check the other files that use
extract_package_name_from_node_modules_pathAssistant
Let me check the usages in fallbacks.rs:
Assistant
Let me see which function this is in fallbacks.rs
Assistant
Let me also check line 363 in fallbacks.rs
Assistant
Now let me try to build the project to see if my changes compile
Assistant
The code compiles. Let me also check the full project builds:
Assistant
Good, the full project compiles. Now let me run relevant tests to ensure nothing is broken:
Assistant
All 235 tests in the resolve module passed. Let me also run the integration tests related to the issue and other relevant tests:
Assistant
Let me also run the unused deps tests and the broader test suite to check for reg
Assistant
Let me run a broader set of tests to check for regressions
Assistant
Let me check if
try_path_alias_fallbackin fallbacks.rs has the same issue:Assistant
Let me verify the modified code around the key areas
Assistant
Let me look at the SCSS node_modules fallback function more carefully:
Assistant
Let me run a broader set of tests to make sure nothing is broken
Assistant
All 545 tests in fallow-core passed. Let me also run the full test suite for all packages to make sure nothing is broken
Assistant
Let me check if there are any issues with the
should_preserve_node_modules_style_filefunctionAssistant
Let me also fix the fallbacks.rs functions. First, let me make
package_name_for_usageaccessibleAssistant
Now let me fix the call sites in fallbacks.rs
Assistant
Let me verify the changes still
Assistant
Let me run the tests again
Assistant
Let me check the final diff to confirm all changes are correct
Assistant
The diff looks good. Let me run the complete test suite to make sure everything passes:
Assistant
Let me also run the CLI tests to make sure nothing is broken there
Assistant
There's a test failure. Let me check if it's related to my changes or pre-existing
Assistant
Let me check if this test failure is pre-existing by checking the test details
Assistant
The test failure is pre-existing and unrelated to my changes. Let me restore my changes:
Assistant
Let me run the full test suite one more time to be thorough:
Assistant
The fix is complete. Let me do a final review of the changes
Assistant
Now let me submit the changes
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.