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:yamlpackages: - apps/* catalog: '@std/csv': jsr:1.0.6 unstorage: npm:unstorage-nightly@2.0.0-alpha.5The package manifests depend on the declared names:
json{ "dependencies": { "@std/csv": "catalog:" } }json{ "dependencies": { "unstorage": "catalog:" } }Source imports also use the declared names:
tsimport { stringify } from '@std/csv/stringify';tsimport { createStorage } from 'unstorage';But Fallow can report the declared package names as unused:
json{ "package_name": "@std/csv", "location": "dependencies", "path": "apps/cli/package.json" }json{ "package_name": "unstorage", "location": "dependencies", "path": "apps/native/package.json" }And report the resolved package-source names as unlisted:
json{ "package_name": "@jsr/std__csv", "imported_from": [ { "path": "apps/cli/src/output.ts" } ] }json{ "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:
Assistant
Let me explore the repository structure first to understand what we're working with.
Assistant
This is a Rust project. Let me explore the crates directory to understand the structure.
Assistant
Let me explore the resolver and dependency analysis code to understand how package names are resolved.
Assistant
Let me look at the specifier resolution and how
jsr:andnpm:are handled in the resolver.Assistant
Now I understand. The
jsr:specifier returnsExternalFile(PathBuf::from(specifier))which keeps the originaljsr:@std/csv/stringifyspecifier. So how does it become@jsr/std__csv?Let me look at how the resolved package name is determined for
jsr:imports. The issue says it reports@jsr/std__csvas unlisted. Let me search for where thejsr:or@jsrtransformation happens.Assistant
Now I understand the flow. Let me look at how
jsr:and bare specifiers resolve through node_modules. The key is thatimport { stringify } from '@std/csv/stringify'is a bare specifier that resolves through node_modules where pnpm has set up the actual package at@jsr/std__csv. Let me look at how dependency usage and unlisted/unused deps are computed.Assistant
Now let me look at how
graph.package_usageis populated and how the resolution maps to the actual package.Assistant
Now I understand the flow. The bare specifier
@std/csv/stringifyresolves through node_modules where pnpm has set up the actual package@jsr/std__csv. Let me look at how pnpm catalogs and package sources are parsed.Assistant
Let me look at the full resolution flow for bare specifiers to understand how
@std/csv/stringifygets resolved to@jsr/std__csv.Assistant
Let me set up the reproduction to understand the actual resolution behavior. First, let me check what's available.
Assistant
pnpm 9 is installed. Now let me set up the reproduction.
Assistant
The pnpm version 9 doesn't support jsr. Let me try installing the latest pnpm that supports jsr. I need Node.js v22.13+. Let me install a newer Node.js.
Assistant
Now let me look at the node_modules structure to understand how pnpm resolves these packages.
Assistant
Now I understand the structure. Let me build fallow and run it on the reproduction to confirm the issue.
Assistant
The output shows
unlisted_dependencies: []andunused_dependencies: []- but the files are reported as unused. Let me check the full output and add entry points to make this realistic.Assistant
The files are reported as unused because there are no entry points. Let me add entry points.
Assistant
Interesting, the issue isn't reproducing in this simple case. Let me add some debug tracing to understand what's happening with the resolution.
Assistant
Let me add temporary debug tracing to understand what path oxc_resolver returns.
Assistant
Let me add a temporary debug eprintln to print the resolved path for bare specifiers. Let me look at line 1100-1130 where the resolved path is processed.
Assistant
Now I can see the issue! oxc_resolver resolves through the symlink and returns the canonical
.pnpmpath. The resolved path contains/.pnpm/, so the first check is skipped. Let me look atextract_package_name_from_node_modules_pathto understand how it parses.pnpmpaths.Assistant
Let me check the full output more carefully for
@jsrorunstorage-nightly:Assistant
No matches at all! Let me check
should_preserve_node_modules_style_fileand understand what's happening with the resolution result.Assistant
Let me add a debug print in
record_package_usageto see what package names are being recorded.Assistant
So
package_usagecontains@jsr/std__csvandunstorage-nightly, but the output shows NO unlisted deps. Let me check if there's a mapping somewhere that handles these. Let me search for where these might be filtered or mapped.Assistant
Let me look at the full unlisted dependencies loop to see all the filters.
Assistant
Let me add a debug print in the unlisted dependencies loop to trace whathappens.
Assistant
No output from DEBUG_UNLISTED_ITER. That's strange. Maybe
find_unlisted_dependenciesis not being called, or thepackage_usagebeing used here is different. Wait, the grep returned exit code 1 because no matches. Let me check if the function is even called.Actually, wait. Maybe the issue is that
find_unlisted_dependenciesis called per-workspace, and the graph passed in is per-workspace, or maybe it's not called at all for this small project. Let me check the orchestration.Actually, let me just check if the debug print appears at all without filtering.
Assistant
find_unlisted_dependenciesis NOT being called! Let me check the orchestration.Assistant
The issue is
find_unlisted_dependenciesis only calledif let Some(ref pkg) = pkg(root package.json). My reproduction has no rootpackage.json. Let me add one.Assistant
Now the issue reproduces. Let me see the full output of unused and unlisted dependencies.
Assistant
Now the issue reproduces. Let me remove the debug prints and understand the root cause better. The problem: bare specifier
@std/csv/stringifyresolves through.pnpmto a path whose extracted package name is@jsr/std__csv, but we should credit@std/csv(the declared/import name).Let me check if there's any existing pnpm lockfile parsing that maps resolved names to declared names.
Assistant
No lockfile parsing. Let me look at the pnpm.rs plugin and unused_overrides.rs to understand existing pnpm handling.
Assistant
Let me look at
package_name_from_lock_keyto understand the lock key format and the npm alias handling. This is relevant to understanding the pnpm conventions.Let me look at the
package_name_from_lock_keyfunction.Assistant
Let me look at the
is_bare_specifierandis_path_aliasfunctions to understand edge cases.Assistant
Now I have a clear understanding. Let me first remove my debug prints, then implement the fix.
Assistant
Now let me add the helper function in
path_info.rs:Assistant
Now let me add the helper function after
extract_package_name:Assistant
Now let me check the imports in
specifier.rsto make surecredited_package_name_from_specifieris accessible:Assistant
Let me add
credited_package_name_from_specifierto the import:Assistant
Let me use the edit command instead. First let me open the file.
Assistant
Now let me look at the canonical branch where
NpmPackage(pkg_name)isreturned:Assistant
Let me look at each location:
Assistant
These are in some helper function. Let me check what function this is (around line 920).
Assistant
Let me look at the main
resolve_specifierbranches at 1149, 1179, 1209, and 1276:Assistant
Now I understand the structure. The fix should be applied in the canonical branch (line 1179) and the Err fallback branch (line 1209) where
.pnpmpaths land and the installed name differs from the declared name. Let me also apply it to the style resolution helper for consistency. Let me make the edits:Assistant
Line 1276 already uses the specifier name directly, so no change needed there. Let me apply the fix to the canonical Ok branch (1179), Err fallback branch (1209), and the style resolution helper (953, 976). Let me make these edits:
Assistant
Now let me apply the fix. Let me edit the canonical Ok branch (line 1179) using its distinguishing context (
&canonical):Assistant
Now I can see the exact context. Let me edit line 1179 (canonical Ok branch):
Assistant
Now let me edit line 1209 (Err fallback branch):
Assistant
Now let me handle the style resolution helper for consistency. Let me check its current state:
Assistant
Let me apply the fix to the style resolution helper too (lines 953, 976, 982):
Assistant
I introduced a duplicate closing brace. Let me fix that:
Assistant
Now line 976 (canonical branch in style helper) and line 981-982 (the
.map):Assistant
Now the
.map(ResolveResult::NpmPackage)at line 982:Assistant
Let me check the first check (non-canonical) at line ~1149 - this excludes
.pnpmpaths and uses the symlink path name, which should already be correct:Assistant
The first check (line 1151) excludes
.pnpmpaths and uses the symlink path name which is always the declared name - so it's already correct. Now let me verify the resolve_specifier changes are correct (line numbers shifted):Assistant
The changes look good. Now let me build and verify:
Assistant
Build succeeds. Now let me run the reproduction to verify the fix:
Assistant
The fix works. No more false positives. Let me verify the package_usage now credits the declared names by checking the full output:
Assistant
The fix works - no false positives. Let me verify the
jsr:import specifier (not bare) case is also handled. Let me check what happens with a directjsr:import:Assistant
Let me run the existing tests to make sure I didn't break anything. Let me start with the graph resolve tests and the relevant coretests:
Assistant
All graph tests pass. Let me run the path_info tests specifically and the core integration tests related to dependencies:
Assistant
All core tests pass. Now let me run the integration tests related to dependencies and the supabase edge case (issue #624 which deals with
jsr:/npm:schemes):Assistant
All 545 integration tests pass. Now let me test the edge case where a package is imported by the resolved name directly (should still be reported as unlisted if not declared). Let me create a test with a direct npm alias in package.json:
Assistant
The direct npm alias case works too. Now let me test the negative case - a genuinely undeclared package should still be reported as unlisted. Let me also verify that importing the resolved name directly without declaring it is correctly flagged:
Assistant
The fix correctly handles the edge case - importing the resolved name directly (without declaring it) is still correctly flagged as unlisted, and declared-but-unused deps are still flagged. This confirms the fix is general and correct.
Let me run the broader test suite to ensure nothing is broken:
Assistant
Let me run the CLI tests and check for any pnpm-specific tests:
Assistant
Let me check if this failure is related to my change or pre-existing:
Assistant
This test failure (
resolves_npm_sidecar_from_node_modules_root) looks unrelated to my change - it's about runningnpm rootas a subprocess. Let me verify it's pre-existing by stashing my changes:Assistant
Interesting - the test passes in isolation. This is likely a flaky test that depends on the
npmbinary I installed. Let me re-run the full CLI suite to confirm it's flaky and unrelated to my change:Assistant
The test passes now - it was a flaky test unrelated to my change (it spawns an
npmsubprocess). Let me run the full CLI suite once more to confirm stability:Assistant
Another flaky/environment-specific test (
fix_batch_aborts_when_a_target_directory_is_read_only) - this is about read-only directory permissions, which behaves differently when running as root. Let me verify both failures are pre-existing/environment-related by stashing:Assistant
Confirmed - both failing tests are pre-existing/environment-related (the
fix_batch_aborts...fails identically on original code because we run as root; the npm sidecar test is flaky). My changes don't break any tests.Let me run clippy on the changed crates to ensure code quality:
Assistant
No clippy warnings. Let me run rustfmt to ensure formatting is correct:
Assistant
Let me apply rustfmt to fix the formatting:
Assistant
Formatting is now correct. Let me rebuild and re-run the reproduction one final time to confirm everything works after formatting:
Assistant
The reproduction now reports 0 issues - exactly matching the expected behavior. Let me run the full graph and core test suites once more to confirm everything passes after formatting:
Assistant
All tests pass. Let me review the final diff of my changes:
Assistant
The diff is clean and focused. Let me verify there are no leftover debug changes or temp files in the repo:
Assistant
Only the two intended files are modified. Let me verify no debug statements were left behind:
Assistant
No debug statements remain. Let me run one final comprehensive test to confirm the fix handles the exact reproduction from the issue (using
apps/cliandapps/nativeas specified):
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.