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 and understanding how pnpm package sources and dependency resolution work in fallow.
- Assistant
Let me search for relevant code around package sources, catalogs, JSR, and dependency resolution.
- Assistant
rg is not found, let me use grep instead.
- Assistant
There's already catalog-related tests. Let me dig into package sources and dependency name resolution.
- Assistant
There's something about
add_exportless_package_source_indexesand package sources. Let me look at the package resolution related code and graph/resolve. - Assistant
Let me look at the unused_deps analysis and how package names are determined when resolving npm packages. Also look for package source related handling.
- Assistant
Let me look at how npm packages get their names from the filesystem resolution path.
- Assistant
The key seems to be
extract_package_name_from_node_modules_path. Let me examine that and existing pnpm handling. - Assistant
So the problem is when pnpm uses package source aliases, the node_modules path contains the resolved name (
@jsr/std__csvorunstorage-nightly) rather than the declared name. Let me look at how usa... - Assistant
Let me also check how unused deps credits package usage and any pnpm alias related code.
- Assistant
Let me look at how package_usage is populated in the graph.
- Assistant
Let me look at ResolveResult package_usage_name and CREDIT of packages in lib.rs. Also how npm package resolution preserves specifier names.
- Assistant
The issue is clear: resolution uses the path-derived name instead of the import specifier. Let me inspect
extract_package_nameand related resolution logic. - Assistant
Let me search CHANGELOG and docs for prior work on package sources, and look for how oxc resolver is configured.
- Assistant
Let me look at the ResolveOptions for oxc.
- Assistant
Let me also check how package.json dependency aliases and sources are parsed.
- Assistant
Let me try to reproduce the issue with a minimal fixture, and inspect an existing pnpm fixture layout.
- Assistant
Let me inspect the surrounding comments about the
.pnpmskip and related decision docs while cargo finishes. - Assistant
I'll check for tests expecting path-derived package names to differ from the import specifier.
- Assistant
I'll set up a small reproduction of the pnpm package-source alias layout and exercise the resolver against it.
- Assistant
There was a broken symlink path for
@std/csv— fixing it. - Assistant
Let me find the correct package name for the CLI.
- Assistant
Build fallow-cli package.
- Assistant
Good, build finished. Now let's run fallow against the repro.
- Assistant
Maybe fallow failed. Let me see stderr.
- Assistant
Let me check the CLI arguments.
- Assistant
Maybe there's a global path option.
- Assistant
Use --root
- Assistant
I'll check whether oxc_resolver returns the real path or the symlink path:
- Assistant
The directory creation failed somehow. Let me fix.
- Assistant
Confirmed oxc returns the realpath. Checking why
.pnpmpaths are excluded from early package-name extraction: - Assistant
Let me look at when
.pnpmexclusion was added specifically. - Assistant
Let me find the exact addition of the
.pnpmexclusion check. - Assistant
Hmm empty. Maybe the path used different|encoding.
- Assistant
Examining all sites that emit
NpmPackagefrom a resolved path: - Assistant
Implementing the fix: prefer the import specifier's package name when classifying bare npm packages.
- Assistant
I'll add a helper that prefers the import name and wire it into the NpmPackage return sites.
- Assistant
Now update all the NpmPackage construction sites to use the helper.
- Assistant
I need to navigate to the right line first, or use a smaller unique string.
- Assistant
The command is
goto 976notgoto:976. - Assistant
Now I can replace.
- Assistant
Now update the main resolve path.
- Assistant
Now replace the three NpmPackage sites in the main path.
- Assistant
Also T check path-alias fallback in fallbacks.rs for consistency, then rebuild and verify.
- Assistant
Good,build succeeded. Let me run the repro again.
- Assistant
The?pipe issue - python reading empty stdin because tee wasn't there and fallow might write to stderr while returning non-zero for unused files. When piping to python'sstdinfrom stdout and simulation drizzlewith piped python reading stdin with heredo...
- Assistant
Fix works. Cleaning up the temporary example and running related tests.
- Assistant
All graph tests pass. I'll write a temporary verification test for the alias case and run dependency-related integration tests.
- Assistant
cargo test filter is a single string.
- Assistant
All integration tests passed. Running lib tests for unused_deps as well.
- Assistant
Direct npm: aliases work too. Checking clippy and cleaning up.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.