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
Good,
extract_package_nameandis_valid_package_nameare already imported. Now let's add the helper function inpath_info.rs:Assistant
Now let's insert the helper function after
extract_package_name:Assistant
Now let's update
specifier.rsto import and use this helper in the three relevant branches:Assistant
Now let's update the three branches. First, let's view exact current line numbers again since imports were added.
Assistant
Now let's also handle the "unlisted dependency" credit issue - we need to check
unused_deps.rsto see how it credits usage, since the resolvedNpmPackage(name)result is what feeds dependency usage tracking. Let's build and test now.Assistant
The fix works. Now let's make sure normal (non-aliased) dependency detection still works correctly, and run the existing test suite.
Assistant
Good,
lodashunused dependency still correctly detected. Let's also verify a genuine unlisted dependency (imported but not declared) still gets flagged, and test truly-unlisted-but-real-aliased package scenario stays correct.Assistant
Both correctly detected:
@std/csvcredited properly (not unused),truly-unlistedcorrectly flagged as unlisted. Now let's run the full test suite to make sure nothing broke.Assistant
All graph tests pass. Let's check the beginning of the output for any failures we might've missed, and run broader test suite for core/cli crates too.
Assistant
All good, no failures. Now let's run the full workspace test suite (this may take a while).
Assistant
It's compiling test binaries with dependencies. Let's run in background with a longer time budget, running specific crates instead to keep runtime reasonable.
Assistant
Good, changes restored. This confirms the failing test is unrelated flakiness (likely from parallel test execution interfering with PATH/env, since it passes standalone and my change doesn't touch that code path at all). Let's rebuild with our changes and run the core/config/cli test suites more targeted (excluding the flaky one) to be safe.
Assistant
No failures (grep exit 1 = no matches = all good). Now let's run the
fallow-clitest suite once more standalone to double check, excluding possibly flaky test but capturing overall status.Assistant
Confirmed — this failure is due to running tests as root (permission checks are bypassed for root), unrelated to our change. This is expected environment-based flakiness. Let's verify the rest of the fallow-cli tests all pass except this one.
Assistant
Only this one root-permission-related test fails, unrelated to our change. Let's also run the graph crate's fuzz/property tests one more time and check
cargo clippyfor our specific files to ensure code quality.Assistant
Let's view the final diff to review everything.
Assistant
Correctly reports
lodash(non-aliased, plain .pnpm-resolved package) as unlisted with the real/declared name, matching the specifier text — the fix generalizes correctly and doesn't break normal.pnpmresolution.Assistant
Both scenarios (aliased and non-aliased packages) resolve correctly now. Let's clean up the repro directory since it's outside the repo (not needed, but good hygiene) and do a final review of the diff.
Assistant
Now let's go through the checklist explicitly.
Checklist Review
- If an error was reported in the issue description, I have successfully reproduced it.
Yes. I built a synthetic pnpm workspace with
pnpm-workspace.yamlcatalog entries usingjsr:andnpm:package sources, matching manifests/imports, and a realistic.pnpmvirtual-storenode_moduleslayout (symlinks pointing into.pnpm/<real-name>@<version>/node_modules/<real-name>). Runningfallow dead-code --format jsonreproduced exactly the reported false positives:@std/csv/unstoragereported as unused, and@jsr/std__csv/unstorage-nightlyreported as unlisted.
- If an error was reported in the issue description, I have successfully reproduced it.
Yes. I built a synthetic pnpm workspace with
Assistant
Build succeeds cleanly with the final formatted diff. The fix is complete, minimal, and targeted:
Summary
Root cause: When resolving bare import specifiers that go through pnpm's
.pnpmvirtual store (used for npm aliases,jsr:/ package sources, and entries expanding to those), fallow's resolver followed the symlink () into the physical store directory and derived the "package name" from that real, resolved directory name (e.g. , ) instead of the name actually declared in and used in the import specifier (e.g. , ). This caused the declared name to be reported as unused, and the resolved/real name to be reported as unlisted.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.