Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION False positives for pnpm package source aliases What happened? fallow…

  1. User

    ISSUE DESCRIPTION

    False positives for pnpm package source aliases

    What happened?

    fallow dead-code reports 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.5
    

    The 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 registry
    • npm:<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/csv is declared and imported, Fallow should credit @std/csv, even if pnpm resolves it to @jsr/std__csv internally. Same for unstorage resolving to unstorage-nightly.

    Reproduction

    Create pnpm-workspace.yaml:

    packages:
      - apps/*
    
    catalog:
      '@std/csv': jsr:1.0.6
      unstorage: npm:unstorage-nightly@2.0.0-alpha.5
    

    Create apps/cli/package.json:

    {
      "name": "@example/cli",
      "type": "module",
      "dependencies": {
        "@std/csv": "catalog:"
      }
    }
    

    Create apps/cli/src/output.ts:

    import { stringify } from '@std/csv/stringify';
    
    console.log(stringify);
    

    Create apps/native/package.json:

    {
      "name": "@example/native",
      "type": "module",
      "dependencies": {
        "unstorage": "catalog:"
      }
    }
    

    Create apps/native/src/storage.ts:

    import { createStorage } from 'unstorage';
    
    console.log(createStorage);
    

    Run:

    fallow dead-code --format json
    

    Expected behavior

    Fallow should treat the package name used in package.json/imports as canonical for dependency analysis.

    Expected:

    • @std/csv should not be reported as unused
    • @jsr/std__csv should not be reported as unlisted
    • unstorage should not be reported as unused
    • unstorage-nightly should not be reported as unlisted

    The resolver may need to preserve both names for pnpm package-source entries:

    • declared/import name: @std/csv, unstorage
    • resolved source name: @jsr/std__csv, unstorage-nightly

    Dependency usage should match against the declared/import name, not only the resolved source package name.

    Fallow version

    2.85.0

    Operating system

    macOS

    Configuration

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /fallow, current file: none) bash-$

  2. GLM Assistant

    Let me start by exploring the repository structure to understand the codebase.

  3. GLM Assistant

    Let me explore the crate structure.

  4. GLM Assistant

    Let me look at the project structure and resolver logic, especially for catalogs and package sources.

  5. GLM Assistant

    Let me look at the dead-code analysis flow.

  6. GLM Assistant

    The key issue is in how the dead-code analysis maps resolved package names back to declared package names. Let me understand the flow. The imports are resolved through the resolver. When pnpm uses jsr: or npm: package sources via catalogs, the resolver might resolve the import @std/csv to a node_modules path that points to @jsr/std__csv.

    Let me look at how unused_deps and the dead-code analysis work, and how package names get compared.

  7. GLM Assistant

    The graph.package_usage is the source of truth for what packages are used in imports. Let me look at how package_usage is populated, and especially package_usage_name().

  8. GLM Assistant

    Let me look at how the specifier is resolved and how the NpmPackage name is derived.

  9. GLM Assistant

    Let me see the rest of resolve_specifier where bare specifiers get resolved.

  10. GLM Assistant

    Let me understand how pnpm workspace/catalog info is parsed and available in the resolve context.

  11. GLM Assistant

    Let me see the helper function around line 950 and the broader context.

  12. GLM Assistant

    Let me look at extract_package_name and extract_package_name_from_node_modules_path.

  13. GLM Assistant

    Let me see what function contains line 950 and check the full set of NpmPackage construction sites.

  14. GLM Assistant

    So line 950 is inside try_style_condition_package_resolution. Let me also find the function containing line 1003 (the main resolve_specifier) and the helper at line ~940-960 in a different function. Let me find all NpmPackage( construction sites with line numbers.

  15. GLM Assistant

    Let me look at each NpmPackage site with surrounding context.

  16. GLM Assistant

    Let me look at the ResolveContext struct to see what data is available.

  17. GLM Assistant

    Let me check how the resolve functions call resolve_specifier and whether there are other NpmPackage construction sites.

  18. GLM Assistant

    There are also NpmPackage sites in fallbacks.rs. Let me examine those.

  19. GLM Assistant

    Now I understand the architecture. The fix: when a bare import specifier resolves to a node_modules package whose physical name differs from the package name derived from the import specifier (due to pnpm package sources, npm-protocol aliases, or overrides), credit the specifier-derived (declared/import) name as canonical for dependency accounting.

    Let me first reproduce the issue with a test fixture to confirm. Let me check existing pnpm catalog tests for patterns.

  20. GLM Assistant

    Let me look at the existing issue-329 fixture to understand fixture structure with node_modules.

  21. GLM Assistant

    Let me look at existing resolver tests that set up pnpm node_modules structures.

  22. GLM Assistant

    Let me look at the jsr/npm specifier tests and the test helper that builds a ResolveContext.

  23. GLM Assistant

    Let me find a test that resolves a bare specifier to a real node_modules package and checks the NpmPackage name, to model my reproduction.

  24. GLM Assistant

    Let me look at the test around line 1439 that builds a real ctx.

  25. GLM Assistant

    I'll create a temporary standalone reproduction test. Let me first check the public API for unused/unlisted dependencies.

  26. GLM Assistant

    Let me look at how the integration test common creates a config and how analyze is called, and what AnalysisResults contains for unused/unlisted. Let me look at the common module and the dead-code integration. Actually, let me look at how dead-code is computed. The issue mentions fallow dead-code. Let me check how that maps to results. The dead-code command combines unused files, exports, dependencies, etc. Let me find the dead-code command.

  27. GLM Assistant

    Let me look at the integration test common helpers to build a config.

  28. GLM Assistant

    Let me check the AnalysisResults struct fields.

  29. GLM Assistant

    Now let me create a temporary reproduction test to confirm the bug.

  30. GLM Assistant

    I've reproduced the bug exactly as described. Now let me implement the fix. First, add a helper function to path_info.rs.

  31. GLM Assistant

    Now let me add the helper function after extract_package_name in path_info.rs:

  32. GLM Assistant

    Let me insert the helper using the edit command. I'll edit the line range that contains the closing of extract_package_name and the start of the normalize comment. Lines 78-83 are the end of extract_package_name. The blank line 82, then line 83 is the doc comment for normalize_npm_specifier. Let me insert between line 81 (closing brace) and 83 (doc comment). I'll replace line 82 (blank) with the helper plus blank.

    Actually let me use the edit command with a line range. Line 82 is blank. I'll replace lines 82:82 (the blank line) with the helper text followed by a blank line.

    Wait, but the helper references is_bare_specifier, extract_package_name, is_valid_package_name which are defined above in the same file. Good.

    Let me open the file first.

  33. GLM Assistant

    The [must_use] needs a #. Let me fix that.

  34. GLM Assistant

    The sed didn't match because of the bracket. Let me check the actual bytes.

  35. GLM Assistant

    Now let me export the helper from the resolve module:

  36. GLM Assistant

    Now let me update the import in specifier.rs and apply the helper at the construction sites. First check the imports in specifier.rs:

  37. GLM Assistant

    Now let me look at all the sites to apply the helper. Let me view each occurrence with context to confirm variable names.

  38. GLM Assistant

    Let me view site 982 (the .map form) in context:

  39. GLM Assistant

    Now let me apply the helper at each construction site. Let me view the exact text at each site and do targeted replacements.

  40. GLM Assistant

    Now sites 1149, 1179, 1209 in resolve_specifier. Let me view their exact context.

  41. GLM Assistant

    Now let me apply the helper at sites 1155, 1185, 1215:

  42. GLM Assistant

    Let me also update the .map(ResolveResult::NpmPackage) form in the style function for consistency:

  43. GLM Assistant

    Now let me build and run the reproduction test:

  44. GLM Assistant

    The fix works. Now let me run the existing test suites to ensure no regressions.

  45. GLM Assistant

    All graph tests pass. Now let me run the core integration tests for dependencies and pnpm catalogs.

  46. GLM Assistant

    All integration tests pass. Let me run the core unit tests too.

  47. GLM Assistant

    Let me also run config and types tests to be safe.

  48. GLM Assistant

    Let me verify the unused-dependencies (not unlisted) analysis also uses graph.package_usage so the fix fully addresses both directions.

  49. GLM Assistant

    Both directions use graph.package_usage, which is built from package_usage_name() — the fix flows through both. Now let me remove the temporary test file and run clippy on the changed crate.

  50. GLM Assistant

    No clippy warnings. Let me run clippy including tests for the graph crate.

  51. GLM Assistant

    Let me run rustfmt to ensure formatting matches the repo style.

  52. GLM Assistant

    Let me review the final diff to make sure everything is correct.

  53. GLM Assistant

    The diff is clean. Let me do a final workspace build to ensure nothing else broke from the new public export.

  54. GLM Assistant

    The build is clean. Let me do a final review of the checklist before submitting.

    Let me verify the reproduction one final time by re-confirming the test passes with the fix (re-create temporarily, run, remove):

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.