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
Let me start by exploring the repository structure to understand the codebase and then find the relevant files related to pnpm package source aliases.
Assistant
Let me explore the crates directory to understand the project structure.
Assistant
Let me explore the graph crate, which seems most relevant to dependency resolution.
Assistant
Let me search for code related to pnpm, package sources, jsr, npm: aliases, catalogs.
Assistant
Let me look at the
unused_deps.rsandunused_overrides.rsfiles, which seem most relevant.Assistant
Let me look at the specifier resolution code that handles jsr: and npm: imports.
Assistant
Let me look at the
extract_package_name_from_node_modules_pathfunction and related pnpm handling.Assistant
Let me search more broadly for where
@jsror jsr-to-npm conversion might happen, and how the resolved package name gets determined.Assistant
Let me look at the
unused_deps.rsfile which handles unused/unlisted dependency analysis.Assistant
Let me look at how imports get collected and matched against dependencies, particularly where
@jsr/std__csvstyle names come from.Assistant
Let me look at the
package_usage_namemethod and how edges are constructed.Assistant
Let me look at the
try_node_modules_resolutionor similar functions whereNpmPackageresults are created in specifier.rs.Assistant
Let me look at the existing tests and reproduction approach. First let me check how tests are structured.
Assistant
Let me find tests related to pnpm catalogs and the
unused_cataloganalysis.Assistant
Let me look at the fixture structure for the catalog tests.
Assistant
Let me look at where the
fixture_pathfunction points.Assistant
Let me look at
normalize_npm_specifierand the path_info functions.Assistant
Let me check the build setup and available tools.
Assistant
Let me look at the existing resolution tests to understand how to set up pnpm-style test cases.
Assistant
Let me look at the test helpers used in the resolution tests.
Assistant
Let me look at how integration tests create real filesystem structures.
Assistant
Let me look at the function containing line 950 and the broader resolution context.
Assistant
Let me check the CLI crate to find the binary target for running
fallow dead-code.Assistant
Let me look at the CLI api.rs to understand the analysis entry point.
Assistant
Let me check how the integration_test.rs includes modules.
Assistant
Let me first build the core crate to ensure the project compiles.
Assistant
The project compiles. Now let me create a temporary reproduction test that mimics the pnpm structure with symlinks.
Assistant
The test passed with empty results, which doesn't match the issue. Let me debug to see what's actually happening with the resolution.
Assistant
Let me modify the test to print all results for debugging.
Assistant
The bug didn't reproduce because the resolver returns the symlink path. Let me check the resolver configuration and how symlinks are handled.
Assistant
Let me look at how the dependencies integration test sets up real node_modules to verify resolution behavior.
Assistant
Let me check the oxc_resolver source to understand symlink handling defaults.
Assistant
Let me check how the path is computed and whether symlinks are resolved. Let me search the context.rs and the main resolver for symlink handling.
Assistant
Let me look at how
load_realpathworks in the resolver context.Assistant
Let me look at how the graph crate tests build a real resolver context with real files.
Assistant
Let me write a direct test to see what the resolver returns for a symlinked pnpm-style package. Let me create a temporary test in the graph crate.
Assistant
The resolver returns the canonical
.pnpmpath. Let me check howcatalog:dependencies andall_dependency_namesare handled.Assistant
Let me check
try_source_fallbackwhich might be matching the canonical path.Assistant
Let me re-run the integration test with full struct debug output.
Assistant
The files are dead (unused). Let me check how fallow determines entry points, then make the files reachable.
Assistant
Let me check the
create_config_with_overrideshelper to set entry points.Assistant
Let me update the repro to set entry points so files are reachable.
Assistant
Let me check how the analysis pipeline creates the resolver (it may differ from my direct test).
Assistant
Let me check
apply_specifier_upgradeswhich transforms resolved results.Assistant
Let me look at the tempdir-based tests that build a full context.
Assistant
Let me extend the graph crate debug test to call the full
resolve_specifierwith a proper context.Assistant
The resolution returns
NpmPackage("@jsr/std__csv")at the graph level, but the integration test shows empty results. Let me add a temporary debug print inunused_deps.rsto see what's collected.Assistant
No edges collected at all. Let me add a debug print directly in
resolve_specifierto see what's happening.Assistant
Let me find the right line to add a debug print. Let me look at where the resolved path is determined and the NpmPackage decision is made. Let me add a debug print right after
resolve_file_with_tsconfig_fallbackin the main resolve_specifier function.Actually, let me look at the structure around line 1100-1140 where the main resolution happens.
Assistant
resolve_specifieris called correctly. Let me checkCanonicalFallbackwhich might be matching the.pnpmpath.Assistant
Let me add a debug print of the final result. Let me look at
resolve_static_imports.Assistant
I made a syntax error. Let me fix the closure properly.
Assistant
Now the bug is confirmed at resolution level: targets are
NpmPackage("@jsr/std__csv")andNpmPackage("unstorage-nightly"). Butfind_unlisted_dependenciesdidn't see them. Let me check how it's called.Assistant
The dependency analysis is skipped because there's no root
package.json! Let me add one to the fixture.Assistant
The bug is now reproduced. Let me see the full unused/unlisted output.
Assistant
I've now reproduced the exact bug. Let me revert my debug prints and then look for existing
.pnpmdetection helpers.Assistant
Let me look for existing
.pnpmdetection helpers and check theis_bare_specifier/is_valid_package_nameimports in specifier.rs.Assistant
Let me check what
fallbacks.rsimports frompath_info.Assistant
Now let me view the exact branches to modify after revert.
Assistant
Let me check how
build.rsusespackage_usage_nameto ensure my fix covers all crediting sites.Assistant
Now let me implement the fix. First, add helper functions in
fallbacks.rsafterextract_package_name_from_node_modules_path.Assistant
Now let me update the import in
specifier.rsand apply the fix in the resolution branches.Assistant
Let me fix the import block formatting properly.
Assistant
Now let me apply the fix in the canonicalize branch of the main
resolve_specifier.Assistant
Now let me apply the fix to the style resolution function too. Let me view it again.
Assistant
Now let me build and run the reproduction test to confirm the fix.
Assistant
The fix works. Now let me run the existing tests to ensure no regressions. Let me start with the graph crate tests.
Assistant
Now let me run the core integration tests, focusing on dependency-related tests first.
Assistant
Now let me run the full core integration test suite to make sure nothing broke.
Assistant
All integration tests pass. Let me run the core lib unit tests and other test suites.
Assistant
All core tests pass. Let me check for other test suites (conformance, ecosystem) that might be affected.
Assistant
Let me investigate whether tsconfig path aliases renaming packages is a supported/tested scenario, to decide between a simple vs. guarded fix.
Assistant
Let me look at how
find_unused_dependenciesconsumes package usage, to decide where the name mapping should happen.Assistant
Let me examine the tsconfig path alias handling and tests to understand if aliasing to a different package name is a concern.
Assistant
Let me empirically test whether a tsconfig path alias to a differently-named package produces a false positive with the simple fix. Let me add a temporary graph test.
Assistant
The simple fix would cause a false positive for tsconfig path aliases to differently-named packages. Let me check whether oxc's
package_jsonpath reliably gives the declared name, which would be a cleaner distinguisher. Let me test both cases.Assistant
The dbg_pnpm_jsr_full_resolve_specifier test was reverted earlier (I did
git checkouton tests.rs). So that test doesn't exist anymore. Let me check what's in tests.rs now.Assistant
Let me append a fresh jsr test and update the tsconfig test to print package_json paths.
Assistant
I've confirmed the
package.jsonsymlink path reliably carries the declared name (for pnpm aliases) vs. the real name (for tsconfig aliases). This is a cleaner, more robust distinguisher than the specifier alone (which would regress tsconfig aliases). Let me reimplementcredited_package_nameto use thepackage.jsonpath. First, let me view the current state of my edits.Assistant
Let me reimplement
credited_package_nameto use thepackage.jsonpath approach.Assistant
Let me clean up that helper section — I introduced a confusing
path_namecheck. Let me rewrite it cleanly.Assistant
Now let me check the imports in fallbacks.rs — I may no longer need
extract_package_nameandis_bare_specifier.Assistant
Now let me update the call sites in
specifier.rs. Let me view the current state.Assistant
Now let me compute the declared name from
resolved.package_json()and update the call sites in the main function.Assistant
Now let me update the import in
specifier.rsto includedeclared_name_from_package_json_path.Assistant
Now let me update the style function call sites. Let me view the current style function state.
Assistant
Now let me build to check for errors.
Assistant
Let me check for warnings, then run the reproduction test.
Assistant
The fix works. Now let me verify the tsconfig-alias case does NOT regress — it should credit
react, notmy-react.Assistant
The tsconfig-alias case correctly credits
react(no regression). Let me verify the jsr case credits@std/csv.Assistant
Both cases work correctly. Let me run the full graph and core test suites to confirm no regressions.
Assistant
All tests pass. Let me also run the broader workspace test suite to be thorough.
Assistant
One CLI test failed. Let me check if it's related to my change or pre-existing/environment-specific.
Assistant
This test spawns an
npmcommand, which isn't available in this environment. Let me confirm it's pre-existing by stashing my changes and running it.Assistant
The test passes on original code. Let me re-run it with my changes to check if it's flaky.
Assistant
The test passes in isolation — it's a flaky test (parallel test interference), unrelated to my change. Let me run the full CLI suite once more to confirm.
Assistant
Different test failed now —
fix_batch_aborts_when_a_target_directory_is_read_only, which fails when running as root (root can write to read-only dirs). These are environment-specific. Let me confirm by running the full CLI suite on the original (stashed) code.Assistant
Both CLI failures are pre-existing/environment-specific (running as root). My change doesn't break them. Now let me clean up my temporary debug tests. First, remove the dbg tests from the graph crate's
tests.rs.Assistant
The dbg tests are at the end (lines 1782-1877). Let me remove them, preserving the file ending cleanly.
Assistant
Now let me remove the temporary integration test file and its registration.
Assistant
Let me verify the
tests.rsdiff is empty (I added then removed the dbg tests).Assistant
There's a trailing blank line. Let me remove it to keep
tests.rsclean.Assistant
tests.rsis now clean. Let me review the final diff for my actual changes.Assistant
The diff is clean. Let me run the key test suites once more to confirm everything passes after cleanup.
Assistant
All tests pass. Let me run clippy on the affected crates to ensure no lint issues.
Assistant
No clippy warnings. Let me verify there are no unused imports by checking the build output for warnings.
Assistant
Let me write a comprehensive temporary verification test covering edge cases (jsr alias, npm alias, normal pnpm, direct source import), run it, then remove it.
Assistant
The test setup has a bug (test harness, not the fix). Let me check line 33.
Assistant
The test-harness bug:
fs::writedoesn't create thedistparent dir. Let me fix the test setup.Assistant
All edge cases pass. Let me clean up the temporary verification test.
Assistant
Only the two source files are modified. Let me run a final check on the affected crates and confirm the build is clean.
Assistant
Let me check the conformance/ecosystem tests to see if they're relevant to run.
Assistant
The conformance/ecosystem tests are Python/CLI-based end-to-end tests, not Rust unit tests. My change is targeted and all Rust tests pass. Let me do a final verification that all import resolution paths go through the fixed
resolve_specifier.Assistant
No direct package-name extraction in those files. Let me confirm they delegate to
resolve_specifier.Assistant
All import paths delegate to the fixed
resolve_specifier. Let me do a final broad check for any other path-based package name derivation in the core crate that feeds dependency analysis.Assistant
The fix is comprehensive. Let me do a final review of the complete diff.
Assistant
The diff is clean. Let me run
cargo fmt --checkto ensure formatting matches the project's style.Assistant
There's a formatting issue. Let me apply
cargo fmtto fix it.Assistant
Formatting is clean. Let me rebuild and run the tests once more to confirm everything is still good after formatting.
Assistant
Let me run clippy once more on both affected crates to be sure.
Assistant
Let me do a final check of the repository state to ensure only the intended changes remain.
Assistant
Let me do a final full workspace build check to ensure nothing else is broken.
Assistant
I need to verify my fix works with a realistic multi-level pnpm symlink structure (real pnpm uses nested symlinks). Let me test what oxc reports for the package.json path in that case.
Assistant
Line 1798:33 — the symlink for inner_link fails. Let me check.
inner_link = inner_store.join("@std/csv")andsymlink(&real, &inner_link). The parentinner_storeexists (created byrealcreation? no,realis inside inner_store). Wait,real = inner_store.join("@jsr/std__csv"), and I createdrealviacreate_dir_all(&real)which createsinner_storetoo. Soinner_storeexists. Theninner_link = inner_store.join("@std/csv").symlink(&real, &inner_link)— real exists. Should work.Wait, line 1798 is
symlink(&real, &inner_link).unwrap();? Let me check the line numbers. Actually the error is NotFound. Hmm.symlink(target, link)— target must exist? No, symlink doesn't require target to exist on Unix. But the link's parent must exist.inner_link.parent()=inner_storewhich exists.Wait, maybe
realis.../@jsr/std__csvandinner_linkis.../@std/csv. Both underinner_store. Hmm. Let me check line 1798. Actually let me just look at the test lines.Actually, the issue might be that on line ~1798 — wait no. Let me recount the test. Let me just look at the actual lines.
Assistant
The
@std/csvscoped symlink needs its@stdparent dir created first. Let me fix the test harness.Assistant
Confirmed: even with a realistic multi-level pnpm symlink structure, oxc reports the
package.jsonpath via thenode_modules/<declared>symlink (declared name) while the resolved file path is canonical (source name). My fix works for real pnpm. Let me remove the debug test and finalize.Assistant
tests.rsis clean. Let me do a final build and test run to confirm everything is in order.Assistant
Let me run a final fmt check and clippy to ensure everything is clean.
Assistant
Everything is clean and passing. Let me do a final review of the complete diff before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.