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: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
Investigating how Fallow resolves pnpm catalogs and package-source aliases so we can fix the false unused/unlisted dependency reports.
- Assistant
Implementing a fix: when a bare import resolves via
node_modules, credit the import specifier's package name instead of the resolved folder name (e.g.@jsr/std__csv). - Assistant
Fixed. When pnpm package sources resolve imports to a different folder name in
node_modules(e.g.@std/csv→@jsr/std__csv,unstorage→unstorage-nightly), Fallow was crediting dependency usage from the resolved path instead of the import specifier.Root cause
After a successful
node_modulesresolution,package_usage_name()came fromextract_package_name_from_node_modules_path(), which reads the installed folder name. For pnpm package sources that name differs from what appears inpackage.jsonand source imports.Fix
Added
package_usage_name_for_resolved_import()incrates/graph/src/resolve/path_info.rs. For bare import specifiers (not path aliases), it prefers the package name from the import specifier over the resolvednode_modulesfolder name. Applied everywhereNpmPackageis constructed from a resolved path inspecifier.rsandfallbacks.rs.Result
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.