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
Let me start by exploring the repository structure to understand the codebase and find relevant files for this issue.
Assistant
Let me explore the crates structure to understand the codebase.
Assistant
Let me look at the dependency resolution and analysis code.
Assistant
The issue is about package source resolution. Let me look at the resolver code where dependencies are resolved. Let me search for where the dependency names come from when matching imports.
Assistant
Let me look at the unused_deps analysis and how dependency names are extracted.
Assistant
Let me look at
package_usage_name()andpackage_usage.Assistant
Let me look at the resolve code that produces
NpmPackageresults.Assistant
Let me look at
extract_package_name_from_node_modules_pathand the surrounding resolution code. The key issue: when the resolution returns the package name from the resolved node_modules path, it gets the resolved source name (e.g.,@jsr/std__csv), not the declared/import name (@std/csv).Let me understand the resolution flow. The import specifier is
@std/csv/stringify. The resolver resolves this to a path in node_modules. With pnpm, the actual installed package directory might benode_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@std/csv(pnpm creates a symlink atnode_modules/@std/csvthat points to the actual package). Wait, actually with pnpm, when you do@std/csv: jsr:1.0.6, pnpm createsnode_modules/@std/csvsymlink that points tonode_modules/.pnpm/@jsr+std__csv@1.0.6/.... So the resolved path would go through the symlink.But the issue says it reports
@jsr/std__csvas unlisted. So somewhere the canonicalization resolves the symlink and gets the real package directory name@jsr+std__csvand extracts@jsr/std__csv.Let me look at
extract_package_name_from_node_modules_path.Assistant
Now let me look at the resolution function around line 950 in specifier.rs.
Assistant
Let me look at the existing pnpm catalog test to understand the test setup.
Assistant
Let me check the oxc_resolver configuration to understand symlink handling.
Assistant
The default
ResolveOptionshassymlinks: true(default). Let me check the oxc_resolver default. Actually, in oxc_resolver, the defaultsymlinksfield is... Let me check. Actually let me look at the resolve tests to understand the symlink behavior.Let me look at the resolve test at line 1716.
Assistant
Let me check the available tooling and try to reproduce the issue.
Assistant
No node/pnpm available. Let me look at the resolve tests harness to write a reproduction at the resolver level.
Assistant
Let me look at a test that uses
specifier::resolve_specifieror the public resolve entry. Let me check how tests call resolution.Assistant
Let me look at how tests build a real context and call resolution with actual node_modules.
Assistant
Let me search for tests that build a full ResolveContext and call resolve_specifier with node_modules.
Assistant
Let me look at the full ResolveContext struct.
Assistant
Let me write a reproduction test that mimics the pnpm symlink structure. First, let me create a temporary test file.
Assistant
I made a mistake with the
build_ctxhelper. Let me remove that. Let me fix the test file. Actually, let me just remove the unused helper function.Assistant
Now I need to register this module. Let me check the resolve mod.rs to add
mod repro_test;.Assistant
Now let me run the reproduction test to confirm the bug.
Assistant
I've reproduced the bug. The resolution returns
@jsr/std__csvinstead of@std/csv. Let me look atextract_package_nameand how the specifier name is derived.Assistant
I've reproduced the bug. Now let me understand all consumers of
package_usage_nameandpackage_usageto ensure my fix is complete.Assistant
Let me check
trace.rsandlib.rsconsumers to understand the full impact.Assistant
Let me look at the resolve tests that check
NpmPackagenames to understand current behavior expectations.Assistant
These tests use
with_empty_ctxwhich has empty lookup tables, so resolution fails and goes to the failed branch which usesextract_package_name(specifier). So these pass with the specifier name.Now, the success branch (when the package IS installed) uses
extract_package_name_from_node_modules_path. For the normal case, the resolved name == specifier name. So tests with installed packages would expect the resolved name == specifier name.Let me look at the tests at lines 520-670 and 940-1080 which seem to involve actual resolution with node_modules.
Assistant
Let me look at the tests around lines 520-670 and 790-810 which involve resolution with actual node_modules.
Assistant
Let me look at integration tests with real node_modules fixtures to understand expectations.
Assistant
Let me check if any test fixtures use the
.pnpmvirtual store structure.Assistant
Let me check where
NpmPackagename is consumed beyondpackage_usage_name.Assistant
Let me see all usages of
extract_package_name_from_node_modules_pathto understand the scope.Assistant
Let me look at the exact code in the canonical and Err branches (sites 1139-1212) and the helper for
.pnpmdetection.Assistant
Let me look at the fallbacks.rs sites and the style resolution sites.
Assistant
Let me check the test fixtures for nested node_modules or scenarios where a bare specifier might resolve to a differently-named package.
Assistant
I have a clear understanding now. Let me check how path_info functions are imported in specifier.rs and fallbacks.rs.
Assistant
Let me check if there's an existing
.pnpmpath helper and look at the path_info tests.Assistant
Let me check for any tsconfig paths mapping to node_modules packages (a concern for the general approach).
Assistant
Let me check the imports in path_info.rs.
Assistant
Now let me implement the fix. First, I'll add helper functions to
path_info.rs.Assistant
Let me add the
Pathimport and the helper functions topath_info.rs.Assistant
Now let me add the helper functions after
normalize_npm_specifier.Assistant
Let me view the exact lines around the insertion point.
Assistant
Now let me insert the helper functions after line 116 (the closing brace of
normalize_npm_specifier).Assistant
Now let me update the imports in
specifier.rsand applycredit_package_nameat the creation sites. First, the import.Assistant
The replace command requires the file to be "open" and the text to be in "displayed lines". Let me open the file first and navigate to line 17.
Assistant
Now let me refactor the inline
.pnpmcheck in the first branch and applycredit_package_name. Let me view the first branch.Assistant
Now let me refactor the first branch to use
is_pnpm_virtual_store_pathand applycredit_package_nameat the threeNpmPackagesites. First, the first branch.Assistant
Now the canonical branch (line 1175):
Assistant
Now the Err branch (line 1209):
Assistant
Now let me handle the style resolution sites in
try_style_condition_package_resolution. Let me find them.Assistant
Let me apply
credit_package_nameat the style resolution sites (953, 976, 981) for consistency.Assistant
Let me apply
credit_package_nameat the three style resolution sites.Assistant
The replace command needs the lines to be in the displayed window. Let me navigate to line 950 first.
Assistant
Now the second style site (canonical, line 977-981) and the third (line 985-987):
Assistant
Now let me handle the fallbacks.rs sites. First, update the import in fallbacks.rs.
Assistant
Now apply
credit_package_nameat the path alias fallback site.Assistant
Now the SCSS node_modules fallback site (line 365 area). Let me find it.
Assistant
Now the SCSS node_modules fallback. The specifier is normalized with
./prefix, so I'll pass the strippedbareform tocredit_package_name.Assistant
Now let me run the reproduction test to confirm the fix works.
Assistant
The fix works for the JSR case. Let me add an npm alias case to the reproduction test to confirm both scenarios.
Assistant
Let me clean up the test file — remove the non-existent helper stubs.
Assistant
Both alias cases pass. Now let me run the full graph test suite to ensure I didn't break anything.
Assistant
All graph tests pass. Now let me run the core crate tests to ensure dependency analysis isn't broken. Let me build the core crate first.
Assistant
Core compiles. Now let me run the pnpm-related integration tests and unused deps tests.
Assistant
All integration tests pass. Now let me run the core lib unit tests and discover tests which use node_modules fixtures.
Assistant
All 2477 core lib tests pass. Let me check for other test binaries and run the discover tests (which use node_modules fixtures).
Assistant
All core tests pass. Let me verify end-to-end with a temporary test that runs the full
analyzepipeline on a pnpm-alias fixture. First, let me check the test helpers.Assistant
Let me check the default rules severity for unused/unlisted dependencies.
Assistant
Let me check the core crate's dev-dependencies and how integration tests are set up.
Assistant
Let me look at the integration_test.rs structure to add a temporary test module that reuses
common.Assistant
Let me create a temporary end-to-end test module to verify the full
analyzepipeline. First, the module file.Assistant
Now let me run the end-to-end test.
Assistant
Let me fix the field access in the test.
Assistant
The end-to-end test passes. Let me confirm the tests are meaningful by temporarily making
credit_package_namea no-op and verifying they fail, then restore.Assistant
The no-op confirms the bug reproduces and the fix resolves it. Let me investigate why the JSR repro seemed to pass with the no-op — let me re-run it with full output.
Assistant
Let me check the oxc_resolver default
symlinksoption to understand the symlink-following behavior.Assistant
The default
symlinks: trueconfirms oxc_resolver follows symlinks (the bug scenario). My fix handles both cases. Let me restore the real fix.Assistant
Fix restored. Let me re-run the e2e and repro tests to confirm they pass with the real fix.
Assistant
Both pass with the real fix. Now let me run the broader test suite (config, types, and the full core/graph) to ensure no regressions before cleanup.
Assistant
Let me run clippy on the affected crates to ensure no lint errors (the repo has strict lints).
Assistant
Let me check if my changes introduced any new clippy warnings specifically in the modified files.
Assistant
These warnings are all in
tests.rs(which I didn't modify). Let me verify they're pre-existing by stashing my changes and comparing.Assistant
Clean checkout shows 0 warnings — my changes introduce warnings. Let me investigate why adding
mod repro_testmakestests.rshelpers appear unused.Assistant
Let me check the cfg gating on tests that use these helpers, and force a clean clippy run on the clean baseline.
Assistant
The "0 warnings" clean run was likely a stale-cache false negative. Let me force a clean clippy run on the stashed baseline to get the true baseline.
Assistant
Let me check whether
mod tests;is gated by#[cfg(test)]and re-run clippy with my changes to see full warning context.Assistant
Let me remove the temporary test files now that the fix is verified, then re-check clippy. First, remove
repro_test.rsand its registration.Assistant
Now remove the e2e temp test and its registration.
Assistant
Now let me re-run clippy on a clean build to confirm no new warnings are introduced by my actual fix (without temp tests).
Assistant
Let me check whether I accidentally modified
tests.rsand inspect git status.Assistant
Let me definitively check whether these
tests.rswarnings are pre-existing by stashing and capturing the full clippy output (including whether it recompiled).Assistant
Let me check the CI configuration and workspace lints to understand how clippy is run.
Assistant
CI uses
--all-targets -- -D warnings. Let me run clippy in that mode on the affected crates to confirm no warnings.Assistant
I found the issue — my earlier
sedaccidentally stripped the#[cfg(test)]attribute frommod tests;. Let me check the git diff for mod.rs.Assistant
Confirmed — my earlier edit accidentally removed
#[cfg(test)]frommod tests;. Let me restore it.Assistant
Now
mod.rshas no diff. Let me re-run clippy in CI mode (--all-targets -- -D warnings) on the affected crates.Assistant
clippy passes for fallow-graph. Let me run clippy for fallow-core in CI mode too.
Assistant
clippy passes. Let me verify the git status shows only intended changes and no leftover temp files.
Assistant
Only the three intended files are modified with no leftover temp files. Let me run the full graph and core test suites once more to confirm everything passes.
Assistant
All tests pass. Let me do a final verification by temporarily re-creating a quick resolution test to confirm the fix still works after cleanup.
Assistant
Let me temporarily re-add the repro test module, verify, then remove it.
Assistant
The fix is confirmed working. Now let me remove the temporary test and restore mod.rs.
Assistant
mod.rs is clean (no diff), only the 3 intended files are modified, no untracked files. Let me do a final clippy check on the graph crate.
Assistant
Let me review the final diff of all my changes.
Assistant
The diff looks complete. Let me check rustfmt compliance since the repo has a
.rustfmt.toml.Assistant
Rustfmt wants those multi-arg calls collapsed onto one line. Let me apply rustfmt to fix formatting.
Assistant
rustfmt is clean. Let me view the final formatted version of the key sites to confirm correctness.
Assistant
The formatting is correct. Let me run the final test suite to confirm everything passes after formatting.
Assistant
Everything passes — tests, clippy, and fmt. Let me do a final review of the complete diff after formatting.
Assistant
Let me verify the duplicates module doesn't rely on the resolved source name in a way my change would affect.
Assistant
The duplicates/cross_reference modules don't use these. Let me confirm the whole workspace still builds.
Assistant
The whole workspace builds. Let me do a final review of the
path_info.rsadditions and confirm the complete change set.Assistant
The change set is clean and complete. Let me do a final comprehensive test run across all affected crates to be absolutely certain before submitting.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.