Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· 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. MiniMax Assistant

    I'll analyze this issue carefully. The problem is that Fallow is incorrectly handling pnpm package sources (like jsr: and npm:<name>@<version>) where the declared name in package.json differs from the resolved package name.

    Let me start by exploring the repository structure.

  3. MiniMax Assistant

    Now let's look at how the workspace is configured and how dependencies are handled:

  4. MiniMax Assistant

    Now let me look at how dependencies are resolved and find the relevant code:

  5. MiniMax Assistant

    Let me look at the package detection logic and how dependencies are tracked:

  6. MiniMax Assistant

    Now let me look at how workspace pnpm package alias detection works:

  7. MiniMax Assistant

    Now let me look at where the issue likely occurs - in the dependency handling and resolver:

  8. MiniMax Assistant

    Let me look at how the resolvers resolve package.json dependencies to understand the issue:

  9. MiniMax Assistant

    Now I have a good idea of the structure. Let me find where pnpm package sources are converted to a resolved name (e.g., @std/csv -> @jsr/std__csv):

  10. MiniMax Assistant

    Let me look at the issue more carefully - the issue is in the package resolution. When the user declares a dep like @std/csv: jsr:1.0.6, pnpm resolves to @jsr/std__csv. Let me understand how the package gets its name when installed:

  11. MiniMax Assistant

    Let me reproduce the issue first. Let me build and run fallow:

  12. MiniMax Assistant

    Now let me create the reproduction:

  13. MiniMax Assistant

    I notice that without node_modules, the imports are resolved as bare specifiers and there's no unlisted dep / unused dep. Let me set up node_modules to match what pnpm would actually create:

  14. MiniMax Assistant

    Wait, pnpm creates symlinks that map the declared name to the resolved name. Let me set that up properly:

  15. MiniMax Assistant

    Hmm, the issue requires actual resolution. Since apps/cli/node_modules/@std/csv resolves to node_modules/@jsr/std__csv whose package.json has name: "@jsr/std__csv", fallow sees that and reports @std/csv as unused but @jsr/std__csv as unlisted. Let me trace what fallow does. First, let me check what extract_package_name_from_node_modules_path returns:

  16. MiniMax Assistant

    Hmm, the unused_dependencies don't show up because there's no entry point. Let me set up entry points:

  17. MiniMax Assistant

    Hmm. The issue must be when node_modules actually exists. Let me check by looking at the resolve flow more closely:

  18. MiniMax Assistant

    So unlisted dependencies means imported but not listed. Let me check the real source code path. Maybe I'm missing a node_modules in the right path:

  19. MiniMax Assistant

    Hmm, I need to look more carefully. Let me check what fallow does for the resolution - it might be looking at the on-disk package.json's name field which would be @jsr/std__csv for the JSR package:

  20. MiniMax Assistant

    Hmm, no issues! Let me look at the resolve code more carefully. Maybe the bare specifier resolution returns the package.json name from the on-disk location. Let me check:

  21. MiniMax Assistant

    Let me look at the resolve function:

  22. MiniMax Assistant

    Now I see! When a bare specifier is resolved, fallow goes through the resolved path and extracts the package name. In the case of @std/csv, the symlink resolves to node_modules/@jsr/std__csv/..., so it extracts @jsr/std__csv as the package name. That's the issue!

    Let me look at this code in more detail and see how the bug occurs:

  23. MiniMax Assistant

    Let me look at where package_usage_name comes from:

  24. MiniMax Assistant

    Now I understand the flow better. Let me check how the bare specifier resolution returns the package name. Specifically, when the user imports @std/csv/stringify:

    • It gets resolved through node_modules/@std/csv/stringify which is a symlink to node_modules/@jsr/std__csv/stringify
    • The path is canonicalized to the actual location node_modules/@jsr/std__csv/stringify
    • Then extract_package_name_from_node_modules_path is called, which returns @jsr/std__csv
    • That's stored as NpmPackage("@jsr/std__csv")

    This is the bug. We need to:

    1. Detect when a resolved path is reached through a symlink in node_modules where the declared name differs from the actual package.json name
    2. In that case, use the declared name (the import specifier's package name, e.g., @std/csv) instead of the actual on-disk package.json's name field

    Let me explore the code further:

  25. MiniMax Assistant

    Now let me check where oxc_resolver is configured and how it relates to package.json reading:

  26. MiniMax Assistant

    Let me check what fallow does at the resolver level. When it resolves @std/csv, the underlying oxc_resolver returns the resolved path. The package.json is read by oxc_resolver and the name field is accessible via Resolution.package_json.

  27. MiniMax Assistant

    Let me check oxc_resolver's API:

  28. MiniMax Assistant

    So PackageJson::path() is the symlinked path (e.g., node_modules/@std/csv/package.json), and PackageJson::realpath() is the canonicalized path (e.g., node_modules/@jsr/std__csv/package.json).

    Now let me look at the current resolution to see what package name is reported:

  29. MiniMax Assistant

    Now I see the bug more clearly. Let me reproduce it more carefully. Let me check how extract_package_name_from_node_modules_path interacts when we have a symlink.

  30. MiniMax Assistant

    Let me check extract_package_name_from_node_modules_path. The path it gets is already canonicalized. Let me trace through:

    1. User imports @std/csv/stringify
    2. oxc_resolver.resolve_file() returns Resolution with path = node_modules/@jsr/std__csv/stringify/index.js (already canonicalized since it followed symlinks), or maybe not - let me check the symlinks behavior more carefully.

    Let me actually test the current behavior:

  31. MiniMax Assistant

    Now let me dig deeper into where fallow handles this. Let me check the actual logic with both paths:

    The bug is in extract_package_name_from_node_modules_path. When it receives the canonicalized path node_modules/@jsr/std__csv/stringify/index.js, it correctly extracts @jsr/std__csv. But the import specifier was @std/csv/stringify, so the package name should be @std/csv.

    The fix should: when resolving a bare specifier, compare the canonicalized path's package name against the specifier's package name. If they differ, this is a pnpm package-source alias case and we should use the specifier's package name.

    Let me look at how this is currently handled:

  32. MiniMax Assistant

    Let me think about the fix more carefully. When a bare specifier is resolved:

    1. The user wrote something like @std/csv/stringify
    2. oxc_resolver resolves it to e.g., node_modules/@jsr/std__csv/stringify/index.js (following the symlink at node_modules/@std/csv)
    3. The Resolution object has both path() (the canonical path) and package_json() (the package.json data with name)
    4. The current code extracts the package name from the canonical path, getting @jsr/std__csv

    The fix: We should detect when the import specifier's package name differs from the resolved package.json's name field, and use the specifier's package name in that case (since it's the one the user declared).

    Let me look at how Resolution.package_json is accessed:

  33. MiniMax Assistant

    Good. So we have access to the package.json's name. Now let me trace through more carefully. Look at where bare specifiers are resolved and check the package.json name:

  34. MiniMax Assistant

    Now let me think about the proper fix. Looking at the code at line 1139:

    if is_bare
        && !resolved_path
            .as_os_str()
            .as_encoded_bytes()
            .windows(7)
            .any(|w| w == b"/.pnpm/" || w == b"\\.pnpm\\")
        && let Some(pkg_name) = extract_package_name_from_node_modules_path(resolved_path)
        && !ctx.workspace_roots.contains_key(pkg_name.as_str())
    {
        return if should_preserve_node_modules_style_file(...) {
            ResolveResult::ExternalFile(resolved_path.to_path_buf())
        } else {
            ResolveResult::NpmPackage(pkg_name)
        };
    }
    

    The issue: When we have a symlinked package like @std/csv -> @jsr/std__csv, the resolved_path returned by oxc_resolver.resolve_file should be the canonicalized path node_modules/@jsr/std__csv/stringify/index.ts. So extract_package_name_from_node_modules_path returns @jsr/std__csv.

    Wait, let me actually verify what oxc_resolver returns for the path. Let me write a small Rust test:

  35. MiniMax Assistant

    Let me run this through cargo:

  36. MiniMax Assistant

    The symlink looks right. The issue is that @std/csv/stringify resolves to node_modules/@std/csv/stringify but the symlink target doesn't have a stringify directory under it... let me check:

  37. MiniMax Assistant

    Oh interesting - the symlink doesn't follow through directory symlinks. Let me fix this by creating the symlink correctly:

  38. MiniMax Assistant

    Good - the symlink works correctly: @std -> node_modules/@jsr/std__csv, so @std/csv resolves through @std (which is node_modules/@jsr/std__csv) and looks for csv inside. But there's no csv directory inside @jsr/std__csv. So the resolution fails.

    Let me make a more realistic pnpm-like structure where the symlink name matches what pnpm would create:

  39. MiniMax Assistant

    Hmm, the symlink resolution isn't quite working. Let me check:

  40. MiniMax Assistant

    The link is broken - the symlink target path needs to be from the link location. Let me check why:

  41. MiniMax Assistant

    The link is broken because relative paths are resolved from the link's parent. Let me try with absolute path or do it differently:

  42. MiniMax Assistant

    Now we have leftover from the .pnpm structure. Let me simplify:

  43. MiniMax Assistant

    Now let me run fallow and see the issue:

  44. MiniMax Assistant

    Hmm, no issues. Maybe my entry points aren't pulling through. Let me try with full text format:

  45. MiniMax Assistant

    Hmm. The issue is that oxc_resolver follows the symlink and gets the right path, but extract_package_name_from_node_modules_path uses the canonical path. So the bug should be happening.

    Wait - the extract_package_name_from_node_modules_path takes the canonical path node_modules/@jsr/std__csv/stringify/index.ts and returns @jsr/std__csv. So NpmPackage("@jsr/std__csv") should be recorded.

    But then:

    • package_usage map gets @jsr/std__csv keyed
    • The user's dependencies declares @std/csv -> falls through to "unused_dep" finding
    • And @jsr/std__csv is "unlisted"

    So why don't I see these issues? Maybe the file isn't actually being traversed. Let me check more carefully:

  46. MiniMax Assistant

    Now I see! The resolution returns /tmp/repro/node_modules/@jsr/std__csv/stringify/index.ts which is the canonical path. But the file is being included in the analysis (since fallow resolves through the symlink and the target file index.ts is now part of the file set).

    Hmm, but no issues are found. The issue is that when the file is included as a "source", the import is treated as internal, not external. Let me look:

  47. MiniMax Assistant

    I see the issue. Looking at the resolve_specifier flow:

    1. oxc_resolver.resolve_file(from, specifier) returns the resolved path node_modules/@jsr/std__csv/stringify/index.ts (canonical).
    2. Then fallow checks ctx.raw_path_to_id.get(resolved_path) to see if it's an internal file. But the file is NOT in the source set, because node_modules/ is ignored.

    Wait, but my debug log shows that index.ts is being whitelisted:

    [DEBUG] whitelisting /tmp/repro/node_modules/@jsr/std__csv/stringify/index.ts
    

    So the file IS in fallow's file index! Let me check:

  48. MiniMax Assistant

    OK, so node_modules files are ignored. But why is index.ts being whitelisted? Let me check the discovery:

  49. MiniMax Assistant

    OK so node_modules is in default ignore. Let me look more carefully at what's happening - my reproduction must have node_modules whitelisted because of the "whitelist" output. Let me check:

  50. MiniMax Assistant

    So node_modules files are NOT included in fallow's file index. But the debug log showed them being "whitelisted" - that's just the Ignore matcher. Looking at the log:

    [DEBUG] ignoring /tmp/repro/apps/native/node_modules/unstorage: Ignore(IgnoreMatch(Types(Glob(UnmatchedIgnore))))
    [DEBUG] whitelisting /tmp/repro/node_modules/unstorage-nightly/index.ts
    

    These are logs of the ignore matcher processing - "whitelisting" here means the type-based matcher matched it (e.g., the file type matcher matched because it's a .ts file). The default ignore pattern **/node_modules/** should still exclude it.

    But wait, my repro shows only 4 files discovered - not the node_modules files. So the issue must be that something in the resolution treats these files differently.

    Let me trace the issue differently. Let me write a small reproducer that doesn't need node_modules. Let me look at the resolve flow more carefully:

  51. MiniMax Assistant

    OK so:

    1. After oxc_resolver.resolve_file, resolved_path is the canonicalized path (i.e., following symlinks). For our case, it's node_modules/@jsr/std__csv/stringify/index.ts.
    2. ctx.raw_path_to_id.get(resolved_path) - this is the lookup of files in fallow's index by their canonical path. Since the file isn't in fallow's index, this returns None.
    3. The code then checks if it's a bare specifier, and if the path looks like it's in node_modules, it extracts the package name.

    The package name extracted is @jsr/std__csv (from the canonical path).

    Now, the question is: when does fallow report "unused_dependencies" vs "unlisted_dependencies"?

    Let me look at the unused_deps.rs more carefully:

  52. MiniMax Assistant

    Let me look at where unlisted deps are detected:

  53. MiniMax Assistant

    OK, so:

    • find_unlisted_dependencies iterates over graph.package_usage, which is built from package_usage_name() which returns the NpmPackage name.
    • The NpmPackage name is @jsr/std__csv (extracted from the canonicalized resolved path).
    • is_package_listed_for_file checks if @jsr/std__csv is in dependencies of the file's workspace - it's NOT, so this package becomes an "unlisted" finding.

    But my repro doesn't show any findings. Let me look at package_usage:

  54. MiniMax Assistant

    Now let me trace through the resolution in my repro case more carefully. The issue must be that the file node_modules/@jsr/std__csv/stringify/index.ts IS being treated as an internal module (because it has the .ts extension and is in a directory that's whitelisted).

    Wait, I need to check whether the path returned by oxc_resolver is the canonical (symlink-followed) path or the original. Let me write a quick test:

  55. MiniMax Assistant

    Now I see it clearly! When the resolution succeeds:

    • The path is the canonicalized real path: /tmp/repro/node_modules/unstorage-nightly/index.ts
    • The package_json.path is the symlinked path: /tmp/repro/apps/native/node_modules/unstorage/package.json
    • The package_json.realpath is the canonical path: /tmp/repro/node_modules/unstorage-nightly/package.json
    • The package_json.name is unstorage-nightly (from the canonical package.json)

    So when oxc_resolver returns the canonical path, fallow extracts the package name from the canonical path, getting unstorage-nightly. That's the bug.

    For @std/csv/stringify, the resolution fails because node_modules/@jsr/std__csv has main: "./stringify/index.ts" but @std/csv/stringify looks for a file stringify.ts (or similar) inside @std/csv/, which doesn't exist.

    Let me fix the package.json to use proper exports:

  56. MiniMax Assistant

    Now I can see the issue clearly:

    • @std/csv/stringify resolves to node_modules/@jsr/std__csv/stringify/index.ts
    • package_json.path (symlinked) is /tmp/repro/apps/cli/node_modules/@std/csv/package.json
    • package_json.realpath (canonical) is /tmp/repro/node_modules/@jsr/std__csv/package.json
    • package_json.name (from canonical package.json) is @jsr/std__csv

    So the canonical path is used in fallow's resolution. When extract_package_name_from_node_modules_path is called on node_modules/@jsr/std__csv/stringify/index.ts, it returns @jsr/std__csv - the resolved package name, not the declared one.

    Now let me reproduce with fallow:

  57. MiniMax Assistant

    Still no issues! Let me add debug logging to see what package_usage contains:

  58. MiniMax Assistant

    Let me check what resolve_file returns in detail. Wait, the resolution succeeds with the canonical path. The flow is:

    1. oxc_resolver.resolve_file() returns the canonical path.
    2. The code at line 1129-1133: ctx.raw_path_to_id.get(resolved_path) returns None because node_modules/@jsr/std__csv/stringify/index.ts is NOT in fallow's file index.
    3. Then the code at line 1137: checks if is_bare (yes) and the path doesn't contain .pnpm/ (yes, but wait the symlink resolves to canonical path which doesn't have it).
    4. extract_package_name_from_node_modules_path(resolved_path) returns @jsr/std__csv.
    5. ctx.workspace_roots.contains_key("@jsr/std__csv") - false.
    6. So NpmPackage("@jsr/std__csv") is returned.

    Hmm, but the result is no findings. Let me check what's going on:

  59. MiniMax Assistant

    OK so path_to_id and raw_path_to_id map files in fallow's discovered file set. So for node_modules/@jsr/std__csv/stringify/index.ts to be returned as InternalModule, that path would need to be in the discovered file set, which it isn't.

    Let me check whether the oxc_resolver.resolve_file returned Ok or whether it failed. Let me look at the resolution in detail.

    Actually wait - I need to test this more carefully. Let me check what is_bare is in the resolve flow:

  60. MiniMax Assistant

    OK. Let me look at what try_style_condition_package_resolution does and also look at where is_bare is used:

    Wait, I see the issue. Look at is_bare_specifier:

  61. MiniMax Assistant

    OK so @std/csv/stringify is bare. The flow should work. Let me add some debugging:

  62. MiniMax Assistant

    Let me add a tracing to see what package name is being recorded:

  63. MiniMax Assistant

    Let me add temporary debug output to see what's happening:

  64. MiniMax Assistant

    Let me add tracing temporarily:

  65. MiniMax Assistant

    Let me approach this differently. Let me look at the actual files and trace through manually:

  66. MiniMax Assistant

    Let me actually add some debugging temporarily:

  67. MiniMax Assistant

    That didn't go well. Let me restore:

  68. MiniMax Assistant

    Let me apply the debug edits properly:

  69. MiniMax Assistant

    The bug is confirmed:

    • For unstorage, the resolved path is node_modules/unstorage-nightly/index.ts (canonical), extracted package name is unstorage-nightly.
    • For @std/csv/stringify, the resolved path is node_modules/@jsr/std__csv/stringify/index.ts (canonical), extracted package name is @jsr/std__csv.

    So NpmPackage("unstorage-nightly") and NpmPackage("@jsr/std__csv") are returned. These should be credited as unstorage and @std/csv (the declared names).

    But the result is "No issues found"! That's weird. Let me investigate more:

  70. MiniMax Assistant

    OK so the issue is that my reproduction setup doesn't actually trigger the bug because:

    1. The issue is that @jsr/std__csv should appear as unlisted_dep
    2. AND @std/csv should appear as unused_dep

    But there are no findings. Let me look at the analysis more carefully. Maybe it's a different code path:

  71. MiniMax Assistant

    OK so find_unused_dependencies is called for the root pkg. But my issue is in the workspace packages. Let me check workspace analysis:

  72. MiniMax Assistant

    OK so find_unused_dependencies is called once for the root pkg. But what about workspace packages? Let me look:

  73. MiniMax Assistant

    OK so is_package_listed_for_file checks the workspace's deps. For a file in apps/cli/, the workspace is apps/cli with deps {"@std/csv": "catalog:"}. So @std/csv is in deps, but @jsr/std__csv is not. So @jsr/std__csv should appear as unlisted.

    But it's not appearing! Let me check why. Maybe the package_usage doesn't contain @jsr/std__csv because the file is being classified differently. Let me look at record_graph_package_usage:

  74. MiniMax Assistant

    OK this is for workspace package self-references, not relevant here. Let me focus on understanding why my repro isn't triggering the issue.

    Wait, let me check:

  75. MiniMax Assistant

    Let me dig deeper. Add more debug to see what's happening in graph build:

  76. MiniMax Assistant

    OK so @jsr/std__csv and unstorage-nightly ARE in package_usage. But they're not being reported as unlisted. Let me check the analysis:

  77. MiniMax Assistant

    Let me check is_builtin_module and is_virtual_module:

  78. MiniMax Assistant

    Hmm, @jsr/std__csv is not a builtin module. So it should be reported. Let me add more debugging to find_unlisted_dependencies:

  79. MiniMax Assistant

    Let me add debug:

  80. MiniMax Assistant

    The DEBUG find_unlisted: checking is not appearing. So the issue is that find_unlisted_dependencies is never called! Let me look more carefully at when it's called:

  81. MiniMax Assistant

    Hmm, find_unlisted_dependencies should be called when config.rules.unlisted_dependencies != Severity::Off. But this is only called for the ROOT package (pkg is PackageJson::load(&pkg_path)). What about workspaces?

    Let me search for where workspace-specific dependency checks happen:

  82. MiniMax Assistant

    So there's no workspace-level analysis for unused_deps! That means workspace dependencies are only checked at the root level. Let me look at how workspace packages contribute to root deps:

  83. MiniMax Assistant

    Hmm, so find_unused_dependencies is called for root pkg. Let me look at how it iterates - the unused deps are determined by what dependencies the root pkg lists that aren't used:

  84. MiniMax Assistant

    OK so workspace deps are checked via is_used_in_workspace. Now let me understand: the workspace @example/cli has deps {"@std/csv": "catalog:"}. When we check if @std/csv is used, we look at package_workspace_usage.get("@std/csv") which should contain the workspace roots that use @std/csv. But @jsr/std__csv is what's stored in package_usage, not @std/csv! That's why the check fails.

    Let me verify this is actually the issue. Let me check package_workspace_usage:

  85. MiniMax Assistant

    OK so for the workspace @example/cli, the dep @std/csv is checked: is_used_in_workspace("@std/csv") calls package_workspace_usage.get("@std/csv").is_some_and(...). But package_workspace_usage has @jsr/std__csv, not @std/csv. So @std/csv is "unused" - and it should appear in the unused_dependencies.

    But the output shows unused_dependencies: []! Let me check if there's some skip:

  86. MiniMax Assistant

    The DEBUG output isn't appearing - meaning find_unused_dependencies isn't being called. Let me check the severity rules:

  87. MiniMax Assistant

    Let me check what the default is:

  88. MiniMax Assistant

    Default is Severity::Error. So the analysis should run. Hmm, let me check where the workspace_findings is. Oh wait, I'm checking the production code path. Let me look for the output:

  89. MiniMax Assistant

    So find_unused_dependencies is called when unused_dependencies != Off. With default Error, it should run. Maybe pkg is None. Let me check:

  90. MiniMax Assistant

    There's NO root package.json! That's why pkg is None. Let me add one:

  91. MiniMax Assistant

    I've reproduced the bug exactly as described in the issue:

    1. @std/csv reported as unused dependency
    2. @jsr/std__csv reported as unlisted dependency
    3. unstorage reported as unused dependency
    4. unstorage-nightly reported as unlisted dependency

    Now let me clean up the debug code and design the fix.

  92. MiniMax Assistant

    Now let me design the fix. The key insight is:

    When a bare specifier like @std/csv/stringify is resolved by oxc_resolver:

    1. The Resolution.path is the canonical path: node_modules/@jsr/std__csv/stringify/index.ts (following symlinks)
    2. The Resolution.package_json().path() is the symlinked path: node_modules/@std/csv/package.json
    3. The Resolution.package_json().realpath() is the canonical path: node_modules/@jsr/std__csv/package.json
    4. The Resolution.package_json().name() is the name from the canonical package.json: @jsr/std__csv

    When this happens, the declared name @std/csv differs from the resolved name @jsr/std__csv. This is the pnpm package-source alias case (jsr:, npm:@).

    The fix: When we detect that the specifier's package name differs from the resolved package.json's name, we should use the specifier's package name for dependency usage credit. This way:

    • @std/csv is recognized as used in package_usage
    • @std/csv is in the workspace's dependencies, so it's not flagged as unused
    • @jsr/std__csv is not in package_usage, so it's not flagged as unlisted

    Let me also check that this isn't a problem for other cases like:

    • Normal packages (resolved name = declared name) - should work as before
    • Scoped packages with normal layout - should work as before
    • Workspace packages (self-references) - handled by try_workspace_package_fallback

    Now let me design the fix:

  93. MiniMax Assistant

    Now let me see what oxc_resolver exposes. Looking at Resolution.package_json(), it returns Option<&Arc<PackageJson>>. The package.json has path(), realpath(), and name().

    The fix should be in resolve_specifier in /fallow/crates/graph/src/resolve/specifier.rs. When we determine the package name for NpmPackage, we should:

    1. First extract the package name from the specifier (e.g., @std/csv from @std/csv/stringify).
    2. Use Resolution.package_json().name() to get the canonical name (e.g., @jsr/std__csv).
    3. If they differ, prefer the specifier's package name (since it's the declared name).

    Wait, but there's an additional concern. For try_workspace_package_fallback, we want to credit the workspace package by its declared name too. Let me look at that.

    Actually, let me think about this more carefully. The fix should be at the point where we determine the package name for NpmPackage. Let me extract a helper function:

  94. MiniMax Assistant

    OK now let me implement the fix. The approach:

    1. After we get Resolution from oxc_resolver, we extract the package name from the resolved path.
    2. We also look at Resolution.package_json().name() to see the canonical name.
    3. If they differ, we prefer the specifier's package name (since it's the user-declared name).

    Let me write the fix:

  95. MiniMax Assistant

    Let me see the oxc_resolver imports more carefully:

  96. MiniMax Assistant

    Now let me look at all the places where NpmPackage is constructed in the resolved code to make sure my fix covers them all:

  97. MiniMax Assistant

    Let me also check the fallbacks module:

  98. MiniMax Assistant

    So there are several places where NpmPackage is constructed. Let me design a clean approach:

    The issue is that when a bare specifier resolves through a symlink, the canonical name (from package.json) may differ from the declared name. The right approach is:

    1. At the point where we extract the package name from a node_modules path, compare with Resolution.package_json().name().
    2. If they differ, use the specifier's package name (since that's the declared name).

    The key insight: the specifier's package name should always be used for dependency credit. The resolved canonical name should only be used when the specifier's name matches.

    Let me look at where Resolution is used to extract the package name:

  99. MiniMax Assistant

    Now let me look at the resolution:

  100. MiniMax Assistant

    Now I'll implement the fix. The approach:

    1. Create a helper function that, given the specifier and the resolved Resolution, returns the canonical package name (i.e., the name that should be used for dependency accounting).
    2. This helper prefers the specifier's package name (since it's the declared name), unless that conflicts with the resolved package.json's name in a way that suggests something else.

    Let me design it:

  101. MiniMax Assistant

    Now let me write the fix. I'll modify extract_package_name_from_node_modules_path to also accept a specifier for context, OR I'll add a new helper that combines the information.

    Actually, the cleanest approach is:

    1. Get the specifier's package name (e.g., @std/csv)
    2. Get the resolved path's package name (e.g., @jsr/std__csv)
    3. Get the canonical package.json's name field (e.g., @jsr/std__csv)
    4. If the specifier's name and the canonical name differ, use the specifier's name (since that's the declared name).

    Let me also think about this: in the case where the canonical name and the resolved-path-extracted name differ, the specifier name might still be different from both. We should prefer the specifier's name in that case too.

    Actually, the simplest implementation: always prefer the specifier's package name when the canonical package.json's name differs from the specifier's package name.

    Let me look at how I can read the canonical name. Looking at the resolution structure:

  102. MiniMax Assistant

    OK, fallow's resolver doesn't currently read resolution.package_json(). Let me add that capability. Let me see the full context of the main resolve_specifier function:

  103. MiniMax Assistant

    Now let me design the fix. I'll create a helper function resolve_npm_package_name that takes the specifier and the resolved Resolution, and returns the canonical package name to use:

  104. MiniMax Assistant

    Let me look at the structure more carefully. Now let me also understand what happens with resolve_file_with_resolver_and_tsconfig_fallback:

  105. MiniMax Assistant

    Now let me write the fix. The approach:

    1. Create a helper function resolve_specifier_package_name(specifier, resolved, fallback_path) that returns the package name to use for NpmPackage.
    2. In each spot where NpmPackage(pkg_name) is created, use this helper instead of just extracting from path.

    Let me look at all the relevant places again carefully:

  106. MiniMax Assistant

    Now let me look at the other NpmPackage cases in specifier.rs:

  107. MiniMax Assistant

    Now let me design the fix. I will:

    1. Add a helper function pnpm_alias_package_name(specifier: &str, resolved_pkg_json_name: Option<&str>, canonical_pkg_name_from_path: Option<&str>) -> Option<String> that detects the pnpm alias case and returns the specifier's name.
    2. Apply this helper in the relevant code paths.

    Actually, a simpler approach: since the specifier is what the user wrote, we should always prefer the specifier's package name when we have a Resolution with a package.json whose name differs from the specifier's name.

    Let me now write the fix:

  108. MiniMax Assistant

    Now let me think about the fix more carefully. I need to:

    1. Look at the Resolution to see the canonical package.json's name field.
    2. Compare with the specifier's package name.
    3. If they differ, prefer the specifier's package name.

    But the existing code structure is a bit awkward. Let me make the fix more direct. The key fix is in the resolved path-based package name extraction.

    Let me design the helper function:

    /// Given a specifier, the resolved path, and the Resolution's package.json,
    /// return the canonical package name for `NpmPackage`. If the resolved
    /// package.json's `name` field differs from the specifier's package name
    /// (indicating a pnpm package-source alias like `jsr:`, `npm:<name>@<ver>`),
    /// prefer the specifier's package name since it's the declared name.
    fn canonical_npm_package_name(
        specifier: &str,
        resolved_pkg_json_name: Option<&str>,
        path_pkg_name: &str,
    ) -> String {
        let specifier_pkg_name = extract_package_name(specifier);
        
        // If the resolved package.json has a name that differs from the specifier's
        // package name, this is a pnpm package-source alias case. Use the specifier's
        // name to credit the declared dependency rather than the resolved name.
        if let Some(canonical_name) = resolved_pkg_json_name {
            if canonical_name != specifier_pkg_name {
                return specifier_pkg_name;
            }
        }
        
        // Otherwise use the path-based name (which should match the specifier's name
        // for non-alias packages).
        path_pkg_name.to_string()
    }
    

    But wait, this won't work for the case where Resolution isn't passed in. Let me think differently.

    Actually, the right approach is: in the resolve function, when we determine the package name for NpmPackage, we should look at the Resolution.package_json() and use that to disambiguate.

    Let me write the fix now:

  109. MiniMax Assistant

    Now let me implement the fix. The cleanest approach:

  110. MiniMax Assistant

    Let me now write the helper function and update all the NpmPackage construction sites:

  111. MiniMax Assistant

    Now let me write the fix. I'll add a helper function and use it in the relevant places:

  112. MiniMax Assistant

    Now let me update the code paths that create NpmPackage. Let me look at the current code again:

  113. MiniMax Assistant

    Let me look at all the places and understand each context:

  114. MiniMax Assistant

    This is try_style_condition_package_resolution (different resolver). It doesn't have the package.json info. Let me check what resolved is:

  115. MiniMax Assistant

    OK, this function gets a Resolution. So I have access to resolved.package_json(). Let me update the helper to take Resolution directly:

  116. MiniMax Assistant

    Wait, I need to put the tests at the bottom of the file. Let me also put it in the right place:

  117. MiniMax Assistant

    Let me move these tests to the bottom of the file (or remove them temporarily while I develop the fix - I can add them back at the end):

  118. MiniMax Assistant

    Now let me update the call sites that construct NpmPackage to use the helper. Let me start with the main resolve_specifier function:

  119. MiniMax Assistant

    Let me first add the Resolution access in the main resolve_specifier function:

  120. MiniMax Assistant

    Now let me update the other NpmPackage call sites in the same function:

  121. MiniMax Assistant

    Now let me look at the failed case:

  122. MiniMax Assistant

    This is the failed case where the resolver couldn't resolve. The specifier is the only source for the package name, so this doesn't need a fix.

    Now let me check the try_style_condition_package_resolution function:

  123. MiniMax Assistant

    This is try_style_condition_package_resolution. Let me update it too:

  124. MiniMax Assistant

    Now let me check the fallbacks.rs too:

  125. MiniMax Assistant

    This is the SCSS fallback. It doesn't have access to Resolution.package_json() directly. Let me look at it:

  126. MiniMax Assistant

    These are package imports (Node.js subpath imports), not pnpm package sources. They don't need the fix.

    Let me check the SCSS node_modules fallback more carefully:

  127. MiniMax Assistant

    This is the SCSS-specific node_modules search. It doesn't use oxc_resolver. But it's possible for SCSS imports to use pnpm aliases. For now, let me leave this as-is since it's less common and the SCSS resolution doesn't have the package.json info readily available.

    Let me first build and test my current fix:

  128. MiniMax Assistant

    The fix works! Now @std/csv and unstorage are correctly credited as used, and @jsr/std__csv and unstorage-nightly are no longer flagged as unlisted.

    Let me also confirm the output with the JSON format:

  129. MiniMax Assistant

    All issues are gone! Now let me think about edge cases and add tests.

    Let me first check what happens with the catalog references issue. Since the user declares @std/csv: catalog: and the catalog maps to jsr:@std/csv@1.0.6, let me check if catalog analysis is also affected:

  130. MiniMax Assistant

    Catalog entries are also not flagged as unused. Let me think more carefully about this. The catalog has @std/csv -> jsr:1.0.6. The user uses @std/csv: catalog: in package.json. The catalog analysis should see that @std/csv is referenced.

    Let me check how consumers.references is built:

  131. MiniMax Assistant

    OK so the catalog analysis walks package.json files directly, looking for catalog: references. It doesn't use package_usage. So my fix doesn't affect catalog analysis (which is correct).

    Now let me think about edge cases:

    1. Normal packages: @std/csv declared and imported, package on disk has name: "@std/csv". My fix: specifier_pkg_name = "@std/csv", canonical_name = "@std/csv", they match, use path_pkg_name = "@std/csv". Same as before.

    2. pnpm jsr alias: @std/csv declared and imported, package on disk has name: "@jsr/std__csv". My fix: specifier_pkg_name = "@std/csv", canonical_name = "@jsr/std__csv", they differ, use specifier_pkg_name = "@std/csv".

    3. pnpm npm alias: unstorage declared and imported, package on disk has name: "unstorage-nightly". My fix: specifier_pkg_name = "unstorage", canonical_name = "unstorage-nightly", they differ, use specifier_pkg_name = "unstorage".

    4. Package with self-reference where name matches specifier: Package declares name: "my-pkg", imported as "my-pkg". My fix: specifier_pkg_name = "my-pkg", canonical_name = "my-pkg", they match, use path_pkg_name.

    5. Workspace package self-reference: Already handled by try_workspace_package_fallback with InternalPackageModule. No issue.

    Now let me also think about: 6. Specifier with subpath: @std/csv/stringify resolves through @std/csv -> @jsr/std__csv. The package.json's name is @jsr/std__csv. specifier_pkg_name = "@std/csv", they differ, use "@std/csv". Correct.

    1. No canonical name from package.json (e.g., a package without name field): resolved_pkg_json_name = None, falls back to path_pkg_name. Same as before.

    Let me also think about whether the fix should be applied to try_scss_node_modules_fallback. Looking at it:

    • It's a fallback that searches for SCSS files in node_modules.
    • The specifier is rewritten to ./<bare> (i.e., relative-like) before the search.
    • If found, it returns NpmPackage(extracted_name).

    This is for SCSS imports like @import 'bootstrap/scss/functions' -> searches for _functions.scss in node_modules/bootstrap/scss/. The "bare" specifier here is bootstrap/scss/functions. The extracted package name from the resolved path would be bootstrap (the first segment of the path).

    In this case, there's no Resolution object, so we can't easily check the canonical name. But SCSS imports typically don't go through pnpm aliases as often. Let me leave this case for now and focus on the main fix.

    Now let me also verify the fix works correctly when there's no node_modules at all:

  132. MiniMax Assistant

    Good. Let me restore the node_modules for further testing:

  133. MiniMax Assistant

    Now let me run fallow with the fix:

  134. MiniMax Assistant

    The fix works. Now let me verify the fix more thoroughly by also testing what happens if you actually use the wrong package (an unused dep should still be detected):

  135. MiniMax Assistant

    Excellent! The unused lodash is still correctly detected.

    Let me also verify the opposite case - if I import something not in dependencies, it should still be flagged:

  136. MiniMax Assistant

    Hmm, path should be a builtin so it should be fine. Let me try a non-declared dep:

  137. MiniMax Assistant

    The unlisted dep detection still works correctly. Now let me also test with a pnpm jsr alias that DOES NOT exist in the imports - to ensure unused dep detection works:

  138. MiniMax Assistant

    Wait, lodash is used in the import but it's not declared in apps/cli/package.json. The dep ramda is declared but not imported. Let me check - actually lodash is not declared. So lodash is unlisted, and ramda should be unused. Let me check:

  139. MiniMax Assistant

    Hmm, ramda is declared but not imported (since I removed the import R from 'ramda'). But it's not being detected as unused. Let me check the file content:

  140. MiniMax Assistant

    It still has ramda import. Let me remove it:

  141. MiniMax Assistant

    Both unused and unlisted deps are detected correctly.

    Now let me make sure I haven't broken any existing tests. Let me run the existing tests:

  142. MiniMax Assistant

    Only one test failed: fix_batch_aborts_when_a_target_directory_is_read_only. Let me check if this is related to my fix or it's a pre-existing issue:

  143. MiniMax Assistant

    OK, this test is failing BEFORE my changes too. It's a pre-existing issue, likely related to running as root in this container. Not related to my fix.

    Now let me add proper tests for my fix. Let me look at existing test infrastructure:

  144. MiniMax Assistant

    Let me look at a test that creates a more complete context with workspace_roots and node_modules:

  145. MiniMax Assistant

    Let me find a test that creates real node_modules structure with the resolver:

  146. MiniMax Assistant

    Good, I have an example. Let me write the test for my fix:

  147. MiniMax Assistant

    Let me look at the workspace test:

  148. MiniMax Assistant

    Now let me write tests for my fix. I'll add them to tests.rs:

  149. MiniMax Assistant

    Let me look at how to build a real ResolveContext with package resolution:

  150. MiniMax Assistant

    Now let me write tests for my fix. First let me find a good place to add them:

  151. MiniMax Assistant

    Let me look at how to build a real ResolveContext with workspace_roots:

  152. MiniMax Assistant

    OK now I understand the test pattern. Let me write the tests. I need to test:

    1. pnpm jsr: alias: A package declared as @std/csv but resolved to @jsr/std__csv. The fix should credit @std/csv.
    2. pnpm npm: alias: A package declared as unstorage but resolved to unstorage-nightly. The fix should credit unstorage.

    Let me add tests using the test infrastructure:

  153. MiniMax Assistant

    Let me look at the actual types:

  154. MiniMax Assistant

    OK, the type for PackageManifestInfo is pub(super). Let me look at how the existing tests work without it:

    Actually, since package_manifests is &'a [PackageManifestInfo] and PackageManifestInfo is pub(super), I need to access it through the module path. Let me look at the test infrastructure more carefully:

  155. MiniMax Assistant

    The test is in the same module so it should be able to use the path super::PackageManifestInfo. Let me look at a cleaner approach. Instead of building the whole context from scratch, let me follow the existing pattern in the test:

  156. MiniMax Assistant

    Wait, this approach is overcomplicated. Let me take a simpler approach - rewrite the test helper to use a simpler pattern. Looking at how with_empty_ctx does it:

  157. MiniMax Assistant

    OK so the existing pattern is: take a closure, build the context, pass it in. The closure consumes it.

    Let me rewrite my test helper to use this pattern. First, let me revert my change:

  158. MiniMax Assistant

    Now let me write the tests properly using a closure pattern:

  159. MiniMax Assistant

    PackageManifestInfo is pub(super) but the tests are in the same module. Let me use super::types::PackageManifestInfo:

  160. MiniMax Assistant

    Now let me run the tests:

  161. MiniMax Assistant

    All my pnpm alias tests pass. Let me also verify the non-aliased test:

  162. MiniMax Assistant

    Now let me also add unit tests for the canonical_npm_package_name helper in specifier.rs. Let me first move the test module to the end of the file:

  163. MiniMax Assistant

    Now let me add unit tests for the helper. Let me add them to specifier.rs:

  164. MiniMax Assistant

    Let me append my helper tests inside the existing tests mod:

  165. MiniMax Assistant

    Now let me add the helper unit tests to the existing tests module:

  166. MiniMax Assistant

    Let me update the imports:

  167. MiniMax Assistant

    Let me fix the test - I missed providing the specifier argument:

  168. MiniMax Assistant

    All 6 unit tests pass! Now let me run the broader test suite to make sure nothing else broke:

  169. MiniMax Assistant

    There's another test failing. Let me investigate:

  170. MiniMax Assistant

    Now it passes. Let me run the full workspace tests again:

  171. MiniMax Assistant

    OK only the pre-existing fix_batch_aborts_when_a_target_directory_is_read_only test is failing - this is unrelated to my change (it's a pre-existing failure when running as root). Let me verify that with git stash again:

  172. MiniMax Assistant

    Confirmed: the fix_batch_aborts_when_a_target_directory_is_read_only test fails BEFORE my changes too - it's a pre-existing issue unrelated to my fix.

    Now let me also run clippy to make sure my changes don't break any linting:

  173. MiniMax Assistant

    No clippy warnings. Let me also run fmt check:

  174. MiniMax Assistant

    Now let me also test my fix on the actual reproduction from the issue:

  175. MiniMax Assistant

    Let me restore the original repro setup:

  176. MiniMax Assistant

    Wait, what? Let me check - I think I didn't rebuild after my changes. Let me rebuild and test:

  177. MiniMax Assistant

    All issues are gone. Let me also run the cli format to see the human output:

  178. MiniMax Assistant

    Let me now also think about edge cases that might be missed:

    1. What if the same package is referenced in two different ways?

      • E.g., apps/cli/foo.ts imports @std/csv/stringify (via symlink to @jsr/std__csv).
      • apps/cli/bar.ts imports @jsr/std__csv directly (which doesn't exist but we don't expect this).
      • In this case, the specifier's package name is @std/csv in both cases, but if someone directly imports @jsr/std__csv, that would be @jsr/std__csv. Since the canonical name is @jsr/std__csv and the specifier is also @jsr/std__csv, my fix uses the specifier name, which is correct.
    2. What about pnpm overrides (not catalog)?

      • The issue example uses catalogs, but the underlying mechanism is the same: pnpm creates a symlink with a different name and the canonical package.json has the resolved name.
      • The fix should work the same for any pnpm aliasing mechanism.
    3. What about catalog references in package.json?

      • The catalog reference "@std/csv": "catalog:" is resolved to "@std/csv": "jsr:1.0.6" by pnpm at install time.
      • My fix doesn't affect catalog resolution itself.
    4. What about workspaces that share a package?

      • Workspace A imports @std/csv, Workspace B imports @jsr/std__csv directly.
      • A's import is credited to @std/csv (correct).
      • B's import is credited to @jsr/std__csv (also correct, since they're importing it directly).

    Now let me look at the try_workspace_package_fallback to make sure my fix doesn't break workspace package resolution:

  179. MiniMax Assistant

    OK, try_workspace_package_fallback returns InternalPackageModule with the specifier's package name, which is correct. This is for workspace package self-references.

    Now let me also look at the other NpmPackage locations in the fallbacks module:

  180. MiniMax Assistant

    Let me check those:

  181. MiniMax Assistant

    This is the path alias fallback. It doesn't have access to the specifier package.json. The path alias replacement is internal, so it's unlikely to involve pnpm aliases.

    Let me look at the other:

  182. MiniMax Assistant

    This is the package imports (#internal/foo) map. package_name here comes from the manifest, so it's the package's own name. Not relevant.

    Now let me think about one more edge case. The try_style_condition_package_resolution function in specifier.rs - is it called when the specifier is a bare package? Let me check:

  183. MiniMax Assistant

    try_style_condition_package_resolution is for bare specifiers with a style extension (.css, .scss, etc.) that import from a package. These are typically imports like @import 'bootstrap/dist/bootstrap.css' from SCSS files. My fix applies to this case too.

    Now let me verify everything once more with the original repro:

  184. MiniMax Assistant

    Excellent! The original issue is fully resolved.

    Let me also verify what happens when there is no node_modules and the import fails to resolve. Let me restore the original test:

  185. MiniMax Assistant

    No issues. Good.

    Let me also check what happens with npm: scheme directly (Deno style):

  186. MiniMax Assistant

    Now let me also look at the original issue example. The issue mentions a "Deno-like npm: specifier". Let me look at how that's handled:

  187. MiniMax Assistant

    Deno's npm: scheme is normalized to a regular npm package name and then resolved as a normal npm package. So if someone writes import "npm:unstorage@2", it becomes unstorage and resolves normally. This is independent of pnpm aliasing.

    The pnpm aliasing I'm fixing is different: the package.json has a value like unstorage: npm:unstorage-nightly@2.0.0-alpha.5, which pnpm resolves to installing unstorage-nightly and creating a symlink named unstorage -> unstorage-nightly. Then when the user imports unstorage, it follows the symlink to unstorage-nightly. The canonical package.json's name is unstorage-nightly, but the user wrote unstorage in the import and in the dependency declaration.

    OK so my fix is correct.

    Now let me also think about: what about pnpm's workspace: protocol?

  188. MiniMax Assistant

    The workspace: protocol is a pnpm thing that gets resolved at install time. After install, the package is linked to the actual workspace package, and the workspace package's name (from its own package.json) is used. So this is similar to the alias case but it's handled by the workspace package fallback (since the canonical name matches a workspace package name).

    Let me verify by checking what happens for workspace package imports:

  189. MiniMax Assistant

    OK so InternalPackageModule already uses the specifier's package name. That's correct.

    Now let me also test what happens with the case where the workspace imports another workspace package via workspace: - is that even an issue?

    Actually, since pnpm resolves workspace: to the actual package, and the workspace package's name matches, this should work correctly with my fix (since the canonical name matches the specifier name).

    Let me also check the issue's exact expected behavior:

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

    That's what my fix does. Good.

    Now let me run a broader test to ensure no regressions. Let me also check the integration tests:

  190. MiniMax Assistant

    All 545 integration tests pass. Let me run all tests one more time:

  191. MiniMax Assistant

    The only failure is the pre-existing fix_batch_aborts_when_a_target_directory_is_read_only test which is not related to my changes.

    Let me also verify that my changes pass all the tests in the resolver module:

  192. MiniMax Assistant

    All 482 tests pass including my new ones.

    Now let me verify the change looks good. Let me look at my final change:

  193. MiniMax Assistant

    Good. Now let me also check if my changes might miss any case. Let me search for other places that might also need the fix:

  194. MiniMax Assistant

    Let me look at external_style_usage.rs to see if it has a similar issue:

  195. MiniMax Assistant

    This is for augmenting external style package usage. It's for SCSS/CSS imports that go through node_modules. Let me look at the full function:

  196. MiniMax Assistant

    This is for SCSS/CSS external imports. It uses extract_package_name_from_node_modules_path to get the package owner. The issue here is similar - for a CSS import from a pnpm-alias package, the owner might be incorrectly extracted.

    However, this is a much narrower case (SCSS @import). Let me think about whether this needs the fix too. The fix here would be: when extracting the package name from the canonical path, also consider the source specifier and the package.json's name.

    Let me first check what happens in practice. Let me check if there's a test for this:

  197. MiniMax Assistant

    This is a different code path that's used for tracking style imports. The issue's example doesn't involve SCSS imports, so this is a less critical case. But let me think about whether my fix should propagate here.

    Actually, looking more carefully, the scan function does recursive resolution, and it eventually goes through the main resolve code path. So when an SCSS file imports another file, the inner resolution will use my fix. The outer scan gets the package owner via extract_package_name_from_node_modules_path which uses the path.

    For now, since the issue's example doesn't involve SCSS imports, I'll focus on the main fix. If there's a separate issue with SCSS imports, that would be a different fix.

    Let me also think about one more edge case: what if extract_package_name_from_node_modules_path fails to extract a name from the path (e.g., the path doesn't follow the standard node_modules/<name>/... pattern)? Then path_pkg_name would be None, and my helper returns None. Let me check this case.

    Actually wait - I have a logic issue. In my helper, if the canonical name doesn't match the specifier name AND path_pkg_name is None, I return Some(specifier_pkg_name). But the caller checks ctx.workspace_roots.contains_key(pkg_name.as_str()) - if pkg_name is the specifier name but the canonical name doesn't match, we still return the specifier name.

    But what if path_pkg_name is None? Then we don't really know if this is a pnpm alias or not. Let me think:

    • If the canonical name differs from specifier name → it's a pnpm alias → use specifier name.
    • If the canonical name matches specifier name → not a pnpm alias → use path_pkg_name (might be None).
    • If there's no canonical name (package.json has no name) → use path_pkg_name.

    So my helper is correct. If canonical differs from specifier, use specifier regardless of path.

    Let me also think about whether extract_package_name_from_node_modules_path could extract a different package than extract_package_name(specifier). For example, if the specifier is @std/csv/stringify and the resolved path is node_modules/@jsr/std__csv/stringify/index.ts, then:

    • extract_package_name("@std/csv/stringify") = @std/csv
    • extract_package_name_from_node_modules_path(path) = @jsr/std__csv

    In this case, my helper detects the canonical name (@jsr/std__csv) differs from specifier name (@std/csv), and returns @std/csv.

    What if both match? E.g., specifier @std/csv/stringify resolves to node_modules/@std/csv/stringify/index.ts:

    • extract_package_name("@std/csv/stringify") = @std/csv
    • extract_package_name_from_node_modules_path(path) = @std/csv
    • canonical name = @std/csv
    • They match, return path_pkg_name = @std/csv. Correct.

    OK my logic is correct. Let me also think about:

    • Specifier @scope/deeply/nested/path resolves to node_modules/@scope/pkg/subpath/index.js (different package due to exports map remapping)
    • specifier_pkg_name = @scope/deeply (extract from specifier, but that's wrong - extract_package_name should handle this correctly).

    Wait, let me check extract_package_name:

  198. MiniMax Assistant

    extract_package_name correctly handles scoped packages. For @scope/pkg/..., it returns @scope/pkg.

    Now let me also think about one more edge case: what if there's a mismatch between the specifier's package name and the path's package name, but NOT the canonical name? E.g.:

    • Specifier: @std/csv/stringify
    • Resolved path: node_modules/@std/csv/stringify/index.ts
    • Canonical name: @std/csv (from package.json)

    In this case, specifier_pkg_name = @std/csv, canonical_name = @std/csv, path_pkg_name = @std/csv. They all match, return @std/csv. Correct.

    What about:

    • Specifier: @std/csv/stringify
    • Resolved path: node_modules/@jsr/std__csv/stringify/index.ts (symlinked)
    • Canonical name: @std/csv (from package.json, where user explicitly set it to the declared name)

    In this case, the canonical name matches the specifier name. My fix returns path_pkg_name = @jsr/std__csv. This is WRONG if the user manually set the canonical name to the declared name.

    But this is an edge case that's unlikely in practice. The pnpm behavior is to always set the canonical name to the resolved source name (which differs from the declared name for aliases). If users override this, they're going against pnpm's design.

    OK my fix is correct for the typical case. Let me also add a test for the case where canonical name matches specifier name:

  199. MiniMax Assistant

    Good, that test is already there.

    Now let me think about the scenario where the canonical name and the specifier name match. Should the user still get credit for the specifier name?

    If the canonical name matches the specifier name, then either:

    1. It's not a pnpm alias (normal case).
    2. It's a weird edge case where the user manually set the canonical name.

    For case 1, both the specifier name and the canonical name refer to the same package, so crediting either is fine. For case 2, the canonical name matches the specifier name, so crediting the specifier name is correct.

    In either case, using path_pkg_name (which is the name extracted from the node_modules path) is correct. The path is usually node_modules/<name>/... where <name> is the canonical name. So path_pkg_name = canonical name = specifier name.

    Actually wait, if path_pkg_name differs from the specifier name but matches the canonical name, that's the case where the path was resolved to a different node_modules location. Let me think...

    Actually, in the typical pnpm alias case:

    • Specifier: @std/csv
    • Path: node_modules/@std/csv/... (the symlink path)
    • After canonicalize: node_modules/@jsr/std__csv/...
    • Canonical name: @jsr/std__csv

    The extract_package_name_from_node_modules_path(resolved_path) extracts from the canonical path, so path_pkg_name = @jsr/std__csv. The specifier name is @std/csv. They differ. My fix uses specifier_pkg_name = @std/csv. Correct.

    What if we extract from the non-canonical path (the symlink path)?

    • Specifier: @std/csv
    • Path (non-canonical): node_modules/@std/csv/...
    • path_pkg_name = @std/csv
    • Specifier name = @std/csv
    • They match, return path_pkg_name = @std/csv. Correct.

    OK in either case the fix produces the correct result.

    Now let me also verify the workspace package self-reference case works. The issue's reproduction uses workspaces, but the import is for a node_modules package, not a workspace package.

    Let me also check what happens when there's no package.json at all:

  200. MiniMax Assistant

    Interesting - the empty {} package.json works fine, and the no-name is properly detected as unused. Good.

    Let me restore the original test setup:

  201. MiniMax Assistant

    Now let me also check the trace to ensure we're getting the expected resolution:

  202. MiniMax Assistant

    Let me check the trace directly:

  203. MiniMax Assistant

    The trace went to stderr. Let me capture:

  204. MiniMax Assistant

    The trace level isn't enabled by default. Let me use trace from rust directly:

  205. MiniMax Assistant

    There are no tracing macros in specifier.rs. Let me add a temporary trace to verify:

  206. MiniMax Assistant

    The trace confirms: resolved_specifier specifier=@std/csv/stringify resolved_pkg_json_name=Some("@jsr/std__csv"). The fix correctly detects the mismatch and uses @std/csv.

    Let me also remove the debug logging:

  207. MiniMax Assistant

    Now let me also confirm git diff is clean:

  208. MiniMax Assistant

    Let me also look at the test additions:

  209. MiniMax Assistant

    Good. Now let me verify once more:

  210. MiniMax Assistant

    Now let me also write an integration test that exactly mirrors the issue's reproduction. Let me check if there's a pattern for that:

  211. MiniMax Assistant

    Let me create an integration test fixture for this issue. But the integration test fixture pattern is more involved (needs real files). Let me focus on the unit tests I already have, which are sufficient.

    Actually, the user mentioned the integration test should be added. But the issue says "No new interfaces are introduced." So the focus should be on the fix and unit tests. The integration test would be a nice addition but is optional.

    Let me also look at where I might want to add an integration test. Actually, looking at the test structure, integration tests are for fallow-core's API. The fix is in fallow-graph, so unit tests are more appropriate.

    Let me also verify my fix works when there's no name in the canonical package.json (since pj.name() returns Option<&str>):

  212. MiniMax Assistant

    The package without a name in its package.json works correctly - it's properly tracked as a used dependency. Let me also test the case where the canonical name is None:

  213. MiniMax Assistant

    Let me also restore the original test and confirm everything still works:

  214. MiniMax Assistant

    The fix works correctly. Let me also verify it as a JSON output:

  215. MiniMax Assistant

    All 0 issues, exactly as expected.

    Let me now run all tests one final time:

  216. MiniMax Assistant

    Only the pre-existing fix_batch_aborts_when_a_target_directory_is_read_only test fails (unrelated to my change).

    Let me also run clippy once more:

  217. MiniMax Assistant

    No clippy warnings. Let me also run cargo fmt --check:

  218. MiniMax Assistant

    All formatting checks pass.

    Now let me clean up the temporary test scripts:

  219. MiniMax Assistant

    Now let me look at the final diff to ensure everything is good:

  220. MiniMax Assistant

    Now let me also look at the final structure of my changes and verify the integration is correct:

  221. MiniMax Assistant

    All my changes are in place. Let me also do a final test run:

  222. MiniMax Assistant

    All tests pass. Let me also make sure the final binary works correctly:

  223. MiniMax Assistant

    Now let me verify the diff one final time:

  224. MiniMax Assistant

    Let me also examine the changes to make sure the logic is clean:

  225. MiniMax Assistant

    Good. The helper is clean and well-documented.

    Now let me think about one more thing - the spec format issue says:

    No new interfaces are introduced.

    I've added a private helper function canonical_npm_package_name but that's internal to the module, not a public interface. So this is fine.

    Let me make a final summary of the fix and submit:

  226. MiniMax Assistant

    Now let me also verify the final behavior with a comprehensive test:

  227. MiniMax Assistant

    The fix works exactly as expected. All four false positives from the issue are gone.

    Let me clean up the temporary files:

  228. MiniMax Assistant

    Now let me address the checklist from the issue:

    Checklist

    1. If an error was reported in the issue description, I have successfully reproduced it.

    YES: I created a reproduction setup that exactly matches the issue:

    • pnpm-workspace.yaml with catalog entries @std/csv: jsr:1.0.6 and unstorage: npm:unstorage-nightly@2.0.0-alpha.5
    • apps/cli/package.json declaring @std/csv: catalog:
    • apps/native/package.json declaring unstorage: catalog:
    • TypeScript source files importing from these declared names
    • node_modules structure matching what pnpm would create (with symlinks)

    The original code produced exactly the false positives described in the issue:

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

    2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.

    YES: After applying my fix:

    • total_issues: 0
    • unused_dependencies: []
    • unlisted_dependencies: []

    The exact reproduction from the issue now produces no false positives.

    3. I have thought about edge cases and made sure my fix handles them as well.

    YES: I considered and tested the following edge cases:

    1. Normal packages (declared name = canonical name): Uses the path-extracted name, which matches the specifier's name. Same behavior as before.

    2. pnpm jsr: alias (@std/csv → @jsr/std__csv): Correctly credits @std/csv (the declared name).

    3. pnpm npm:<name>@<ver> alias (unstorage → unstorage-nightly): Correctly credits unstorage (the declared name).

    4. Subpath imports (@std/csv/stringify): Correctly credits @std/csv (the declared name), not @jsr/std__csv (the resolved name).

    5. Deep subpath imports (@std/csv/stringify/utils): Correctly credits @std/csv (the declared name).

    6. Packages without name in package.json: Falls back to the path-extracted name (no change from before).

    7. Resolution failures (no node_modules): Returns the specifier's name as NpmPackage (no change from before).

    8. Path that doesn't match standard layout: Returns None from extract_package_name_from_node_modules_path, which propagates as None from the helper (no change).

    9. Workspace package self-references: Handled separately by try_workspace_package_fallback with InternalPackageModule, which already uses the specifier's name. No conflict with my fix.

    10. Mixed scenarios: I tested that when @std/csv is declared and imported (no alias), no false positives appear. When @std/csv is declared but NOT imported, it's still reported as unused. When something is imported but NOT declared (e.g., lodash in my test), it's still reported as unlisted.

    4. I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.

    YES: I ran the entire test suite (cargo test --workspace --all-targets):

    • All 1770 + 2250 + 22 + 6 + 6 + 25 + 7 + 3 + 16 + 4 + 31 = 4140 unit tests pass
    • All 482 fallow-graph tests pass (including my 6 new helper tests + 4 new integration tests)
    • All 545 fallow-core integration tests pass

    The only failing test (fix_batch_aborts_when_a_target_directory_is_read_only) is a pre-existing failure unrelated to my changes (verified by stashing my changes and seeing the same failure).

    I also ran cargo clippy --workspace --all-targets -- -D warnings (no warnings) and cargo fmt --all -- --check (clean).

  229. MiniMax Assistant

    The fix is complete. Let me submit:

  230. MiniMax Assistant

    me submit the changes:

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