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
Interface
No new interfaces are introduced.
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 start by exploring the repository structure and understanding how fallow handles pnpm package sources and dependency resolution.
- Assistant
Let me search for pnpm catalog and package source handling in the codebase.
- Assistant
rg is not available, let me use grep instead.
- Assistant
There's existing pnpm catalog support. Let me inspect the relevant modules for how declared vs resolved package names are handled.
- Assistant
Let me look at the pnpm catalog related code and graph resolution more carefully.
- Assistant
I'll inspect how unused/unlisted dependencies are computed and how package names are resolved from node_modules.
- Assistant
I'll inspect how package_usage is built and how resolved package names are mapped back to declared names.
- Assistant
Looking at how package names are extracted from resolved paths — that is likely where the alias mismatch happens.
- Assistant
The issue appears to be snapshotting the resolved package path name; next I'll inspect how import specifiers map to package usage names.
- Assistant
Let me continue reading the resolve_specifier function.
- Assistant
I'll look at extract_package_name and any existing alias handling.
- Assistant
Let me read path_info.rs for extract_package_name.
- Assistant
There's existing related logic around line 897 in fallbacks.rs — let me inspect it.
- Assistant
I'll search for existing tests and history related to pnpm aliases and JSR package sources.
- Assistant
Let me check how package_usage is recorded during graph building.
- Assistant
Checking package.json dependency parsing and any existing alias map handling.
- Assistant
I'll inspect existing pnpm catalog tests and fixtures, then reproduce the issue.
- Assistant
I'll scan unit tests around node_modules package name extraction and review the resolve helpers more carefully.
- Assistant
I'll craft a minimal reproduction that mirrors pnpm package-source alias layouts.
- Assistant
I'll write a temporary unit test that simulates a pnpm alias layout and shows how the package name is credited.
- Assistant
I need to fix the reproduction layout — the symlinks were set up incorrectly.
- Assistant
The virtual store should live under
node_modules/.pnpmin a real pnpm layout — fixing that. - Assistant
I'll build fallow and run it against the reproduction project.
- Assistant
Need to fix the package name and rebuild.
- Assistant
Running fallow against the reproduction fixture.
- Assistant
Let me check the CLI flags.
- Assistant
Maybe it uses cwd or a positional path.
- Assistant
Use -r flag
- Assistant
I've reproduced the issue. Next I'll add a helper that prefers the import specifier's package name and wire it into the resolve path.
- Assistant
Let me check the fallbacks call sites for available specifier context.
- Assistant
I'll add a helper to prefer the bare import name and apply it wherever
NpmPackageis created from a resolved path. - Assistant
I'll add unit tests and update the call sites next.
- Assistant
Updating specifier.rs to use the helper.
- Assistant
I'll update the import and all the sites that create NpmPackagefrom path.
- Assistant
Updating each place in specifier.rs that builds
NpmPackage. - Assistant
I'll replace the three blocks in try_style_condition_package_resolution and then the main resolve_specifier blocks.
- Assistant
Updating the main resolve_specifierpath extraction sites next.
- Assistant
I'll replace the three NpmPackage(pkg_name) usages in this section.
- Assistant
Updating the SCSS node_modules fallback to prefer the bare package name.
- Assistant
Update fallbacks for scss_node_modules. For path alias that resolves to node_modules, using path Treg is more correct for plugin aliases that map to packages.
- Assistant
The first replace worked; I'll re-read the SCSS block and update it.
- Assistant
Let me try replace again with exact content.
- Assistant
Checking for other NpmPackage construction sites and whether the helper should be exported.
- Assistant
I'll inspect the remaining NpmPackage construction sites that still need the helper.
- Assistant
Rebuilding and verifying the fix against the reproduction.
- Assistant
False positives are gone. I'll run the graph unit tests and a basic dependency fixture to check for regressions.
- Assistant
All graph tests passed. Next I'll run the dependency-related core integration tests.
- Assistant
Need to use a filter pattern properly.
- Assistant
Repository rules forbid adding tests, so I'll remove the unit tests I added in path_info.rs.
- Assistant
I need to open the file around those lines first.
- Assistant
I'll check
.claude/rules/detection.mdfor where this behavior should be documented. - Assistant
I'll document this under the Resolution-level section in detection.md.
- Assistant
Verifying npm protocolaliases work without catalogs as well.
- Assistant
I'll quickly check that ordinary non-aliased packages still report correctly.
- Assistant
Final review of the changes before submitting:
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →