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: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: - Assistant
I’ll first map the repository and locate pnpm/catalog resolution and dependency-usage logic, then reproduce the reported behavior with the project’s existing test or fixture conventions.
- Assistant
rgis unavailable, so I’ll usegrep/find. The repository is a Rust workspace; I’ll narrow the search to source and test files and inspect workspace crate roles. - Assistant
The catalog analyzer itself tracks declared keys correctly; the false names likely enter through module resolution, where
ResolveResult::NpmPackageis populated from the installed package’s resolved identity. I’ll trace every constructor and inspect the resolver data model before deciding where to preserve the import-facing name. - Assistant
I’ll inspect the primary specifier-resolution branches around package-name extraction and how graph package usage is recorded. The key invariant should be: resolution may use the physical package identity/path, but dependency accounting must use the source specifier’s declared package segment.
- Assistant
The resolver currently derives
NpmPackagefrom the resolvednode_modulespath, which explains both aliases exactly. Rather than expanding the public enum (a broad API change), the smallest robust fix is likely at graph construction: for external package edges, record the package name extracted from the original source while retaining the resolved target for path/workspace semantics. I’ll verify all source-edge forms expose the original source and assess special schemes (npm:, builtins, aliases) before editing. - Assistant
There is a second dependency-analysis path that builds import spans directly from resolved edges, so changing only graph aggregation would leave inconsistent unlisted reporting. I’ll inspect that function and then centralize “usage name for this edge” on
ResolvedSourceEdge, deriving from the source only when the target is package-bearing. This preserves handling for internal aliases and unresolvable paths. - Assistant
A naive source extraction would regress Deno
npm:imports (npm:preact@10/hooks) and potentially other non-package source forms. I’ll review existing npm-scheme tests and resolver fallbacks, then implement an edge method that uses the import-facing name for ordinary bare package specifiers while retaining the resolver’s name for explicit schemes or non-bare sources. - Assistant
The safe rule is now clear: only
NpmPackageedges with an ordinary valid bare source should receive source-name credit; explicit schemes and path/import-map aliases keep the resolver-provided identity. I’ll first create a temporary pnpm-like fixture outside the repository and run the CLI to confirm the exact baseline, including physical symlinks whose canonical paths expose the alternate source names. - Assistant
The fixture is ready; Cargo only required selecting the
fallowbinary. I’ll rerun the baseline command. - Assistant
The baseline reproduces all four dependency errors (
unused_dependencies: 2,unlisted_dependencies: 2). I’ll extract their names for a precise record, then make the centralized edge-aware usage-name change in the graph type and update both consumers. - Assistant
I’ll avoid allocations and preserve lifetimes by adding a borrowed package-name extractor, then expose
package_usage_name_for_sourceon the resolved target plus a convenience method on source edges. Ordinary imports such as@std/csv/stringifybecome@std/csv;npm:...,#..., and path aliases continue using the resolver identity. - Assistant
The implementation is in place across graph aggregation and span attribution. I’ll compile and run focused graph/core tests first; then rerun the external reproduction to verify both categories disappear.
- Assistant
The focused graph tests pass. The chained command stopped because
dead-codecorrectly exits nonzero for the fixture’s unrelated unused-file findings, not due compilation or a test failure. I’ll inspect the generated JSON directly and run the entire core library test suite rather than relying on a filter that selected no tests. - Assistant
The reproduction is fixed, but one existing test exposes an important edge case: plugin virtual-package suffix filtering intentionally relies on the resolver-provided synthetic identity (
some-pkg/__mocks__) even when the source issome-pkg. I’ll inspect the fixture and plugin suffix flow to refine canonicalization narrowly enough for real installed aliases without breaking virtual-package semantics. - Assistant
The synthetic helper uses the same string for source and target; canonicalizing a subpath necessarily removes the suffix. Real imports also need package root for dependency accounting, while virtual suffix checks need the raw source/target. The clean fix is not to preserve malformed package names in the graph; instead, make virtual suffix filtering inspect source specifiers from the already-built span index. I’ll confirm the helper shape and add a per-package check that recognizes matching raw sources without altering canonical dependency names.
- Assistant
I’ll update virtual suffix handling to test both the canonical package key and its original import sources. This preserves the plugin contract for
pkg/__mocks__while allowing package accounting to correctly canonicalize all ordinary package subpaths. - Assistant
All 2,477 core library tests now pass. I’ll review remaining uses of the old target-only method and run Clippy/checks; this ensures no dependency-accounting path still emits resolved source names and catches API/style issues.
- Assistant
Clippy passes and no target-only accounting consumer remains. I noticed the virtual-suffix compatibility check can be made linear rather than scanning every import for every package, so I’ll precompute the canonical package names associated with matching virtual sources before the main loop.
- Assistant
The optimization edit did not apply because the exact formatted text differed, but the subsequent full graph/core suites and Clippy still passed on the correct functional implementation. I’ll inspect the local section and apply the optimization against its actual formatting.
- Assistant
I’ll insert the precomputed set immediately after span collection and replace the nested suffix scan with a set lookup.
- Assistant
The insertion matched an earlier
ignore_depsdeclaration in another function, causing the expected compile error; no logic ambiguity, just placement. I’ll remove that misplaced block and insert it afterimport_spans_by_fileinfind_unlisted_dependencies, then rerun checks. - Assistant
The optimized compatibility path now compiles, its regression test passes, and Clippy is clean. I’ll do the final verification pass: rerun the exact reproduction, full affected test suites, and inspect the final diff/status for accidental files or misplaced code.
- Assistant
Final reproduction and full affected suites pass. I’ll inspect the complete diff once more, especially the virtual-suffix precomputation placement and borrowed scoped-name slicing, 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.