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
I'll start by exploring the repository structure to understand the codebase.
Assistant
I'll start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the crates directory to understand the structure of the project.
Assistant
Let me look at the relevant crates. The issue is about dependency resolution, pnpm package sources, catalogs. Let me search for relevant terms.
Assistant
This catalog parser only collects package names and lines, not the version specifiers. Let me look at how dependencies are resolved and how the resolved package names are used. Let me search for relevant code.
Assistant
I need to make sure I only send one tool call at a time.
Assistant
Let me look at the
types.rsfile to understandResolveResult.Assistant
Now let me look at the fallbacks.rs, particularly the
extract_package_name_from_node_modules_pathfunction.Assistant
Let me look at how the resolution flow works, particularly around the bare specifier handling and where the NpmPackage result is created from a resolved path.
Assistant
Now let me look at the main resolution function in
specifier.rsto understand how bare specifiers get resolved toNpmPackage.Assistant
Let me first reproduce the issue. Let me check how the project is built and how
fallow dead-codeworks.Assistant
Let me build the project first to make sure it compiles.
Assistant
The project builds. Now let me create the reproduction setup. First, let me create a test directory with the reproduction case.
Assistant
The reproduction needs actual node_modules. Let me check if pnpm/npm is available and look at how existing tests set up node_modules for resolution.
Assistant
No node/pnpm available. Let me look at the existing tests for resolution to understand how they simulate node_modules.
Assistant
Let me look at the
path_info.rsto understandextract_package_nameand related functions.Assistant
Now let me look at the resolution tests to understand expected behavior, particularly around pnpm and bare specifiers.
Assistant
Let me look at the test that uses real node_modules paths, particularly around line 1714.
Assistant
Let me look at how
package_usage_nameis used and how unlisted dependencies are detected.Assistant
Let me look at how the
package_usagegraph is built and how unused dependencies are detected.Assistant
Let me find where
package_usageis built from the resolved modules.Assistant
Let me look at the existing integration tests for pnpm to understand the test setup patterns.
Assistant
Let me look at the existing test helpers that build a real resolver and context with file indexes.
Assistant
Let me look at the test that builds a real resolver with node_modules and tests bare specifier resolution.
Assistant
Let me look at the test helper
with_package_map_ctxin fallbacks.rs tests.Assistant
Now let me write a temporary reproduction test to confirm the current behavior with a real pnpm virtual store structure.
Assistant
Now let me register this test module and check the resolve mod.rs structure.
Assistant
I've reproduced the bug. Now let me look at the exact code sections in
resolve_specifierto plan the fix. Let me view the relevant section again with line numbers.Assistant
Let me check if there are existing tests with tsconfig path aliases pointing to node_modules packages, which could be affected.
Assistant
Let me add debug output to understand what oxc_resolver returns. Let me check the oxc_resolver symlink options.
Assistant
I've confirmed the bug. Now let me look at the exact code sections to edit. Let me view the canonicalize branch with line numbers.
Assistant
Let me check the imports at the top of specifier.rs.
Assistant
Now I understand the issue clearly. Let me implement the fix. First, I'll add helper functions. Let me view the area around
should_preserve_node_modules_style_fileto place the helpers.Assistant
Let me add the helper functions after
should_preserve_node_modules_style_file.Assistant
Now let me apply the helper to the canonicalize Ok branch and Err branch. Let me view the current state.
Assistant
Now let me edit the canonicalize Ok branch to use the helper. Let me use the
replacecommand.Assistant
Now the Err branch:
Assistant
Now let me apply the helper to the style condition path for consistency. Let me view it.
Assistant
Let me apply the helper to the style condition path.
Assistant
Now let me build and run my reproduction test to verify the fix.
Assistant
Both repro tests pass. Now let me run the full graph crate test suite to ensure no regressions.
Assistant
All graph tests pass. Now let me run the core crate tests, which include dependency analysis tests.
Assistant
All core tests pass. Now let me set up an end-to-end test that mirrors the issue's reproduction with real pnpm-style node_modules symlinks, and run the CLI.
Assistant
The fix works end-to-end. Let me verify the bug reproduces WITHOUT the fix by temporarily disabling the helper logic.
Assistant
Let me check the full output to understand the analysis.
Assistant
The files are flagged as unused, which may exclude them from dependency analysis. Let me check how fallow handles entry points and whether dependency analysis runs on unused files.
Assistant
Let me check how
resolved_modulesis built and whether unused files are excluded.Assistant
So
find_unused_dependenciesusesgraph(which haspackage_usage), andfind_unlisted_dependenciesusesgraph.package_usageandresolved_modules. Thepackage_usageis built fromresolved_modulesinModuleGraph::build. Andresolved_modulescomes fromresolve_all_imports.Let me check whether
resolved_modulesincludes ALL discovered files or only reachable ones. Let me look at whereresolve_all_importsis called and how the graph is built.Assistant
Let me find where
resolved_modulesandgraphare constructed (beforefind_dead_codeis called). Let me search forresolve_all_importsandModuleGraph::buildcalls in the core crate.Assistant
Let me check stderr and whether node_modules is detected in the e2e.
Assistant
Let me check
credit_workspace_package_usagewhich is called after building the graph.Assistant
Let me add a temporary debug print to see what's in
package_usagein the CLI.Assistant
The assertion failed because there are two occurrences (the lib.rs has two places: line 500 and 754). Let me target the first one specifically.
Assistant
The debug didn't print, so
dead-codeuses a different code path. Let me check which function the CLIdead-codecalls.Assistant
analyzecallsanalyze_full(config, false, false, false, false). Let me findanalyze_fullto see which graph-build path it uses (the first at line ~500 or the second at ~732).Assistant
analyze_fullis at line 611 and uses the second graph-build path. My debug was added at the wrong (first) path. Let me add it at the correct path.Assistant
Interesting — with the neutered fix,
package_usagekeys areunstorage-nightlyand@jsr/std__csv(resolved source names). But the output still shows 0 unused/unlisted. Let me investigate why the unused-deps check doesn't flagunstorage/@std/csv. Let me look at the unused-deps "used" logic.Assistant
There must be existing catalog/package-source resolution logic. Let me search for where
npm:/jsr:source specifiers are resolved to map package names.Assistant
Let me look at the
PackageJsonstruct and how dependency names / catalog sources are handled.Assistant
production_dependency_names()returns the keys (declared names). Sounstorage/@std/csvshould be checked. Let me find where the catalog source specifiers create a name mapping. Let me look at the workspace module.Assistant
Let me add more debug to understand the workspaces and unused-deps findings. Let me check whether the apps are discovered as workspaces.
Assistant
The apps are workspaces. Let me look at
collect_unused_for_categoryandcollect_package_workspace_usageto understand the "used" determination.Assistant
Let me check
ModuleGraph::build_with_reachability_roots— maybe it excludes unreachable modules frompackage_usage.Assistant
Let me check the default severity for
unused_dependenciesandunlisted_dependenciesrules.Assistant
Let me check what rules the
dead-codecommand enables. Let me look at the CLIdead-codecommand.Assistant
Let me add debug to
find_unused_dependenciesto see what's happening with the workspace deps.Assistant
The DEBUGWS didn't print. Let me check which
find_unused_dependenciesfind_dead_code_fullactually calls.Assistant
My e2e is missing a root
package.json— without it,pkgisNoneand the dependency analysis is skipped entirely. Let me add a root package.json and re-test with the neutered fix.Assistant
Now the dependency analysis runs. Let me check the actual findings with the neutered fix.
Assistant
I've now reproduced the exact bug from the issue. Now let me restore my actual fix (un-neuter it) and verify the bug is fixed.
Assistant
Now let me remove the debug lines and rebuild.
Assistant
Debug lines removed. Let me rebuild and re-run the e2e to confirm the fix.
Assistant
The fix resolves the bug end-to-end. Now let me run the broader test suite to ensure no regressions. Let me run config and core integration tests.
Assistant
All integration tests pass. Let me also run the extract crate tests and verify the whole workspace compiles.
Assistant
Let me check
try_scss_node_modules_fallbackto see if it should also get the fix for consistency.Assistant
Let me check
find_scss_in_node_modulesto see if it returns symlink or canonical paths.Assistant
The SCSS fallback returns symlink paths (no
.pnpm), so it doesn't have the bug — no fix needed there. My fix covers the main JS/TS path and the style-condition path.Now let me clean up my temporary repro test file and unregister it.
Assistant
Let me verify the final state of my changes and run the affected test suites one final time.
Assistant
The diff looks clean. Let me run the final test suite for all affected crates to confirm no regressions and clean compilation.
Assistant
All tests pass. Let me run clippy on the affected crate to ensure no lint issues with my new code (the repo enforces clippy).
Assistant
Clippy passes cleanly. Let me rebuild the binary and re-run the end-to-end reproduction one final time to confirm the final state is correct.
Assistant
The fix works correctly:
unused_dependencies: 0— no false@std/csv/unstorageflaggedunlisted_dependencies: 0— no false@jsr/std__csv/unstorage-nightlyflaggedunused_files: 2— expected (the source files aren't entry points; unrelated to this issue)
Let me do a final git status check to ensure the repo is clean of temp files.
Assistant
The repository is clean — only
crates/graph/src/resolve/specifier.rsis modified, and no untracked temp files remain.Let me do a final review of the complete change to make sure it's coherent and correct.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.