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/package-resolution logic and relevant tests, then reproduce the alias mismatch before making a focused fix.
- Assistant
ripgrepis unavailable, so I’ll usegrep/find. The project is Rust; next I’m narrowing the search to resolver and lockfile crates and identifying the established fixture/testing conventions. - Assistant
The catalog analysis itself tracks declared keys, but the symptom indicates import resolution is replacing the source specifier’s package name with the installed package’s real
package.jsonname. I’ll inspect resolution and graph construction, plus the existing pnpm catalog fixture, to find where both identities are available. - Assistant
The
NpmPackage(String)result currently carries one name. I’m inspecting each construction path around package resolution; the likely safe correction is to derive that string from the original bare import specifier while still using the resolved path/package metadata for internal-vs-external classification. - Assistant
A lower-risk design is apparent: preserve the resolved package name in
ResolveResultfor resolution semantics, but make graph dependency accounting use the original import/re-export specifier forNpmPackageedges. This directly implements “declared/import name is canonical” without disrupting workspace detection. I’ll verify helper visibility and special schemes (npm:, packageimports, styles) before editing. - Assistant
The accounting rule needs one guard: only ordinary bare package specifiers should override the resolved identity.
npm:URL-like imports and#importsmappings should retain their existing normalized/resolved handling. I’ll now create an external temporary reproduction with pnpm-style alias symlinks (without modifying repository tests), run the CLI to confirm the reported false positives, and then patch graph accounting for static imports, dynamic imports, and re-exports uniformly. - Assistant
The temporary fixture and pnpm-style symlinks are ready; the first invocation only failed because the CLI crate has multiple binaries. I’ll rerun the intended
fallowbinary and inspect its argument layout if needed. - Assistant
fallowanalyzes the process working directory rather than accepting--cwd. I’ll execute Cargo from the fixture while pointing it at the repository manifest. - Assistant
Changing directories bypassed the repository’s toolchain file. I’ll pin the same toolchain via
RUSTUP_TOOLCHAIN=1.95and rerun. - Assistant
The reproduction exactly matches all four reported dependency findings, confirming the failure path. I’ll implement a small accounting helper that chooses the package name from an ordinary bare source specifier when the resolver classified it as external npm, while retaining target-provided names for
npm:imports, package import maps, and internal package modules. - Assistant
One edge case surfaced from the helper definitions:
is_bare_specifierintentionally includesnpm:and#imports. I’ll tighten “ordinary package import” to exclude path aliases/import maps and any URI scheme (:), preventing regressions in Deno npm imports and Node/package-map semantics, then validate the reproduction. - Assistant
The fixed binary removes all four false positives in the reproduction; only unrelated unused-file findings remain. The trailing Git check ran from
/tmpand therefore failed harmlessly. I’ll return to the repository, run the graph crate’s full test suite and the core catalog integration tests, then inspect lint/diff quality. - Assistant
All 520 graph tests and targeted catalog integration tests pass. The implementation also covers dynamic imports and re-exports because both flow through the same helper. I’ll run strict Clippy for the affected crate and broader dependency integration tests; if clean, I’ll review the final diff and repository status before submission.
- Assistant
Strict Clippy is clean, dependency-focused integration tests pass (including external package import-map targets), and the Deno
jsr:/npm:regression suite passes, confirming the guards preserve scheme behavior. I’ll run the complete core test suite as the final verification, then summarize the checklist and submit. - Assistant
Final review is clean: one source file changed, formatting and whitespace checks pass, and both complete affected-crate suites pass.
Checklist:
- If an error was reported in the issue description, I have successfully reproduced it. I built a temporary pnpm-style workspace with alias symlinks; before the fix it reported
@std/csvandunstorageas unused and@jsr/std__csvandunstorage-nightlyas unlisted. - If an error was reported in the issue description, I have confirmed that my fix resolves the error. Running the same CLI reproduction after the fix produced none of those four dependency findings.
- I have thought about edge cases and made sure my fix handles them as well. Accounting now uses the source package identity for normal bare imports, dynamic imports, and re-exports, while explicitly preserving existing behavior for /other schemes, , path aliases, internal package modules, and resolved target identity.
- If an error was reported in the issue description, I have successfully reproduced it. I built a temporary pnpm-style workspace with alias symlinks; before the fix it reported
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.