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 look at pnpm.rs and pnpm_catalog.rs.
Assistant
Now let's check what's imported/exported from path_info.rs and where it's re-exported for use in specifier.rs.
Assistant
Good, all needed functions (
extract_package_name,is_bare_specifier,is_valid_package_name) are already imported in specifier.rs. Let's add the helper function to path_info.rs.Assistant
Now let's update specifier.rs to use this helper at each
ResolveResult::NpmPackage(pkg_name)construction that derives the name from a resolved path.Assistant
Now let's update each
ResolveResult::NpmPackage(pkg_name)construction site to usepreferred_package_name.Assistant
No hidden diffs; let's just use
editwith explicit line ranges instead.Assistant
Now let's handle the remaining occurrences (in
resolve_specifier, previously lines ~1139-1276, now shifted by +4).Assistant
Now let's build to check compile errors.
Assistant
I see — I selected the wrong end line and left leftover duplicate lines. Let me remove the trailing duplicated lines (1220-1224 roughly).
Assistant
Lines 1220-1223 are leftover duplicates. Let's delete them.
Assistant
Now let's build again.
Assistant
Compiles. Now let's re-run the repro.
Assistant
Bug fixed — no more false positives. Now let's run the full existing test suite to check for regressions.
Assistant
All graph tests pass. Let's run the full test suite (or at least core/cli) to check for wider regressions.
Assistant
All 1770 tests pass with the fix applied. That confirms the earlier failure was flaky (parallel test env issue), not caused by my change. Let's continue running the rest of the workspace test suite to be thorough.
Assistant
Confirmed — this failure is pre-existing (environment-related, since we run as root, chmod read-only doesn't block root), unrelated to my change. Let's continue running the rest of the suite to check for other issues.
Assistant
The full test suite passed (excluding the two known pre-existing, environment-related flaky failures). Let's check the whole log for any FAILED entries to be certain.
Assistant
No failures. Now let's add a regression test fixture and integration test for this issue, consistent with the repo conventions (similar to issue-329-pnpm-catalog). Let's check the integration test file structure.
Assistant
Let's check
workspace_cross_imports.rshead for setup pattern relevant to symlinked node_modules with.pnpm.Assistant
Now register the module in integration_test.rs.
Assistant
Now let's check the
.gitignore— since our fixture createsnode_modulesat test runtime (not checked in), that's fine since node_modules is gitignored globally. Let's build and run the new test.Assistant
Test passes. Let's verify it actually fails without the fix (sanity check the test is meaningful).
Assistant
Confirmed the test correctly fails without the fix. Let's restore the fix.
Assistant
Now let's rebuild and confirm tests pass with fix, then also add a small unit test for
preferred_package_namein path_info.rs.Assistant
Now let's add unit tests for
preferred_package_namein path_info.rs.Assistant
Leftover stray
>>> REPLACEmarker on line 188. Let me fix that.Assistant
Good, that's fixed. Now let's build and test.
Assistant
All good. Now let's run clippy to make sure style/lint compliance since repo probably enforces strict clippy.
Assistant
No clippy warnings. Let's view the final diff for review.
Assistant
This looks clean. Now let's double check the untracked new files.
Assistant
Good. Now let's do a final full build + targeted test run to make sure everything still compiles and passes.
Assistant
Confirmed fixed. Let's run the two relevant test suites once more (graph + core integration) to confirm everything is green with all changes in place.
Assistant
All 546 core integration tests pass (up from 545, +1 for our new test), and all graph tests pass. Let's clean up the temporary repro directory (not part of repo, but tidy).
Assistant
Let's view the final new files content once more for sanity, and confirm the fixture tree.
Assistant
Confirmed it's ignored. Now let's review the full diff summary one more time before final submission.
Assistant
Now let's go through the checklist explicitly.
Assistant
Everything looks good. Let's do a final comprehensive check by rebuilding release and re-running the reproduction from the issue verbatim (without the fake node_modules, since the issue didn't include node_modules — confirming baseline behavior is unaffected).
Assistant
Good — clean output as expected without node_modules too (files still marked unused since no entry, but that's expected default behavior unrelated to this fix).
Now let's go through the checklist explicitly:
Assistant
Checklist review:
-
Reproduced the reported error: Yes — I built a minimal reproduction matching the issue (pnpm-workspace catalog with
jsr:/npm:package sources, plus a synthetic pnpm.pnpmstore + symlinkednode_modules, since the false positive only manifests once packages are actually installed/resolved through pnpm's virtual store). Confirmed the exact false positives described (@std/csv/unstoragereported unused,@jsr/std__csv/unstorage-nightlyreported unlisted). -
Confirmed the fix resolves the error: Yes — after the fix, the same reproduction produces zero issues. I also verified (by stashing the fix) that the new regression test fails without the change and passes with it.
-
Thought about edge cases: Handled bare vs. non-bare specifiers (relative/absolute paths fall back to the path-derived name via
is_bare_specifiercheck), scoped packages, deep subpaths (@std/csv/stringify), the case where the specifier name already matches the path-derived name (no-op), and both and -sourced aliases. The fix is applied uniformly at every resolution site that derives its name from a resolved filesystem path (both the main resolver path and the style/CSS resolution path), not hardcoded to the two example package names.
-
Assistant
- Ran existing tests and confirmed they pass: Yes — ran the full workspace test suite (
cargo test --release --workspace) twice; all tests passed except two pre-existing, environment-related flaky failures (fix_batch_aborts_when_a_target_directory_is_read_only, which fails because tests run as root and root bypasses read-only permissions, and an initial run ofresolves_npm_sidecar_from_node_modules_rootthat passed on isolated re-run) — both verified to fail identically on the unmodified codebase (git stashverification), so unrelated to this change.fallow-graph(523 tests) andfallow-coreintegration tests (546 tests, including the new regression test) all pass cleanly.
Final diff review:
- Ran existing tests and confirmed they pass: Yes — ran the full workspace test suite (
Assistant
The change set is minimal, targeted, well-tested, and resolves the issue. Let's submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.