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
It's a Rust project. Let's search crates for pnpm-related logic.
Assistant
Now let's build a reproduction directory structure mimicking pnpm's virtual store.
Assistant
Now let's run fallow dead-code on this repro.
Assistant
Reproduced. Let's see the rest (unlisted deps and unresolved imports).
Assistant
Confirmed the exact bug from the issue. Now let's fix the resolver logic. Let's look at the specifier.rs code more broadly to plan a fix.
Assistant
Now let's update specifier.rs to use this helper at all the relevant NpmPackage-producing sites.
Assistant
Now let's patch each
ResolveResult::NpmPackage(pkg_name)occurrence in the main function and in the style helper.Assistant
This is for CSS/style contexts (
is_bare_style_subpath), which is more path-like than a plain bare specifier. Let's checkis_bare_style_subpathto see if it corresponds to bare specifiers.Assistant
Good, it's a bare specifier too. Let's patch these occurrences using
preferred_bare_package_name(specifier, pkg_name).Assistant
Now let's patch the main function's four occurrences (lines around 1139-1276, now shifted).
Assistant
The false positives are fixed. The
unused_filesentries are unrelated (no entry points configured in this minimal repro) and expected. Let's run existing test suites to make sure nothing broke.Assistant
All graph tests pass. Let's run the full core and cli test suites too.
Assistant
All pass. Let's run the full workspace test suite (all crates) to be thorough, and also clippy/fmt checks.
Assistant
Confirmed this test fails even without my changes (likely because we're running as root, bypassing read-only permission checks). Not related to my fix. Let's restore my changes.
Assistant
Now let's continue running the rest of the workspace tests, skipping that pre-existing failing test.
Assistant
All other tests pass (the failing test is a pre-existing environment issue unrelated to root-privileges bypassing read-only permission checks). Let's check the beginning of the output for any other failures I may have missed by scrolling up.
Assistant
All good, all tests pass. Let's also run clippy to check code quality conforms to repository lint rules.
Assistant
No clippy warnings. Now let's double check the diff for correctness/readability.
Assistant
Only the two intended files were modified. Let's clean up the temp reproduction directory.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.