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.5Create
apps/cli/package.json:{ "name": "@example/cli", "type": "module", "dependencies": { "@std/csv": "catalog:" } }Create
apps/cli/src/output.ts:import { stringify } from '@std/csv/stringify'; console.log(stringify);Create
apps/native/package.json:{ "name": "@example/native", "type": "module", "dependencies": { "unstorage": "catalog:" } }Create
apps/native/src/storage.ts:import { createStorage } from 'unstorage'; console.log(createStorage);Run:
fallow dead-code --format jsonExpected behavior
Fallow should treat the package name used in package.json/imports as canonical for dependency analysis.
Expected:
@std/csvshould not be reported as unused@jsr/std__csvshould not be reported as unlistedunstorageshould not be reported as unusedunstorage-nightlyshould not be reported as unlisted
The resolver may need to preserve both names for pnpm package-source entries:
- declared/import name:
@std/csv,unstorage - resolved source name:
@jsr/std__csv,unstorage-nightly
Dependency usage should match against the declared/import name, not only the resolved source package name.
Fallow version
2.85.0
Operating system
macOS
Configuration
Interface
No new interfaces are introduced.
- Assistant
Investigating how Fallow resolves pnpm catalog entries and package-source aliases so we can fix the false positives.
- Assistant
Implementing a fix: when a bare import resolves via
node_modules, credit the import specifier's package name (as declared inpackage.json) instead of the physical pnpm-installed name. - Assistant
Implementing the helper and updating resolver call sites.
- Assistant
Fixed. When a bare import resolved through
node_modules, Fallow was crediting the physical package name from the resolved path (e.g.@jsr/std__csv,unstorage-nightly) instead of the name used in imports andpackage.json(e.g.@std/csv,unstorage). That mismatch caused false unused and unlisted dependency reports for pnpm package-source catalog entries.Root cause:
extract_package_name_from_node_modules_pathreads the installed directory name. pnpm package sources (jsr:,npm:alias@ver) can install under a different name than the declared catalog key.Fix: Added
package_usage_name_for_node_modules_importincrates/graph/src/resolve/path_info.rs. For bare specifiers, dependency usage now credits the import-side package name rather than the physicalnode_modulesname. The resolver uses this everywhere it maps a resolvednode_modulespath toNpmPackage.Tests added:
- Unit tests for the helper in
path_info.rs - Resolver test simulating pnpm virtual-store layout with JSR and npm alias packages
- Integration test (
issue_pnpm_package_sources.rs) matching your reproduction scenario
With this change,
@std/csvandunstorageare credited when imported, and@jsr/std__csv/unstorage-nightlyare no longer reported as unlisted. - Unit tests for the helper in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →