False positives for pnpm package source aliases What happened? fallow dead-code reports…
- User
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:packages: - apps/* catalog: '@std/csv': jsr:1.0.6 unstorage: npm:unstorage-nightly@2.0.0-alpha.5 - Assistant
Investigating how Fallow resolves pnpm catalogs and package sources so we can fix the false positives.
- Assistant
Implementing the fix: when a bare import resolves via
node_modules, credit the import specifier's package name instead of the canonicalized install path (pnpm package-source aliases). - Assistant
Fixed. Fallow was crediting the physical
node_modulespackage name after symlink canonicalization instead of the name used in imports andpackage.json.Root cause
When pnpm installs catalog entries like
'@std/csv': jsr:1.0.6orunstorage: npm:unstorage-nightly@..., it symlinks the declared name to the resolved install. The resolver followed those symlinks viacanonicalizeand extracted the resolved name (@jsr/std__csv,unstorage-nightly) for dependency usage tracking — whilepackage.jsonand source imports use the declared names (@std/csv,unstorage).Fix
Added
npm_package_usage_name()incrates/graph/src/resolve/path_info.rs. When a bare, non-alias import resolves intonode_modulesand the specifier's package name differs from the physical install folder, the declared/import name is credited instead.Applied at every
NpmPackageconstruction site that derives the name from a path in and .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.