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
This is a Rust project. Let's search for "jsr:" and "package-source" handling.
Assistant
Now let's add the helper function right after
is_node_modules_path:Assistant
Now let's update the two branches at lines ~1167 (canonical Ok) and ~1194 (canonicalize Err), and the style-resolution branch at ~973/981.
Assistant
Now let's handle the main function's branches (previously at ~1149 fast path, ~1179 canonical-Ok, ~1209 canonical-Err).
Assistant
Now let's edit this block (Ok and Err branches only, since fast-path at 1187-1205 never touches
.pnpmpaths already).Assistant
Now update the
elsebranch right after that (the NpmPackage(pkg_name) for the Err case that isn'tshould_preserve_node_modules_style_file):Assistant
Now let's build.
Assistant
Builds fine. Now let's build the CLI and re-run the reproduction.
Assistant
The false positives are gone. Now let's run existing tests, especially in the graph crate for resolve/specifier, and broader test suite for regressions.
Assistant
All graph tests pass. Let's run the full test suite for the workspace briefly, at least core and cli crates, to check for regressions.
Assistant
All pass. Let's check for other test files (there might be more test binaries in fallow-core).
Assistant
All pass. Let's also run cli tests and full workspace test to be safe.
Assistant
Confirmed this failure is pre-existing (running as root ignores read-only perms) and unrelated to our change. Let's restore our changes.
Assistant
Now let's run the rest of the workspace tests (skipping this known pre-existing failure) to make sure nothing else broke.
Assistant
All other tests pass; the only failure is the pre-existing root-permission issue unrelated to this change. Now let's review our diff for correctness and clippy lints.
Assistant
Now let's run clippy to check for lint issues.
Assistant
No clippy warnings. Now let's also check other places, e.g.
unused_deps.rsnpm: normalization mentions — maybe there's also a similar issue for therequire/dynamic importcode paths for bare specifiers resolving into pnpm store (not just static imports). Let's checkresolve_all_importsor wherever elseextract_package_name_from_node_modules_pathis called (outside specifier.rs).Assistant
That's just a proptest, not related. Now let's check
external_style_usage.rsusage - this is about crediting style usage, in core crate, used for detecting unused SCSS/style dependencies. Let's check if similar issue could occur there.Assistant
Correctly resolved with no false positives. Now let's verify that an actually unlisted dependency (not declared anywhere) still gets correctly reported even when it resolves through the pnpm virtual store — i.e., ensure we didn't break genuine unlisted-dependency detection.
Assistant
Genuine unlisted dependencies are still correctly reported with the real name (since specifier itself is "ghost-pkg" and it's genuinely unlisted). Let's clean up the temporary repro directory and finalize.
Assistant
Let's also check for a CHANGELOG entry convention to see if this repo expects changelog updates (not required, but let's check quickly).
Assistant
Good. Now let's build the CLI once more with these final changes (no code changes beyond changelog) and run the full test suite once more as a final sanity check.
Assistant
Build succeeds. Let's do a final diff review.
Assistant
This looks good. Let's do one more full test run to be thorough before submitting.
Assistant
All relevant tests pass. Let's review the checklist items now.
Checklist review
- Reproduced the error: Yes — I built a synthetic pnpm workspace mimicking real pnpm virtual-store layout (
node_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csvsymlinked fromnode_modules/@std/csv, and similarly forunstorage/unstorage-nightly), and confirmedfallow dead-codereported@std/csv/unstorageas unused and@jsr/std__csv/unstorage-nightlyas unlisted, exactly matching the issue. - Confirmed the fix resolves the error: Yes — after the fix, the same reproduction produces zero issues (no unused/unlisted dependency false positives).
- Thought about edge cases: Verified (a) a genuinely unlisted dependency resolved through the
.pnpmstore is still correctly reported under its real name (no regression to true positives), (b) directnpm:aliasing without a catalog ("foo": "npm:bar@^1.0.0") is credited correctly too, (c) normal (non-aliased) packages resolved through are unaffected since declared and resolved names already match, (d) workspace-package detection via -routed symlinks is untouched since that check still uses the path-derived name before the new override applies, (e) applied the same fix to the SCSS/style bare-specifier resolution path for consistency.
- Reproduced the error: Yes — I built a synthetic pnpm workspace mimicking real pnpm virtual-store layout (
Assistant
This diff looks complete and well-scoped. Let's submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.