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: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
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /fallow, current file: none) bash-$
- Assistant
I’ll first inspect the repository structure and search for pnpm/catalog/package-source resolution code and relevant tests. Then I’ll reproduce the name mismatch, trace where the declared alias is lost, implement the narrowest general fix, and run the affected and broader test suites.
- Assistant
ripgrepis unavailable, so I’ll usegrep/find. The project is a Rust workspace; I’ll identify resolver and lockfile crates plus fixtures before running a targeted baseline. - Assistant
The catalog parser itself only tracks catalog usage; the symptom points to module resolution returning a package’s physical pnpm store identity. I’ll inspect dependency-analysis data flow—especially extraction of external imports, resolved paths, and package-name derivation—then inspect the existing JSR edge-case test for intended semantics.
- Assistant
I found
graph.package_usageis the canonical input to both findings. Next I’ll trace how eachResolvedImportcontributes to that map and inspect the resolver’sNpmPackageresult construction; that is likely where the physical package.json name overrides the import specifier. - Assistant
I’ll inspect
specifier.rsaround normal package resolution and physical package.json handling, along with result types and graph construction. I’ll also check dependency versions to understand whether the underlying resolver exposes the original module request separately. - Assistant
The fallback correctly uses
extract_package_name(specifier), so the bug must be in the successful-resolution branch. I’ll open the complete resolver function and path classification helpers, focusing on symlink/canonical pnpm paths and package manifest name lookup. - Assistant
The successful branch has several early and canonicalized paths. I’ll view it without truncation and inspect
extract_package_name_from_node_modules_path, since pnpm aliases likely producenode_modules/<declared-name>pre-canonicalization but.pnpm/<source-name>/node_modules/<source-name>after canonicalization. - Assistant
The defect is now clear: the resolver intentionally skips the pre-canonical package-name extraction for
.pnpm, canonicalizes the path, then extracts the source package name from the inner virtual-storenode_modules. For package-source aliases, that differs from the bare request name.Before editing, I’ll reproduce with a temporary workspace and realistic pnpm-style symlinks for both unscoped npm alias and scoped JSR-translated source. I’ll build/run the CLI and capture JSON findings.
- Assistant
The fixture was created, but Cargo requires selecting the
fallowbinary; no code has run yet. I’ll invoke that binary, checking help only if the root option placement is rejected, and then summarize dependency findings from the JSON envelope. - Assistant
The command produced JSON but my filter found no nonempty keys containing “depend”, suggesting either the fixture symlinks were malformed or output categories use different names. I’ll inspect the report and verify symlink targets/resolution directly.
- Assistant
The symlink targets were one directory too high, so resolution fell back to the import request name and did not reproduce. I’ll correct both links and mark source files as entry points to ensure dependency analysis includes them, then rerun the baseline.
- Assistant
The reproduction exactly matches the report. I’ll implement a resolver helper that, only for resolved paths inside pnpm’s virtual store and valid bare package requests, returns the package name from the original specifier rather than the canonical inner path. This keeps current behavior for relative imports, tsconfig/plugin aliases, and non-pnpm layouts, while covering JS and style resolution paths consistently. First I’ll inspect package-name validation semantics to avoid treating path aliases as package requests.
- Assistant
Validation is permissive, but
is_path_aliasreliably excludes the framework aliases most at risk. I’ll add two small private helpers inspecifier.rs: virtual-store detection by path component (cross-platform), and extraction that substitutes the original bare request name only in that case. Then I’ll use it at all node_modules classifications in the central JS/style resolver, leaving lower-level SCSS and explicit plugin fallback behavior untouched. - Assistant
The patch is localized and also replaces the previous byte-window path check with component-aware detection. I’ll rerun the exact reproduction and verify all four false positives disappear while imports remain resolved.
- Assistant
The reproduction is fixed: both declared aliases receive usage credit, neither physical source name is unlisted, and no imports are unresolved. I’ll now run the graph crate’s full tests (the directly affected layer), then core dependency-analysis tests/integration tests. I’ll identify exact Cargo package names first.
- Assistant
All 520 graph tests pass. Since the behavioral effect is consumed by core’s dependency analysis, I’ll run the full
fallow-corelibrary/unit and integration test suite rather than only a name-filtered subset. - Assistant
The full core run passed (2,477 library tests and 545 integration tests), including catalog and style-package coverage. I’ll run Clippy on the changed crate with all targets, inspect the final diff/status for accidental files, and remove the temporary reproduction (outside the repository) 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.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare 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 →