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
I'll start by exploring the repository structure and understanding how fallow handles pnpm package sources and dependency resolution.
- Assistant
Let me explore the crates structure and search for relevant code related to pnpm, catalogs, and package sources.
- Assistant
rg is not available, let me use grep instead.
- Assistant
Let me look at existing package source handling and similar issues.
- Assistant
Let me search more specifically for how package names are resolved from lockfiles and catalogs.
- Assistant
Let me look at how the dependency graph resolves packages and how pnpm links are handled.
- Assistant
Let me examine package name extraction and how npm packages get credited for usage.
- Assistant
Let me look at how npm packages are resolved and where package name is extracted after path canonicalization.
- Assistant
Let me examine the main specifier resolution for bare package imports.
- Assistant
Let me read the main resolve_specifier function more carefully around lines 1100-1290.
- Assistant
Let me continue reading that section of the resolver.
- Assistant
Let me look at existing related tests and how npm: scheme handling credits declared names.
- Assistant
Let me look at the npm: stripping at line 1007 and surrounding context, and also the Supabase edge test.
- Assistant
Let me check the CHANGELOG and git history for related package-source or alias handling.
- Assistant
Let me look at pnpm store path tests and path_info for package name extraction.
- Assistant
Let me check integration test helpers and how node_modules is mocked, and search for alias-related handling for declared vs resolved names.
- Assistant
Let me look at how dependencies tests work and how they set up node_modules.
- Assistant
Let me check oxc resolver configuration and try to reproduce with a minimal fixture.
- Assistant
Let me also check CLUDE.md/CONTEXT for resolver design notes and look at other places that emit NpmPackage for bare specs.
- Assistant
I'll create a reproduction fixture that mimics pnpm's package-source alias layout.
- Assistant
Building fallow to reproduce the issue.
- Assistant
Now let's run fallow on the reproduction fixture.
- Assistant
Hmm exit code 0 and empty output. Maybe dead-code needs entry points or uses package.json main?
- Assistant
Let me check the CLI options.
- Assistant
Need to see how to specify the directory.
- Assistant
Use
-rfor root. - Assistant
Confirmed the bug. I'll implement a fix preferring the import/declared package name for bare npm-style specifiers.
- Assistant
Let me read the style package resolution and decide where the helper should live.
- Assistant
I'll add a helper and apply it at NpmPackage construction sites. First, the helper:
- Assistant
Adding the helper function and its unit tests.
- Assistant
Adding unit tests for the new helper.
- Assistant
Now updating specifier.rs to use the preferred package name.
- Assistant
Need to use --file option since path_info is open.
- Assistant
Need to open the file first at the right line.
- Assistant
Now I can replace.
- Assistant
Updating NpmPackage construction sites in resolve_specifier and style resolution.
- Assistant
I'll add a local helper and update each NpmPackage site.
- Assistant
I need to goto line 897 first.
- Assistant
I need to check what type workspace_roots is - FxHashMap from rustc_hash.
- Assistant
Updating each site with preferred_npm_package_name directly for simplicity.
- Assistant
The replace tool is picky about the current window. Let me goto 950 and ensure the text is in the window.
- Assistant
Let me try smaller replacements.
- Assistant
Now update the main resolve_specifier function's NpmPackage sites.
- Assistant
I'll update the three NpmPackage sites in this block.
- Assistant
Updating fallbacks.rs for consistency.
- Assistant
Updating fallbacks.rs package-name sites as well.
- Assistant
Update line 71 to use preferred_npm_package_name.
- Assistant
Let me check the other site around line 363.
- Assistant
Updating the SCSS node_modules fallback as well.
- Assistant
Exporting the helper and rebuilding to verify the fix.
- Assistant
No need to export preferred_npm_package_name publicly unless other crates need it. Leaveit private.
- Assistant
Build succeeded. Verifying the reproduction.
- Assistant
The false positives are gone. Checking remaining total_issues:
- Assistant
Verifying alias packages declared directly without catalog, and running unit tests.
- Assistant
Running related unit and integration tests to check for regressions.
- Assistant
All graph resolve tests passed. Running dependency-related core unit tests next.
- Assistant
The guidelines forbid adding tests — removing the unit tests I added.
- Assistant
I need to remove the tests I added.
- Assistant
Final verification and reviewing the diff.
- Assistant
Making the helper crate-private since it doesn't need a public API.
- Assistant
Need to goto first.
- Assistant
pub(super) works party within path_info's parent module resolveграфических.
- Assistant
Rebuilding and doing a final verification.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.