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
I'll explore the repository structure and locate how pnpm package sources/catalogs are resolved for dead-code analysis.
- Assistant
I'll search for catalog, package-source, and alias resolution logic next.
- Assistant
rg is not available, let me use grep.
- Assistant
I'll dig into package-source handling and dependency name resolution.
- Assistant
I'll focus on package name extraction from lock keys and install sources.
- Assistant
I'll inspect the package resolver and how dependencies map to on-disk package names.
- Assistant
Let me look at discover and graph crates for package resolution.
- Assistant
That
extract_package_name_from_node_modules_pathfunction looks like the key—I'll inspect it and how resolved imports credit package names. - Assistant
Next I'll check how resolved package names are credited from imports.
- Assistant
Let me look at the resolve path that uses extract_package_name_from_node_modules_path - the try_path and canonicalize logic around lines 40-100 and 300-370.
- Assistant
Let me look at the main specifier resolution for bare package imports.
- Assistant
Let me look carefully at specifier.rs around lines 930-1280 where package names are extracted.
- Assistant
Let me see the main resolve path around line 1130-1280
- Assistant
I'll inspect how unused_deps uses
NpmPackageresolve results. - Assistant
There's a
package_usage_name()method on ResolveResult. Let me find that. - Assistant
Let me open types.rs to see ResolveResult and package_usage_name
- Assistant
So the fix should be: when we resolve a bare package specifier through a canonicalized path that goes through
.pnpmand extracts a different package name than the import specifier's package name, we...I understand the issue you're describing with pnpm package sources and catalogs. The core problem is that Fallow's resolver is conflating the declared package name (like@std/csvorunstorage) with the resolved source name (like@jsr/std__csvorunstorage-nightly) when handling pnpm's special package sources.Looking at the code you pointed to, the key part is in the
resolve_bare_specifierfunction around lines 1167-1179. - Assistant
Let me also check the CHANGELOG and any related recent fixes or tests for package sources / aliases.
- Assistant
I'll check lock-key alias handling and existing tests around pnpm package sources.
- Assistant
I'll set up a minimal reproduction of the pnpm package-source alias issue.
- Assistant
Let me look at existing integration tests for dependencies and how they set up node_modules with pnpm structure. Also look for
add_exportless_package_source_indexeswhich sounds. - Assistant
There's false_positive
There's false_positive_fixes.rs and issue files related to pnpm. Let me also search CHA.
- Assistant
I'll find existing symlink/pnpm node_modules setup patterns and the non-canonical path extraction path.
- Assistant
I'll write a quick unit test to reproduce the alias package-name mismatch.
- Assistant
I'll add a temporary test in the graph crate and run it to confirm the bug.
- Assistant
I'll append a temporary graph unit test that builds a pnpm-style alias layout.
- Assistant
I reproduced it. Next I'll implement preferring the bare-import package name and check related code paths.
- Assistant
I'll add a helper that prefers the bare-import package name and wire it into the NpmPackage return paths.
- Assistant
I'll add the helper after extract_package_name and update all the places that return NpmPackage from path extraction.
- Assistant
I accidentally removed the closing brace of extract_package_name. Need to fix that.
- Assistant
Need a blank line between functions for style. Let me fix that and add unit tests, then update exports and call sites.
- Assistant
Now I'll wire the helper into specifier and fallbacks, and export it.
- Assistant
I'll update specifier.rs and fallbacks to credit the declared bare-import package name.
- Assistant
Updating all the NpmPackage construction sites now.
- Assistant
Next I'll update the main resolve_specifier NpmPackage sites.
- Assistant
I'll replace the three NpmPackage(pkg_name) sites in the main resolver.
- Assistant
Checking brace structure around the Err branch for syntax issues.
- Assistant
Missing closing braces—fixing that next.
- Assistant
Now updatefallbacks.rs for consistency. Also check upgrades.rs for anything related.
- Assistant
Updating fallbacks for SCSS node_modules and path-alias cases that hit package-source aliases.
- Assistant
Update NhpPackage sites in fallbacks.
- Assistant
First replace worked, second needs goto.
- Assistant
Need to fix the SCSS fallback.
- Assistant
Also check if package_imports fallback returns NpmPackage paths from external package targets - those already use correct names
Export helper optionally from mod.rs - not strict.
- Assistant
There's something odd at path_info.rs:413 — checking that next.
- Assistant
That's fine - existing proptest. Let me run the tests properly.
- Assistant
The guidelines ban adding tests, so I'll remove the ones I added and keep only the product code.
- Assistant
Remove tests from tests.rs starting at around 1781, and path_info tests.
- Assistant
I'll truncate the file at line 1780.
- Assistant
Remove the path_info tests I added too.
- Assistant
All graph tests passed. Next I'll run an end-to-end dead-code check on a temporary pnpm alias fixture.
- Assistant
I'll create a temporary fixture and run fallow dead-code on it.
- Assistant
Need to check the correct CLI flags.
- Assistant
Maybe it uses positional path or -C
- Assistant
Use --root
- Assistant
Python script had a typo. Let me fix and rerun.
- Assistant
End-to-end reports zero issues. Running related unit tests and a quick format/clippy check next.
- Assistant
rustfmt with system edition fails - normal. Let me use cargo fmt.
- Assistant
There's a small grammar issue in the doc comment: "so a alias" should be "so an alias". Let me fix that.
- Assistant
Let me fix the doc comment grammar with open file.
- Assistant
I can see "so a alias" on line 92-93.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.