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 first inspect the repository structure and search for pnpm/catalog/package-source resolution code and related tests. Then I’ll reproduce the name mismatch with the narrowest existing test or fixture mechanism before changing implementation.
- Assistant
The project is a Rust workspace, and ripgrep is unavailable, so I’ll use
grep/find. I’ll inspect workspace members and locate lockfile/resolver models, especially any code that converts pnpm lockfile package keys into dependency names. - Assistant
Catalog bookkeeping itself keys entries by the declared manifest name, so the defect likely occurs earlier in import resolution. I’ll inspect crate names, resolver result types, and every construction of
ResolveResult::NpmPackage; that variant appears to carry only the resolved name today. - Assistant
The public resolve result intentionally stores one analysis name, so expanding it to two names would be invasive and likely unnecessary. The correct canonical name can usually be extracted from the original import specifier. I’ll inspect the resolver branches that currently return the installed package’s
package.json#nameand compare them with graph construction, where package usage is recorded. - Assistant
The mismatch is confirmed in the resolved-file path: pnpm symlinks are deliberately canonicalized into
.pnpm/<source-name>..., thenNpmPackagereceives that source name. Dependency accounting should instead use the bare import’s package segment. I’ll inspect surrounding alias classification and existing pnpm resolver tests/fixtures so the fix only canonicalizes true bare package imports and does not relabel tsconfig/plugin aliases or relative imports. - Assistant
A safe invariant emerges: once a syntactically bare import resolves outside the workspace as an npm package, usage belongs to
extract_package_name(specifier), regardless of physical target. This also correctly handles ordinary npm aliases, not just catalogs. Before editing, I’ll reproduce through the CLI using a temporary project with pnpm-style symlinks for both scoped JSR and npm aliases; this avoids modifying tests and mirrors the filesystem behavior that triggers canonicalization. - Assistant
The temporary reproduction fixture is built; the first invocation only failed because the CLI crate has multiple binaries. I’ll rerun the
fallowbinary and check its help if argument placement differs. - Assistant
The first run did not exercise dependency accounting because both source files were classified as unused entryless files. I’ll add manifest entry points and verify the symlink targets. If the resolver still preserves alias paths in this handcrafted layout, I’ll use an actual pnpm install (if available) or a focused resolver harness.
- Assistant
The symlinks were broken by one extra
.., which explains the fallback classification by import text rather than installed resolution. I’ll correct both links and rerun; this should reproduce the reported physical-source-name findings. - Assistant
The reproduction now exactly matches all four false positives. I’ll introduce a small helper that chooses the package name from a valid bare import specifier, falling back to the physical node_modules name for non-package aliases. Then I’ll apply it only at resolution points that currently derive
NpmPackagefrom a node_modules path, including style subpath resolution. This preserves physical names for unusual alias paths while making declared import names canonical. - Assistant
is_valid_package_nameaccepts package subpaths whileextract_package_namestrips them, andis_path_aliasexcludes known alias syntax. I’ll addpackage_usage_name(specifier, resolved_name)with those guards and replace the six physical-path result constructions. The failed-resolution branch already derives from the import and needs no change. - Assistant
The implementation is localized and leaves unresolved-import fallback behavior unchanged. I’ll format it, run the exact CLI reproduction again, and inspect all dependency-related arrays to confirm both aliases receive usage credit and no source names leak into findings.
- Assistant
The exact reproduction is fixed: both declared dependencies are used, neither resolved source name is unlisted, and the run has zero issues. Next I’ll run the graph crate’s complete test suite, since resolution behavior is concentrated there, then run the core integration test suite or at least its pnpm/catalog tests depending on runtime.
- Assistant
All 472 graph tests and the relevant catalog and Deno-scheme integrations pass. Edge-case review: ordinary packages are unchanged because imported and physical names match; scoped/subpath imports normalize to the declared package; npm aliases and JSR sources normalize to import names; known tsconfig/package-map aliases retain physical fallback names; direct
jsr:/URL imports still exit before this logic. I’ll run strict clippy for the changed crate and inspect the final diff/status before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.