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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the crate structure.
Assistant
Let me look at the project structure and resolver logic, especially for catalogs and package sources.
Assistant
Let me look at the dead-code analysis flow.
Assistant
The key issue is in how the dead-code analysis maps resolved package names back to declared package names. Let me understand the flow. The imports are resolved through the resolver. When pnpm uses
jsr:ornpm:package sources via catalogs, the resolver might resolve the import@std/csvto a node_modules path that points to@jsr/std__csv.Let me look at how unused_deps and the dead-code analysis work, and how package names get compared.
Assistant
The
graph.package_usageis the source of truth for what packages are used in imports. Let me look at howpackage_usageis populated, and especiallypackage_usage_name().Assistant
Let me look at how the specifier is resolved and how the NpmPackage name is derived.
Assistant
Let me see the rest of
resolve_specifierwhere bare specifiers get resolved.Assistant
Let me understand how pnpm workspace/catalog info is parsed and available in the resolve context.
Assistant
Let me see the helper function around line 950 and the broader context.
Assistant
Let me look at
extract_package_nameandextract_package_name_from_node_modules_path.Assistant
Let me see what function contains line 950 and check the full set of NpmPackage construction sites.
Assistant
So line 950 is inside
try_style_condition_package_resolution. Let me also find the function containing line 1003 (the main resolve_specifier) and the helper at line ~940-960 in a different function. Let me find allNpmPackage(construction sites with line numbers.Assistant
Let me look at each NpmPackage site with surrounding context.
Assistant
Let me look at the ResolveContext struct to see what data is available.
Assistant
Let me check how the resolve functions call resolve_specifier and whether there are other NpmPackage construction sites.
Assistant
There are also NpmPackage sites in fallbacks.rs. Let me examine those.
Assistant
Now I understand the architecture. The fix: when a bare import specifier resolves to a
node_modulespackage whose physical name differs from the package name derived from the import specifier (due to pnpm package sources, npm-protocol aliases, or overrides), credit the specifier-derived (declared/import) name as canonical for dependency accounting.Let me first reproduce the issue with a test fixture to confirm. Let me check existing pnpm catalog tests for patterns.
Assistant
Let me look at the existing issue-329 fixture to understand fixture structure with node_modules.
Assistant
Let me look at existing resolver tests that set up pnpm node_modules structures.
Assistant
Let me look at the jsr/npm specifier tests and the test helper that builds a ResolveContext.
Assistant
Let me find a test that resolves a bare specifier to a real node_modules package and checks the NpmPackage name, to model my reproduction.
Assistant
Let me look at the test around line 1439 that builds a real ctx.
Assistant
I'll create a temporary standalone reproduction test. Let me first check the public API for unused/unlisted dependencies.
Assistant
Let me look at how the integration test common creates a config and how analyze is called, and what
AnalysisResultscontains for unused/unlisted. Let me look at the common module and the dead-code integration. Actually, let me look at how dead-code is computed. The issue mentionsfallow dead-code. Let me check how that maps to results. Thedead-codecommand combines unused files, exports, dependencies, etc. Let me find the dead-code command.Assistant
Let me look at the integration test common helpers to build a config.
Assistant
Let me check the AnalysisResults struct fields.
Assistant
Now let me create a temporary reproduction test to confirm the bug.
Assistant
I've reproduced the bug exactly as described. Now let me implement the fix. First, add a helper function to
path_info.rs.Assistant
Now let me add the helper function after
extract_package_namein path_info.rs:Assistant
Let me insert the helper using the edit command. I'll edit the line range that contains the closing of extract_package_name and the start of the normalize comment. Lines 78-83 are the end of extract_package_name. The blank line 82, then line 83 is the doc comment for normalize_npm_specifier. Let me insert between line 81 (closing brace) and 83 (doc comment). I'll replace line 82 (blank) with the helper plus blank.
Actually let me use the
editcommand with a line range. Line 82 is blank. I'll replace lines 82:82 (the blank line) with the helper text followed by a blank line.Wait, but the helper references
is_bare_specifier,extract_package_name,is_valid_package_namewhich are defined above in the same file. Good.Let me open the file first.
Assistant
The
[must_use]needs a#. Let me fix that.Assistant
The sed didn't match because of the bracket. Let me check the actual bytes.
Assistant
Now let me export the helper from the resolve module:
Assistant
Now let me update the import in specifier.rs and apply the helper at the construction sites. First check the imports in specifier.rs:
Assistant
Now let me look at all the sites to apply the helper. Let me view each occurrence with context to confirm variable names.
Assistant
Let me view site 982 (the
.mapform) in context:Assistant
Now let me apply the helper at each construction site. Let me view the exact text at each site and do targeted replacements.
Assistant
Now sites 1149, 1179, 1209 in resolve_specifier. Let me view their exact context.
Assistant
Now let me apply the helper at sites 1155, 1185, 1215:
Assistant
Let me also update the
.map(ResolveResult::NpmPackage)form in the style function for consistency:Assistant
Now let me build and run the reproduction test:
Assistant
The fix works. Now let me run the existing test suites to ensure no regressions.
Assistant
All graph tests pass. Now let me run the core integration tests for dependencies and pnpm catalogs.
Assistant
All integration tests pass. Let me run the core unit tests too.
Assistant
Let me also run config and types tests to be safe.
Assistant
Let me verify the unused-dependencies (not unlisted) analysis also uses
graph.package_usageso the fix fully addresses both directions.Assistant
Both directions use
graph.package_usage, which is built frompackage_usage_name()— the fix flows through both. Now let me remove the temporary test file and run clippy on the changed crate.Assistant
No clippy warnings. Let me run clippy including tests for the graph crate.
Assistant
Let me run rustfmt to ensure formatting matches the repo style.
Assistant
Let me review the final diff to make sure everything is correct.
Assistant
The diff is clean. Let me do a final workspace build to ensure nothing else broke from the new public export.
Assistant
The build is clean. Let me do a final review of the checklist before submitting.
Let me verify the reproduction one final time by re-confirming the test passes with the fix (re-create temporarily, run, remove):
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 →