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 how it's organized and find the relevant code for handling pnpm package sources and dependency analysis.
Assistant
The repository is a Rust project. Let me explore the structure more, especially looking at the pnpm-related files and the unused_deps analysis.
The issue is about pnpm package sources (like
jsr:andnpm:<name>@<version>) being handled incorrectly - the tool is reporting false positives because it's treating the resolved source name differently from the declared/import name.Let me look at:
- The pnpm-related files
- The unused_deps analysis
- How package names are resolved
Assistant
Let me explore the pnpm plugin and the unused_deps/unused_catalog files since they seem most relevant:
Assistant
Let me look at the pnpm plugin and the unused_catalog files since those seem most relevant to the issue.
Assistant
Now let me look at the unused_catalog.rs and the main unused_deps module:
Assistant
Let me look at the unused_deps module to understand how dependencies are analyzed:
<tool_call> <function=bash_terminal> <parameter=command> cat /fallow/crates/core/src/analyze/unused_deps.rs </tool_call>
Assistant
The tool call wasn't properly formatted. Let me try again with the correct format.
Assistant
Now let me look at how package names are resolved, particularly the
package_usage_namemethod and how imports are tracked:Assistant
Let me look at the resolve/types.rs file to understand how package_usage_name works, and also how package names are resolved from imports.
Assistant
Now I need to understand how the package name gets set in
NpmPackageresult. Let me look at the graph building and resolution logic to understand howNpmPackage(name)gets its name.Let me check the graph/build.rs file.
Assistant
Let me look at the resolver to see where
NpmPackageresults are created:Assistant
Now I need to look at the specifier resolution code to see where
NpmPackageresults are created, and how the package name is determined.Assistant
Let me look at the path_info.rs to see how
extract_package_nameworks:Assistant
Let me look at how the package name gets extracted from node_modules paths:
Assistant
Let me look at the
extract_package_name_from_node_modules_pathfunction specifically:Assistant
Let me look at the function definition:
Assistant
Now I need to understand the problem more clearly. The issue is about pnpm package sources (like
jsr:andnpm:<name>@<version>in catalogs). Let me look for how pnpm handles the package-source name mapping.When pnpm resolves a package like
@std/csvthat has a catalog entry@std/csv: jsr:1.0.6, pnpm internally installs it as@jsr/std__csv. Similarly,unstorage: npm:unstorage-nightly@2.0.0-alpha.5gets resolved tounstorage-nightly.The problem is that:
- Fallow sees imports like
import { stringify } from '@std/csv/stringify'which resolves to the physical location under node_modules - From the physical path, it extracts the package name as
@jsr/std__csvorunstorage-nightly - But the package.json declares the dependency as
@std/csvorunstorage - So Fallow reports
@std/csvas unused and@jsr/std__csvas unlisted
The fix needs to handle the mapping between the declared package name and the resolved source name when pnpm package sources are used.
Let me look at the pnpm-lock.yaml parsing and how fallow reads the pnpm catalog data to see if there's already a mechanism to track source name mappings.
- Fallow sees imports like
Assistant
Now I need to understand the problem better. Let me look at how the pnpm lock file parsing handles package sources and how the package name mapping works.
Assistant
Let me search for how pnpm package sources are handled, particularly looking for any existing mapping between declared names and resolved names:
Assistant
Let me search more specifically for how pnpm package sources are tracked or resolved.
Assistant
Let me look at the config module to understand how pnpm catalog data is parsed:
Assistant
Let me look at how pnpm catalog data is parsed, and then understand where the mapping between declared package names and resolved source names happens.
Assistant
Let me continue exploring the repository structure to understand how pnpm package sources affect dependency resolution.
Assistant
Assistant
I need to search for where the dependency analysis functions are called. Let me fix the command format.
Assistant
Let me look at how these functions are called from the main analysis module.
Assistant
Good, now I can see how the functions are called. Let me look at the actual call sites in mod.rs to understand the context.
Assistant
Now I understand the issue and the codebase. Let me implement the fix step by step.
The problem is:
- When pnpm uses package sources (like
jsr:ornpm:<name>@<version>), the resolved package name in node_modules differs from the declared name - Fallow tracks imports using the resolved name but compares against declared names
- This causes false positives for unused/unlisted dependencies
The fix needs to:
- Parse pnpm-workspace.yaml catalogs to extract source→declared name mappings
- Apply these mappings in the dependency analysis functions
Let me start by examining the catalog data structure more closely:
- When pnpm uses package sources (like
Assistant
Now I have a good understanding of the issue and the codebase. Let me outline my approach:
Issue Summary
When pnpm uses package sources in catalogs (e.g.,
jsr:1.0.6ornpm:unstorage-nightly@2.0.0-alpha.5), the resolved package name in node_modules differs from the declared name in package.json. Fallow tracks imports using the resolved source name but compares against declared names, causing false positives for unused/unlisted dependencies.Fix Plan
- Extend
PnpmCatalogEntryto store the source value from the catalog - Create a function to determine the resolved source package name from the source specifier
- Build a mapping from source names to declared names
- Apply this mapping in the dependency analysis functions to map resolved names back to declared names
Let me implement this step by step.
- Extend
Assistant
Now I have a good understanding. Let me implement the fix step by step.
First, I'll extend the
PnpmCatalogEntrystructure to store the source specifier value:Assistant
Let me look at the current file structure and make the edit correctly.
Assistant
The issue is that the line range syntax might not be matching correctly. Let me try with the correct format.
Assistant
The issue is about pnpm package source aliases. Let me re-read the problem:
- In pnpm-workspace.yaml catalogs, packages can have source specifiers like
jsr:1.0.6ornpm:unstorage-nightly@2.0.0-alpha.5 - When pnpm resolves these, the package name in node_modules differs from the declared name
- Fallow currently uses the resolved source name for tracking, but compares against declared names
- This causes false positives: declared packages reported as unused, resolved packages reported as unlisted
The fix needs to:
- Store the source specifier in PnpmCatalogEntry
- Create a mapping from source names to declared names
- Apply this mapping in dependency analysis
Let me implement this step by step. First, I'll modify the PnpmCatalogEntry structure and the parsing code.
- In pnpm-workspace.yaml catalogs, packages can have source specifiers like
Assistant
Let me try again with the edit command. The issue might be with the special characters in the text. Let me use a different approach.
Assistant
Let me continue with my approach. I need to modify the PnpmCatalogEntry structure and then create a mapping from source names to declared names.
The key issue is:
- pnpm catalogs can have entries like
@std/csv: jsr:1.0.6orunstorage: npm:unstorage-nightly@2.0.0-alpha.5 - These get resolved to different package names in node_modules
- Fallow tracks the resolved name but compares against the declared name
The fix:
- Add source_specifier field to PnpmCatalogEntry
- Parse the source specifier value from the catalog
- Create a function to derive the source package name from the specifier
- Build a mapping from source name → declared name
- Apply this mapping during dependency analysis
Let me continue implementing this.
- pnpm catalogs can have entries like
Assistant
Let me check what happened to the file:
Assistant
Let me fix this properly. The field was added in the wrong position and the formatting is incorrect.
Assistant
I need to fix the PnpmCatalogEntry struct properly. Let me use the edit command with the correct format.
Assistant
Let me try a different approach using sed:
Assistant
The field order is wrong now. Let me fix it properly:
Assistant
Let me try a different approach using a heredoc-style edit:
Assistant
Let me try writing a file with sed that does the replacement properly:
Assistant
Let me continue. I need to modify the PnpmCatalogEntry struct and related code to track source specifiers.
Assistant
The edit was successful. Now I need to verify the change and continue with the implementation. Let me check the struct and then modify the collect_entries function to populate the source_specifier field.
Assistant
Now I need to update the
collect_entriesfunction to extract the source specifier value. Let me look at that function:Assistant
I need to update the
collect_entriesfunction to extract the source specifier value. Let me look at the function and understand how to modify it.Assistant
Now I need to modify the
collect_entriesfunction to also extract the source specifier value. The current code ignores the value with_.Assistant
Good, let me verify the change was applied correctly:
Assistant
Now I need to add a function to derive the source package name from a source specifier. Let me add this to the PnpmCatalogData struct and update the parsing logic.
Assistant
Now I need to add a method to derive the source package name from a source specifier. Let me add this to the PnpmCatalogEntry struct.
Assistant
Now let me verify the changes and continue building the mapping functionality:
Assistant
Good, the changes look correct. Now I need to add a method to
PnpmCatalogDatato build a mapping from source package names to declared package names, and then use this mapping in the dependency analysis.Assistant
Let me check the current state of the file:
Assistant
Now let me check if the code compiles by trying to build it:
Assistant
I need to wait for the build to complete. Let me check if it finishes successfully.
Assistant
I made an error with the package name. It should be
fallow-confignotfallow_config. Let me continue with the build using the correct package name.Assistant
I have a compilation error. The
source_package_namemethod is trying to return a reference to a local variable. I need to fix the return type to return an ownedStringinstead of&str. Let me fix this.Assistant
Now let me check if it compiles:
Assistant
The config package compiles. Now I need to integrate this mapping into the dependency analysis. Let me first look at how the
PnpmCatalogStateis built and used:Assistant
Now I need to integrate the source-to-declared mapping into the dependency analysis. Let me look at how the dependency analysis is called and where I need to pass the mapping:
Assistant
I need to continue with my plan. Let me look at how the PnpmCatalogState is gathered and where it's used:
Assistant
Now I understand the architecture better. I need to integrate the source-to-declared mapping into the dependency analysis. The key insight is that when pnpm uses package sources like
jsr:ornpm:<name>@<version>, the resolved package name in node_modules differs from the declared name.I need to:
- Pass the catalog data (with source mappings) to the dependency analysis functions
- Apply the mapping when tracking package usage and checking for unlisted dependencies
Let me look at the dependency analysis functions and see how to integrate the mapping:
Assistant
I need to continue with the fix. Let me look at how the dependency analysis functions use the package usage and where to apply the mapping.
Assistant
Let me continue with my approach. I need to integrate the source-to-declared mapping into the dependency analysis functions. Let me first understand the full flow better and then make the necessary changes.
Assistant
Let me continue with the approach. I need to integrate the source-to-declared mapping into the dependency analysis functions. Let me look at the current structure and find the best place to apply the mapping.
Assistant
Let me continue with my approach. I need to integrate the source-to-declared mapping into the dependency analysis functions.
Assistant
Let me now implement the integration of the source-to-declared mapping into the dependency analysis. First, let me understand the complete picture by looking at how the catalog state is built and used:
Assistant
Let me continue with my approach. I need to:
- Add a method to
PnpmCatalogStateto expose the source-to-declared mapping - Modify the dependency analysis functions to use this mapping
Let me first add the method to
PnpmCatalogState:- Add a method to
Assistant
Let me verify the change and then continue integrating the mapping into the dependency analysis functions.
Assistant
Now I need to modify the dependency analysis functions to use the source-to-declared mapping. The key changes are:
- Add the mapping as a parameter to the dependency analysis functions
- When checking if a declared dependency is used, also check if any source name maps to the declared name
- When checking for unlisted dependencies, skip packages that are source aliases of declared packages
Assistant
Now I need to modify the dependency analysis functions to use the source-to-declared mapping. Let me start with
find_unused_dependencies:Assistant
I need to modify the
find_unused_dependenciesfunction to accept the source-to-declared mapping and use it when checking if dependencies are used. Let me also modifyfind_unlisted_dependenciessimilarly.Assistant
Good, now let me modify
find_unlisted_dependenciessimilarly:Assistant
Let me look at the full signature of
find_unlisted_dependencies:Assistant
Now let me modify
find_unlisted_dependenciesto accept the source-to-declared mapping and use it:Assistant
Now I need to modify the call sites of these functions to pass the source-to-declared mapping. Let me look at how they're called in the main analysis module:
Assistant
Now let me modify the call sites in mod.rs to pass the source-to-declared mapping:
Assistant
The tool call had issues with the search pattern. Let me try a different approach to modify the file.
Assistant
I need to modify the call sites in
mod.rsto pass the source-to-declared mapping. Let me use Python to make these changes:Assistant
Now let me verify the changes and check for any compilation errors:
Assistant
The build is in progress. Let me wait for it to complete to see if there are any errors.
Assistant
The issue is that the
source_to_declaredvariable is defined inside a condition block, but the dependency analysis functions are called outside that block. Let me fix this by restructuring the code:Assistant
I need to move the
source_to_declaredvariable to the outer scope. Let me look at the file structure:Assistant
The error shows that
source_to_declaredis not in scope. Let me look at where I placed the variable definition and where it's being used. The issue is that the variable is defined inside a different code block than where it's being used. I need to move the variable definition to a place where it's accessible. Let me look at the structure more carefully.Assistant
The issue is that
source_to_declaredis defined at the outer scope, but the function calls are in a nested closure that doesn't have access to it. I need to restructure the code so that the variable is accessible where it's used. Let me fix this by moving the variable definition and handling the catalog state gathering differently.Assistant
The user is still in the same session. Let me continue with my work - I need to verify the changes compile correctly and then update the tests to pass the new parameter.
Assistant
The core package compiles. Now I need to update the test files that call
find_unused_dependenciesandfind_unlisted_dependenciesto pass the new parameter. Let me check what tests need updating.Assistant
I need to update all the test files to pass the new
source_to_declaredparameter. Let me modify the helper function first and then update all test calls.Assistant
I need to update the test files to pass the new
source_to_declaredparameter. Let me create a helper function in the test helpers module and update all test calls.Assistant
The user is at the same terminal session. I need to continue fixing the test files to pass the new
source_to_declaredparameter to thefind_unused_dependenciesandfind_unlisted_dependenciesfunctions.Let me update all the test files to use the new helper function.
Assistant
Let me continue updating the test files. I need to update the
unlisted_deps.rstest file as well, and then check if there are any compilation errors.Assistant
I need to continue with my work. I've been updating the test files to pass the new
source_to_declaredparameter. Let me now try to compile and see if there are any remaining issues.Assistant
The code compiles. Let me run the existing tests to make sure I haven't broken anything.
Assistant
I need to fix the remaining test calls. Let me update them all:
Assistant
Let me check the current state and fix any remaining issues:
Assistant
Let me continue fixing the remaining issues. I need to remove the extra semicolons that were introduced and fix any remaining test calls.
Assistant
Let me continue fixing the remaining test calls. I need to check which calls are still missing the new parameter.
Assistant
Let me fix these specific test calls:
Assistant
The user is continuing from the previous context. I need to fix the remaining test calls that are missing the new
source_to_declaredparameter. Let me fix the two remainingfind_unlisted_dependenciescalls inunused_deps.rs.Assistant
The user is still in the same terminal session. I need to fix the remaining test calls that are missing the new
source_to_declaredparameter. Let me fix these specific test calls.Assistant
Now let me check if there are more test files that need updating:
Assistant
Let me check all the test files that need updating:
Assistant
Let me check the actual state of the test files and fix them properly. I need to see which test files still have issues.
Assistant
The user is still in the same terminal session. I need to fix the remaining test files that are missing the new
source_to_declaredparameter. Let me fix all the test files systematically.Assistant
Let me fix all remaining test files at once:
Assistant
Let me fix all remaining test calls properly:
Assistant
Let me verify the fix and check if there are still errors:
Assistant
Let me look at the actual format of the test calls:
Assistant
Let me continue fixing the remaining test files properly.
Assistant
Let me continue with my work. I need to fix the remaining test files that are missing the new
source_to_declaredparameter. Let me check the current state and fix them properly.Assistant
The file got corrupted. Let me reset and fix it properly:
Assistant
Let me continue fixing the remaining test files properly. I need to be more careful with the regex replacements.
Assistant
Let me continue fixing the test files. I need to properly fix all the test files that call
find_unlisted_dependenciesandfind_unused_dependencies.Assistant
The argument count errors are fixed. Let me run the tests again to see if they all pass:
Assistant
All tests pass. Let me run a broader test suite to make sure nothing else is broken:
Assistant
All tests pass. Now let me add a specific test for the pnpm package source alias scenario to ensure the fix works correctly.
Assistant
Let me run the new tests to verify they pass:
Assistant
All the new tests pass. Let me also add tests for the catalog parsing to ensure the source specifier extraction works correctly:
Assistant
Let me run the new tests to verify they pass:
Assistant
I need to fix the JSR package name derivation. The resolved name for JSR packages should be
@jsr/<pkg>not just<pkg>.Assistant
I need to fix the test expectations since I corrected the JSR package name derivation to include the
@jsr/prefix.Assistant
Let me run the tests again to see the current state:
Assistant
I see the issue. The code is incorrectly duplicating the
@symbol for scoped packages. For@std/csv, it's producing@jsr/@std__csvinstead of@jsr/std__csv. I need to fix the transformation to strip the leading@from scoped packages.Assistant
I need to fix the test expectations to match the corrected behavior. Let me update the tests.
Assistant
I need to continue fixing the test failures. Let me run the tests again to see the current state.
Assistant
Let me look at the test file to see the current state of the test expectations.
Assistant
The shell is interpreting
!as a special character. Let me use single quotes instead.Assistant
The user is at the same terminal session. I need to continue fixing the test file - there are still test expectations that don't match the actual implementation. Let me check the test file content.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '580,620p' /fallow/crates/config/src/workspace/pnpm_catalog.rs </tool_call>
Assistant
The user is at the same terminal session. I need to continue fixing the test file. Let me look at the test expectations in the test file.
Assistant
I need to fix the test expectations to match the actual implementation. The tests are expecting just
"std__csv"but the implementation returns"@jsr/std__csv"(with the@jsr/prefix). Let me update the tests.Assistant
Let me run the tests again to see if they pass now.
Assistant
All tests pass. Let me run the full test suite to make sure everything still works.
Assistant
The tests are passing. Let me run a broader test to make sure I haven't broken anything else.
Assistant
Let me run the full test suite to ensure everything works.
Assistant
All tests pass. Let me verify the implementation is complete by running the full test suite one more time and checking for any compilation warnings.
Assistant
All tests pass (705 + 2481 + 14 + 545 = 3745 tests). The implementation is complete. 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.