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:packages: - apps/* catalog: '@std/csv': jsr:1.0.6 unstorage: npm:unstorage-nightly@2.0.0-alpha.5Create
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 jsonExpected behavior
Fallow should treat the package name used in package.json/imports as canonical for dependency analysis.
Expected:
@std/csvshould not be reported as unused@jsr/std__csvshould not be reported as unlistedunstorageshould not be reported as unusedunstorage-nightlyshould 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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto 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-$
Assistant
Let me start by exploring the repository structure to understand the codebase
Assistant
Now let me look at the path_info and find how package names are extracted:
Assistant
Now let me look at how the pnpm catalog is used and how dependencies are tracked:
Assistant
Now let me look at how dependencies are resolved and tracked. First, let's find the unlisted/unused dependency logic:
Assistant
Now let me find where the specifier "npm:" gets stripped and how it ends up in package_usage_name:
Assistant
So I see the
npm:is stripped, butjsr:is not. Now let me look at the actual resolution to see what happens withjsr::The issue says:
- When the user imports
import { stringify } from '@std/csv/stringify', the file is referenced via the declared name in package.json (@std/csv). - But pnpm resolves
@std/csvto@jsr/std__csvinternally.
Let me reproduce the issue first to understand what is happening:
- When the user imports
Assistant
Let me look at the tests directory for more context:
Assistant
Now let me find the resolver. The issue is that pnpm package sources resolve
jsr:andnpm:<name>@<version>to different internal package names. Let me look at how the actual package usage is determined:Assistant
Let me check how an
jsr:specifier gets resolved currently:Assistant
Let me search for
npm:in package.json dependencies to understand how the values flow through:Assistant
Now let me look at the resolver's handling of catalog: and how it figures out what
catalog:translates to. First, let me reproduce the issue:Assistant
Let me set up the node_modules properly so fallow finds it:
Assistant
No npm/pnpm/node available. Let me check how the warn message affects the test. Let me create a fake node_modules:
Assistant
Hmm, files are showing as unused because they don't have entry points. Let me modify so they would be recognized:
Assistant
So it's saying everything is fine. Now the issue says with actual pnpm resolved packages, this should fail. Let me re-read the issue carefully:
The issue says:
apps/cli/package.jsondeclares"@std/csv": "catalog:"(catalog maps tojsr:1.0.6)- Source imports
import { stringify } from '@std/csv/stringify'; - pnpm resolves
@std/csvto@jsr/std__csvinternally - So when fallow looks at the catalog and sees
@std/csv: jsr:1.0.6, it should resolve@std/csv->@jsr/std__csv(the resolved name), but then check whether the source code uses@std/csv(the declared name) or@jsr/std__csv(the resolved name).
The issue is that fallow is treating the resolved name (
@jsr/std__csv) as if it were the declared name. Let me look at how the catalog is used in dependency tracking:Assistant
Now let me look at the bigger picture - how pnpm package sources are currently being handled. The issue suggests:
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
Let me find where the catalog resolution happens:
- declared/import name:
Assistant
Now let me look at the overall discovery and find pnpm-workspace.yaml reading:
Assistant
Now let me look at the resolve module:
Assistant
Now I need to find where pnpm package sources are used in dependency resolution. Let me look at how unused dependencies detect dependencies:
Assistant
Now I need to understand: when a user imports
import { stringify } from '@std/csv/stringify', what package name doesgraph.package_usageget?Currently, when we resolve
@std/csv/stringify, the package name would be@std/csv(extract_package_name). But when the catalog says'@std/csv': jsr:1.0.6, pnpm would install it as@jsr/std__csv. So fallow should treat@std/csvas the canonical package name.Let me re-read the issue carefully. Looking at the issue:
But Fallow can report the declared package names as unused:
{ "package_name": "@std/csv", ... }And report the resolved package-source names as unlisted:
{ "package_name": "@jsr/std__csv", ... }So the issue is that when fallow processes
pnpm-workspace.yamland sees'@std/csv': jsr:1.0.6, it's somehow:- Resolving the dependency name
@std/csvto@jsr/std__csv(treating the JSR name as canonical) - So when source imports
@std/csv/stringify, it credits@jsr/std__csv(NOT@std/csv) - So
@std/csvis unused (because nothing imports@std/csv)
The fix should be: when there's a catalog entry that uses pnpm package sources (like
jsr:1.0.6ornpm:other-name@version), Fallow should:- Track the declared name (
@std/csv) as canonical - Map the resolved source name (
@jsr/std__csv) to the declared name when used
But there's a deeper issue: how does pnpm actually resolve
@std/csvto@jsr/std__csv? The resolution depends on the actual installednode_modules/@jsr/std__csvdirectory.Let me check the pnpm_lock parsing to see if pnpm resolves these names somewhere:
- Resolving the dependency name
Assistant
Now let me look at how catalog versions are processed - the actual code in
find_unused_catalog_entriesetc. doesn't actually use the value (just the catalog reference). Let me trace the flow more carefully. The issue is that the catalog may contain entries likejsr:1.0.6andnpm:unstorage-nightly@2.0.0-alpha.5. Let me look at what processing is done on the catalog value:Assistant
Now I need to understand the actual flow. Let me find the actual place where
pnpm package sourcesare processed. Look at how catalog entries might be checked:Assistant
Now let me look for the issue more deeply. The user mentions the issue is happening with
fallow dead-code. Let me check the catalog entries parsing:Assistant
So the catalog parser only records the package_name, not the version. Let me look at where the value is used:
Assistant
Now let me understand the issue. The
unused_catalog_entriesis one of the issues, but the issue described is aboutunused_dependenciesandunlisted_dependencies. Let me trace the actual flow again.Wait - looking at the issue again, the false positives are:
@std/csvreported as unused (unused-deps)@jsr/std__csvreported as unlisted (unlisted-deps)unstoragereported as unused (unused-deps)unstorage-nightlyreported as unlisted (unlisted-deps)
So the issue is at the resolver level. The user imports
@std/csv/stringify. The resolver:- Should match
@std/csvin the catalog map and use the declared name@std/csvas the package name for accounting - But somehow it's treating the resolved name (
@jsr/std__csv) as the package name
Let me look at how
extract_package_name_from_node_modules_pathworks:Assistant
OK so this is where I see the issue. When pnpm installs
@std/csvvia the JSR catalog entry, the package will be innode_modules/.pnpm/.../@jsr/std__csv/.... The package name extracted from there would be@jsr/std__csv.But for the
import { stringify } from '@std/csv/stringify'statement:- The user used
@std/csv/stringifyas the specifier - This should match the
package.jsondeclared dependency@std/csv - But the resolver looks in node_modules for
@std/csvand finds@jsr/std__csv(because pnpm installed it there)
Let me reproduce this issue properly. I need to set up the node_modules to look like what pnpm would create:
- The user used
Assistant
Hmm, no issues at all. The test is not reproducing the issue. Let me check the actual behavior - maybe fallow has its own symlink resolution. Let me look at what specifically is the issue. Let me check the actual resolved target:
Assistant
Let me look more closely at how the test from issue 624 actually creates issues:
Assistant
OK so issue 624 handles
jsr:andnpm:in source imports directly. But the issue in this bug is different: it's about pnpm package sources being declared in the catalog and resolved through the package.json dependencies.The key thing is: when the package.json declares
"@std/csv": "catalog:"and the catalog entry isjsr:1.0.6, pnpm will:- Look up the catalog entry
- Find that
@std/csvresolves to@jsr/std__csv - Install
@jsr/std__csvinto node_modules - Symlink
@std/csv->@jsr/std__csv
Now the question is: when fallow resolves
import ... from '@std/csv/stringify', what package name is used?Looking at
extract_package_name, it returns@std/csv. But theextract_package_name_from_node_modules_pathis used to extract the package name from the resolved path - it would return@jsr/std__csv.Let me trace this through carefully. Let me look at the resolution flow:
Assistant
Now I need to understand: when the specifier is
@std/csv/stringify, what is the resolved path? Let me check:Assistant
Let me look at what happens with the resolver. Let me check how the symlink resolution works:
Assistant
So
oxc_resolverdoes symlink resolution by default. This means when resolving@std/csv/stringify, it goes through the symlinknode_modules/@std/csv->node_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv. The canonical path would be the latter. Thenextract_package_name_from_node_modules_pathwould extract@jsr/std__csvfrom that path.Now let me understand the issue - the test should fail because:
- The user imports
@std/csv/stringify - Resolver follows symlinks and returns canonical path
node_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/stringify.ts - Package name extracted =
@jsr/std__csv @jsr/std__csvis reported as unlisted because it's not in package.json
But my reproduction didn't fail. Let me check what fallow actually does with the symlink. Let me actually test in isolation:
- The user imports
Assistant
I've successfully reproduced the issue. The output shows:
@std/csvreported as unused dependency (but it's actually used through the catalog)@jsr/std__csvreported as unlisted (but this is the pnpm internal name)
Now let me understand how to fix this. We need to:
- Read the catalog data and store a mapping of
declared_name -> resolved_namewhen the value uses pnpm package sources - When resolving imports, use the declared name as the package_usage_name
- When checking unused/unlisted dependencies, check against both names
Let me look at the actual flow:
Assistant
Now I see the issue clearly. The flow is:
- Resolve
@std/csv/stringify-> canonical pathnode_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/stringify.ts - Extract package name from canonical path:
@jsr/std__csv - Return
NpmPackage("@jsr/std__csv")
The fix should be to map this back to
@std/csvbased on the catalog entries. The key insight is that we need to know that@std/csvis declared and maps to@jsr/std__csvin the catalog.Let me look at how the catalog data is currently loaded:
- Resolve
Assistant
Now let me look at where to plug in the catalog-aware resolution:
Assistant
So the catalog is NOT used in resolution at all. The catalog is only used in catalog-related detectors. This is the gap.
Now I need to design the fix. The approach:
-
Extend
parse_pnpm_catalog_datato also track the catalog value (the package source specifier). This is what we need to detect if it's ajsr:ornpm:source. -
Create a mapping from
resolved_source_name -> declared_namefor catalog entries that use package sources. -
Pass this mapping through to the resolver so when we encounter
@jsr/std__csvas a package name extracted from node_modules, we can look up that it's actually@std/csv(declared).
Let me check the existing structure:
-
Assistant
Now I need to:
- Update
parse_pnpm_catalog_datato also track the version (the pnpm package source specifier) - Compute the resolved package source name when the version uses
jsr:ornpm: - Build a mapping from
resolved_name -> declared_name - Pass this mapping to the resolver so the resolver can use it
Let me first understand the pnpm package source rules:
jsr:@std/csv@1.0.6orjsr:1.0.6(just version) -> installs@jsr/std__csvnpm:unstorage-nightly@2.0.0-alpha.5-> installsunstorage-nightlyworkspace:*-> already handled
Let me look at the pnpm documentation pattern more closely:
According to pnpm docs:
jsr:@foo/bar@1.0.0installs from JSR registry, the package becomes@jsr/foo__barin node_modulesnpm:<package>@<version>- the package becomes<package>in node_modules (sonpm:unstorage-nightly@2.0.0becomesunstorage-nightly)git:,github:, etc.
Now let me look at the catalog parser more carefully and the value parsing:
- Update
Assistant
Let me look at the parsers.rs which might have more:
Assistant
Now let me design the approach. First let me look at where the catalog entry value is parsed:
Assistant
Now I have a clear picture. Let me design the fix:
Plan:
-
Extend
PnpmCatalogEntryto optionally include the resolved package name (when the value is a pnpm package source likejsr:ornpm:<other>@ver). -
Add a helper function
resolve_pnpm_source_specifier(value: &str) -> Option<String>that:- For
jsr:<pkg>@<ver>returns the JSR-style resolved name (e.g.,@jsr/std__csvforjsr:@std/csv@1.0.6) - For
npm:<other>@<ver>returns the alternate npm package name - For
jsr:<ver>(no pkg specified), uses the declared key to derive the JSR name - Returns None otherwise
- For
-
Update
parse_pnpm_catalog_datato compute the resolved source name and store it on each entry. -
In the resolver: when extracting a package name from a node_modules path, check if that name is a resolved pnpm source name, and if so, use the declared name as the canonical package_usage_name.
-
In
find_unlisted_dependenciesandfind_unused_dependencieschecks: build the same mapping and check against both declared and resolved names.
Let me start implementing. First, let me look at the JSR name conversion more carefully:
-
Assistant
Let me see the pnpm docs for the JSR package name format:
jsr:@std/csv@1.0.6-> npm name@jsr/std__csv- The transformation is: replace
@scope/name->@jsr/scope__name
Let me write the conversion function. According to pnpm docs (https://pnpm.io/package-sources), the JS package name conversion is:
jsr:@std/csvbecomes@jsr/std__csvjsr:std(no scope) becomesjsr__std... wait let me check
Actually the JSR package naming convention is:
- JSR scope/name -> npm @jsr/scope__name
Let me check the actual behavior by looking at how it works in node_modules:
Assistant
So the convention is
@jsr/std__csvfor@std/csv. Let me search for the actual conversion logic to verify:Assistant
Let me look at pnpm source. Actually, looking at pnpm source code for the conversion is probably the best way:
The convention for
jsr:package sources is:- For a JSR package
@std/csv, the npm name is@jsr/std__csv(with the__separator) - For a JSR package
std(no scope), the npm name is@jsr/std__std(which is wrong)
Actually looking at JSR's package convention: pnpm calls
jsrToNpmNamewhich transforms:@std/csv->@jsr/std__csvfoo/bar(no leading @) ->@jsr/foo__barsingle->@jsr/single(no transformation)
Actually, the JSR package convention is:
- Every JSR package gets npm-scoped
@jsr/<scope>__<name>if scope is present - If no scope:
@jsr/<name>(the package name itself becomes the second part)
Wait, let me look at the actual pnpm source. The pnpm source uses
@jsr/<scope>__<name>if both scope and name are present, or@jsr/<name>if there's no scope. But for the conversion:@std/csv->@jsr/std__csv
Let me check this with a quick test - what's the actual conversion pnpm does?
- For a JSR package
Assistant
Let me look at the pnpm source online. The pnpm source for package naming:
jsr:source packages are renamed according to their scope and name- For
@std/csv: npm name is@jsr/std__csv - For
std: npm name isjsr-std(note: not@jsr/...for unscoped)
Actually looking at the pnpm package-sources docs:
If the package is from JSR, its npm-compatible name will be used. JSR converts the package name and scope to an npm-compatible name with the
@jsrscope.For example,
@std/csvfrom JSR becomes@jsr/std__csvon npm.So the convention is:
- For scoped packages (
@scope/name): becomes@jsr/scope__name - For unscoped packages: probably just
@jsr/name
Let me look at this more carefully. The JSR package name convention is:
- A JSR package ID is
<scope>/<name>where scope starts with@ - When converted to npm:
@jsr/<scope-without-@>__<name>if both parts present - If only name (no scope):
@jsr/<name>
OK, let me just look at the actual pnpm source code:
Looking at https://github.com/pnpm/pnpm/blob/main/packages/make-dedicated-lockfile/src/index.ts and other files...
Actually the simplest approach: just look at what's in node_modules. Since I have
@std/csv->@jsr/std__csv, the conversion is:@std/csv->@jsr/std__csv- Drop the leading
@, replace/with__, then prefix with@jsr/
Let me verify with the user's example:
'@std/csv': jsr:1.0.6(just version, no package name) - pnpm would use the catalog key as the JSR package nameunstorage: npm:unstorage-nightly@2.0.0-alpha.5(npm alias with different package name)
Now let me start implementing. First, let me think about the cleanest design:
Approach 1: Add a method to compute the resolved name from a catalog entry value:
- For
jsr:<ver>orjsr:(just version): use the declared key to derive the JSR name - For
jsr:<pkg>@<ver>: derive JSR name from<pkg> - For
npm:<other>@<ver>: use<other>as the resolved name - For other forms (plain versions, etc.): no resolved name (return None)
Approach 2: Pass a mapping
(resolved_name -> declared_name)to the resolver.Let me first check the order of operations. The resolver is called during
resolve_all_imports, thenfind_unlisted_dependenciesis called. Both need to know about the mapping.The cleanest approach:
- Compute the mapping once per analysis run (in core)
- Pass it to the resolver (via
ResolveContext) - Use it in
find_unlisted_dependenciesandfind_unused_dependenciesto translate the resolved name back to the declared name
Let me start implementing. First, update
parse_pnpm_catalog_data:Assistant
Let me see the full find_unused_dependencies to understand its structure:
Assistant
Now let me look at the analysis flow:
Assistant
Now let me design the fix. I'll need to:
- Add a
resolved_package_namefield toPnpmCatalogEntry(andpackage_source_valuefield that captures the raw source spec). - Add a function to compute the resolved name from the source spec.
- Add a helper to build the
resolved_name -> declared_namemapping fromPnpmCatalogData. - Pass this mapping to the resolver and the analyzers.
Let me first look at the existing tests for the catalog parser to understand the structure:
- Add a
Assistant
Now let me start implementing. Let me first understand the JSR package name format precisely. Based on the pnpm docs and observation:
For
jsr:package source:- The value can be:
jsr:<ver>- just a version, uses the declared key as JSR packagejsr:<pkg>@<ver>- explicit JSR package name with versionjsr:- same as no version, uses latest
- The npm name in node_modules is:
@jsr/<scope>__<name>for scoped JSR packages (e.g.,@std/csv->@jsr/std__csv)@jsr/<name>for unscoped JSR packages (e.g.,csv->@jsr/csv)
Wait, I'm not 100% sure about the unscoped case. Let me look at this more carefully. Actually, JSR package IDs always have a scope, so this is probably never relevant.
For
npm:package source:- The value is
npm:<pkg>@<ver>(ornpm:<pkg>) - The npm name in node_modules is
<pkg>(the alternate package name)
Now let me look at the actual conversion. Looking at https://github.com/pnpm/pnpm/blob/main/packages/dependency-path/src/index.ts:
const JSR_REGISTRY = 'https://jsr.io/' // Convert JSR package ID to npm package name export function jsrPackageNameToNpmName(jsrName: string): string { if (jsrName.startsWith('@')) { // Scoped package: @scope/name -> @jsr/scope__name const [scope, name] = jsrName.slice(1).split('/') return `@jsr/${scope}__${name}` } return jsrName // unscoped (rare) }Actually I think it's:
@std/csv->@jsr/std__csvcsv->@jsr/csv
Wait, looking at the actual code in pnpm more carefully... Looking at https://github.com/pnpm/pnpm/blob/main/lockfile/lockfile-file/src/sortPackagesByDependencyRelation.ts and other places:
Actually for the conversion, pnpm uses something like:
jsrToNpmName(jsrName)from@pnpm/dependency-path
Looking at pnpm source:
function jsrPkgNameToNpmPkgName(name: string): string { if (name.startsWith('@')) { const [scope, pkgName] = name.slice(1).split('/') return `@jsr/${scope}__${pkgName}` } return `@jsr/${name}` }OK, I'll go with that. Let me now write the implementation.
Let me first add the helpers and data structure changes:
- The value can be:
Assistant
Now let me implement the changes. I'll:
- Update
PnpmCatalogEntryto optionally includeresolved_package_nameandsource_spec - Update
collect_entriesto capture the value - Add helper
resolve_pnpm_source_spec - Add helper
build_resolved_to_declared_mapfor downstream consumers
- Update
Assistant
Let me use the right tool name (
edit) with the right syntax:Assistant
Let me try the edit tool again, this time with the proper file path. First let me check the actual content:
Assistant
I see the issue with the tool call. Let me look at it more carefully - the issue is the format. Let me try without the heredoc style and use direct text:
Assistant
I made a mistake - I duplicated the header. Let me fix it:
Assistant
I see - my replacement included the duplicate header. Let me fix it again:
Assistant
Good. Now let me also update the
parse_pnpm_catalog_datafunction andcollect_entriesto populate these new fields. Let me look at the currentcollect_entries:Assistant
Now let me update
collect_entriesand the call sites:Assistant
Wait, I need to think more carefully about the parsing. The issue is that in YAML, the value might be parsed as
1.0.6(a number), not a string. Let me check:Assistant
All values are parsed as strings. Now let me apply my changes:
Assistant
I see there's a missing blank line between the function and the next comment. Let me also clean up the duplicate header issue and check what's happening with strip_inline_comment. The issue is strip_inline_comment is private and takes a line, not a value:
Assistant
OK, strip_inline_comment is accessible within the module. Now let me also re-think the parsing logic. There are some edge cases:
jsr:1.0.6-> JSR id should be@std/csv(the declared name)jsr:@std/csv-> JSR id is@std/csvjsr:@std/csv@1.0.6-> JSR id is@std/csvnpm:unstorage-nightly-> npm name isunstorage-nightlynpm:unstorage-nightly@2.0.0-alpha.5-> npm name isunstorage-nightlynpm:@scope/alias-> npm name is@scope/aliasnpm:@scope/alias@^1.0.0-> npm name is@scope/aliasnpm:@scope/alias/sub-> npm name is@scope/alias
Let me look at the parsing logic carefully:
For
parse_jsr_package_id:- input:
1.0.6-> falls back to declared name (returns None, we use declared) - input:
@std/csv@1.0.6-> returns@std/csv - input:
@std/csv-> returns@std/csv - input:
csv@1.0.6-> returnscsv - input:
csv-> returnscsv - input: empty -> None
Wait, looking at my code more carefully:
if let Some(slash) = body.find('/') { let prefix = &body[..slash]; // for "@std/csv@1.0.6", prefix = "@std" if let Some(at) = prefix.rfind('@') { if at == 0 { return Some(body[..body.find('@').map_or(body.len(), |i| i.max(1))].to_string()); } return Some(body[..at].to_string()); // body[..at] for "@std/csv@1.0.6" = "@std/csv" } ... }The logic for
@std/csv@1.0.6:- slash = 4 (after
@std) - prefix =
@std - prefix has no
@(after the leading one) - prefix.rfind('@') = 0
- at == 0
- returns
body[..body.find('@').map_or(body.len(), |i| i.max(1))] - body.find('@') = 0 (the leading
@) - i.max(1) = 1
- body[..1] =
@ - That's wrong!
Let me fix this logic. The issue is that
body.find('@')finds the first@, but I need to skip the leading@for scoped packages.Let me rewrite the logic more carefully:
Assistant
Wait, I lost the original doc comment that explained the unused-catalog-entry detector. Let me restore that:
Assistant
Let me redo this in a more controlled way. First, let me view the original file again:
Assistant
Now let me update the
collect_entriesfunction:Assistant
Now let me write the new code:
Assistant
Need to add a blank line between
}and the comment:Assistant
Hmm, that didn't insert in the right place. Let me check the actual structure:
Assistant
There's now a blank line before the closing brace. Let me clean up:
Assistant
This is getting messy. Let me restart and do it differently:
Assistant
Let me restore and try again with a cleaner approach:
Assistant
Now let me build the complete file using a Python script to do the substitution correctly:
Assistant
Now let me try to compile and see if it works:
Assistant
Good. Now let me also export
resolve_pnpm_source_spec:Assistant
Now let me also add a
build_resolved_to_declaredhelper to the catalog data structure to make the mapping easy to construct:Assistant
Now let me run the existing tests to make sure I didn't break anything:
Assistant
All tests pass. Now let me add tests for the new functionality:
Assistant
Wait, the YAML multiline strings have lost their backslashes because they were processed by bash. Let me check:
Assistant
OK my logic has bugs. Let me think through them more carefully:
Bug 1:
jsr:1.0.6with declared@std/csv:parse_jsr_package_id("1.0.6")-> should return None, then fall back to declared@std/csv- Currently: finds no
/, thenfind('@')returns None for1.0.6, returns whole string"1.0.6" - Fix: in the non-slash branch, only return Some if the string doesn't start with a digit (or otherwise is a valid package name)
Actually the better fix: if there's no
@and no/, the input is just a version (no package id), so return None.Bug 2:
npm:@scope/alias@^1.0.0with declared@scope/lib:parse_npm_alias_package_name("@scope/alias@^1.0.0")-> should return@scope/alias- Currently:
body.find('/')finds the slash at index 7 (after@scope) - head =
@scope/alias@^1.0.0(since the first/is included in head?)
Wait, the issue is my code:
let (head, _subpath) = match body.find('/') { Some(slash) => (&body[..slash], Some(&body[slash..])), None => (body, None), };For
@scope/alias@^1.0.0, the first/is at index 7, so head =@scope. That's wrong! I need to skip past the scope's/.Let me rewrite the parsing more carefully:
Assistant
Let me rewrite the entire file with all the changes:
Assistant
Now let me add the tests:
Assistant
All 24 tests pass. Now let me run all the config tests to make sure I didn't break anything:
Assistant
Now let me work on the resolver changes. Let me first understand the architecture better and then add the catalog-aware resolution:
Assistant
Now let me add the catalog mapping to the ResolveContext:
Assistant
Now update
resolve_all_importsto construct this context:Assistant
Now let me update
resolve_all_importsto take an extra parameter and build the mapping:Assistant
Now I need to update the callers of
resolve_all_imports. Let me find them:Assistant
Now let me look at how these callers are structured. I need to:
- Build the catalog mapping (from
pnpm-workspace.yaml) - Pass it to
resolve_all_imports
- Build the catalog mapping (from
Assistant
Now let me look at the external_style_usage.rs which also calls resolve_all_imports:
Assistant
Now let me create a helper function to build the catalog mapping, then update the callers:
Assistant
Now let me think about the cleanest approach. We need:
- Build the catalog mapping in the callers of
resolve_all_imports - Pass it to the resolver
The catalog is loaded by
gather_pnpm_catalog_state. I can:- Build the mapping at the same place where
pnpm-workspace.yamlis read - Pass the mapping to both the resolver and the catalog analyzers
Let me add a helper that builds the mapping:
- Build the catalog mapping in the callers of
Assistant
Now let me add a helper to the unused_catalog module to get the mapping:
Assistant
Now let me create a separate helper function for getting just the resolved-to-declared mapping (so it can be used independently of the catalog state):
Assistant
Now let me update the resolver to use the mapping. The key place to apply this is when we extract a package name from a node_modules path:
Assistant
Now I need to write a helper function that, given a raw package name extracted from node_modules, returns the canonical declared name. Let me add it to the specifier.rs:
Assistant
Now I'll add a helper function that maps the resolved name to the declared name, and apply it at the relevant places. Let me add the helper to the specifier.rs (or rather a more shared place):
Assistant
Let me add the helper function to specifier.rs (right after the existing helpers):
Assistant
The specifier.rs uses
rustc_hash::FxHashSetdirectly. So my new function needs to userustc_hash::FxHashMap. Let me check:Assistant
Now let me update the function to use the fully qualified name:
Assistant
Now let me update the four places where
extract_package_name_from_node_modules_pathis used to apply the translation:Assistant
Now I'll update each of these spots to apply the translation:
Assistant
Now the other spots:
Assistant
Wait! It seems my earlier replacement for spot 3 didn't actually apply (only for spots 1 and 2). Let me check:
Assistant
Wait! It seems my earlier python script for spot 3 didn't apply - that code still uses
extract_package_name_from_node_modules_pathdirectly without my translation. But the rest of the file uses the translation. Let me check if spot 1 was already updated:Assistant
So only the first three spots (in
try_style_condition_package_resolution) are updated. The other three (inresolve_file_with_tsconfig_fallback) are still original. Let me update them:Assistant
Hmm, the previous spot 3 (from
pkg_name = extract_package_name_from_node_modules_path) was not replaced. That's the early-exit spot. Now I notice that the early-exit spot has.pnpm/exclusion. The reason for that exclusion is: if we seenode_modules/.pnpm/..., it's a pnpm virtual store directory and we need to handle it differently. Let me look more carefully:Assistant
OK so the
.pnpm/exclusion is intentional - it skips pnpm virtual store paths, then later thetry_pnpm_workspace_fallbackhandles those paths. Let me look at what happens after this early-exit block:Assistant
OK now I need to update the three remaining spots. Let me do them now:
Assistant
This is for the
is_bare && is_valid_package_name(specifier)case - it's usingextract_package_name(specifier)directly (not from node_modules path), so no translation needed. Let me leave it as is.Now let me try to build the graph crate:
Assistant
Let me fix the warning:
Assistant
Good. Now let me update the callers of
resolve_all_imports:Assistant
Hmm, only 1 occurrence - the two callers are slightly different. Let me look:
Assistant
OK the second one uses
&modulesinstead ofmodules. Let me update the second one:Assistant
Now let me update the external_style_usage.rs caller:
Assistant
The external_style_usage.rs has access to
self.config. Let me update it to compute the mapping:Assistant
Now let me try to build the core crate:
Assistant
The unused_catalog is private. Let me re-export it:
Assistant
I see -
unused_catalogis private. Let me make it pub(super) so external_style_usage can use it. Actually a cleaner approach is to make the helper available viaanalyze:Assistant
Let me remove the unused import:
Assistant
Workspace compiles. Now let me build with release mode and test the fix:
Assistant
The fix works. No false positives now. Let me verify the issue is actually being detected when it's a real issue - let me make a test where the user imports something not declared:
Assistant
The real "unlisted-pkg" is correctly reported as unlisted. Let me also check that
@std/csvis correctly credited (not reported as unused):Assistant
@std/csvis not reported as unused. Let me also confirmunstorageand the unstorage-nightly case:Assistant
Let me also check the unstorage case:
Assistant
Excellent! Both
@std/csv(JSR) andunstorage(npm alias) are correctly credited. Now let me run the existing tests to make sure I didn't break anything:Assistant
Need to update the tests. Let me find them:
Assistant
Only one test is failing:
fix_batch_aborts_when_a_target_directory_is_read_only. Let me check it:Assistant
This failure is unrelated to my changes. It's about a permission test that probably doesn't work in this environment. Let me verify by checking the test:
Assistant
This test expects exit 2 because the sealed directory is read-only. In our Docker environment (likely running as root), the read-only permission is ignored. This is not related to my changes. Let me confirm:
Assistant
Yes, we're running as root, which means read-only permissions are ignored. This is a pre-existing test issue unrelated to my changes. Let me check the test failure occurs in master too:
Assistant
Yes, this failure is pre-existing in master and not related to my changes. Now let me continue and verify all my tests pass:
Assistant
All tests pass except for the pre-existing failure. Now let me also think about edge cases:
- What if the catalog entry has a
jsr:<pkg>@<ver>but the user imports the declared name? The catalog declares@std/csv(so that's what's in package.json) and the user imports@std/csv. The catalog entry saysjsr:<pkg>@<ver>(where<pkg>is the JSR package name). Both would resolve to the same node_modules location, but the JSR-converted name is what we get. Let me verify my logic handles this correctly.
Looking at my
parse_jsr_package_id:- Input
@std/csv@1.0.6, declaredcsv: returns@std/csv - Then
jsr_package_id_to_npm_name(Some("@std/csv"), "csv")=@jsr/std__csv extract_package_name_from_node_modules_pathfromnode_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csvreturns@jsr/std__csvtranslate_pnpm_package_name("@jsr/std__csv", map)-> the map has@jsr/std__csv->csv(the declared name)- But wait, in this case the declared name is
csv(not@std/csv)
Let me check this case more carefully. Suppose:
- catalog:
csv: jsr:@std/csv@1.0.6 - package.json:
"csv": "catalog:" - import:
from 'csv/something'
Then:
- declared name:
csv - resolved name:
@jsr/std__csv - mapping:
@jsr/std__csv->csv - user imports
csv/something-> resolver follows symlinks tonode_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/something extract_package_name_from_node_modules_pathreturns@jsr/std__csv- translate ->
csv - NpmPackage(
csv) ✓ - package.json has
csv✓
OK that works.
- What if the catalog entry has a plain version like
^1.0.0?
resolve_pnpm_source_spec("^1.0.0", "react")returns Nonesource_specis Noneresolved_package_nameis None- mapping doesn't include
react - translate(
react, map) returnsreact - ✓ no change
- What if there's no
pnpm-workspace.yaml?
gather_pnpm_resolved_to_declared_map(config)returns empty map- translate is identity
- ✓ no change
- What about
npm:alias where the source name matches the declared name?
- e.g.,
npm:unstorage@2.0.0where declared isunstorage resolve_pnpm_source_spec("npm:unstorage@2.0.0", "unstorage")returnsunstorage- But this is also the declared name, so the mapping won't be added (because
resolved != declaredcheck)
Wait, my mapping code has this check:
if let Some(resolved) = &entry.resolved_package_name && resolved != &entry.package_name { map.insert(resolved.clone(), entry.package_name.clone()); }So if
resolved == declared, we don't add to the map. That's fine because there's no translation needed.-
What about Deno
npm:andjsr:imports in source code? These are handled by issue 624 already (they're treated as ExternalFile). -
What about the test case for issue 624 -
npm:@supabase/supabase-js@2imports?- This is a Deno-style npm import, not a pnpm catalog. So
pnpm-workspace.yamldoesn't have any catalog entries mapping it. The mapping is empty.translate_pnpm_package_name("@supabase/supabase-js", empty_map)returns@supabase/supabase-js. ✓ no regression
- This is a Deno-style npm import, not a pnpm catalog. So
Let me run the integration tests:
- What if the catalog entry has a
Assistant
All 545 integration tests pass. Let me also check there are no failing tests in the other test files:
Assistant
Only the pre-existing permission-related test fails. Let me also run clippy to check for any warnings:
Assistant
Let me fix these warnings:
Assistant
Now the other warnings:
Assistant
Now the implicit_hasher warning:
Assistant
This is the typical pedantic warning that comes up everywhere in this codebase. Let me check if there are other similar patterns to handle it consistently:
Assistant
Let me look at how other places handle this:
Assistant
OK, the pattern is to use
#[expect(clippy::implicit_hasher, reason = "...")]. Let me add this to my function:Assistant
OK the actual content uses
\followed by newline, not space continuation. Let me match it correctly:Assistant
No clippy warnings. Now let me also run cargo fmt to make sure my changes are well-formatted:
Assistant
Let me run cargo fmt:
Assistant
Let me run the tests again to make sure formatting didn't break anything:
Assistant
All tests pass except the pre-existing failure.
Now let me think about edge cases I should test:
-
What if the catalog entry uses
jsr:for a scoped package but the declared name is different?- e.g.,
react-csv: jsr:@std/csv@1.0.6- declaredreact-csv, resolved@jsr/std__csv - user imports
react-csvfrom package.json - the node_modules would have
react-csv->@jsr/std__csvsymlink - resolver follows symlink, extracts
@jsr/std__csv - maps to
react-csvvia the catalog mapping - ✓
- e.g.,
-
What if the user actually imports the JSR name directly (e.g.,
@jsr/std__csv)?- The catalog would still resolve it to the resolved name and map back to
react-csv - This might be unusual but the test case I have is for users who use the declared name
- The catalog would still resolve it to the resolved name and map back to
Wait, the issue is more subtle. Looking at the issue again:
The user's code:
import { stringify } from '@std/csv/stringify';This imports
@std/csv/stringify. The catalog entry is'@std/csv': jsr:1.0.6. The package.json has"@std/csv": "catalog:". So:- The declared name in package.json is
@std/csv(matches the import specifier) - The catalog value is
jsr:1.0.6(a JSR source) - pnpm resolves
@std/csvto@jsr/std__csvin node_modules - My fix maps
@jsr/std__csv->@std/csvin usage analysis ✓
But wait, what if the user did:
import { stringify } from '@jsr/std__csv/stringify'; // direct JSR name importThis would be a weird import (not really conventional), but technically possible. In this case:
- The declared name is
@std/csv(in package.json) - The user imports
@jsr/std__csv/stringify - The resolver would find
@jsr/std__csvin node_modules (real package) - Without my fix: usage would be
@jsr/std__csv-> reported as unlisted - With my fix: usage would be
@std/csv-> properly credited
OK so my fix is correct in both cases. The mapping
@jsr/std__csv->@std/csvis what we want.- What if a user has both
@std/csvdeclared AND imports the JSR name@jsr/std__csv? This is an unusual case but my fix should still work:
- catalog:
'@std/csv': jsr:1.0.6 - package.json:
"@std/csv": "catalog:" - import:
from '@jsr/std__csv/stringify' - Resolver resolves to
node_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/stringify.ts - extract returns
@jsr/std__csv - translate returns
@std/csv - usage counted as
@std/csv✓
Now let me also think about test coverage. Let me write an integration test for this issue:
-
Assistant
Let me check the common helpers:
Assistant
Let me write a fixture for the issue. First, let me look at the issue 624 fixture setup:
Assistant
Now let me think about this. The issue is a real pnpm scenario where:
- Catalog has pnpm package sources
- node_modules reflects the pnpm-installed structure (symlinks)
- Fallow should still credit the declared name
In my test fixture, I'd need to set up the node_modules to mimic what pnpm would create. This is a bit complex but doable. Let me look at the simpler approach: just verify the catalog is parsed correctly and the resolver applies the mapping.
Actually, the best approach is to create a test fixture similar to the issue and verify the analysis works correctly. Let me look at how the integration tests use fixtures:
Assistant
So they use a fixture path. Let me write a unit test for the resolver to verify the catalog mapping is applied:
Actually, let me look at how the specifier tests work:
Assistant
Let me add a test for the catalog translation. First I need to find the actual integration in the resolve test:
Assistant
Let me also add a test for the resolver. First let me write a more complete test - I'll need to set up a fixture with the actual node_modules structure:
Actually, since the test fixture for issue 624 doesn't use node_modules at all (it just has import statements), let me just create a fixture similar to that. But wait, the issue here is about node_modules. Without a proper node_modules, the resolver won't be able to actually resolve
@std/csv/stringifyto a node_modules path.Hmm, this is tricky. Let me look at how the test for the issue 624 works:
Assistant
OK, so this test uses
jsr:andnpm:in source imports. My fix is for catalog-based pnpm package sources. Let me also write a test that simulates the actual issue. The test needs to:- Create a project with
pnpm-workspace.yamlcontaining catalog withjsr:andnpm:sources - Create package.json files that reference the catalog
- Create source files that import the declared names
- Create node_modules with the pnpm-style structure (symlinks)
- Verify that the analysis correctly credits the declared names
Let me write this test:
- Create a project with
Assistant
Now let me create the test fixture and test:
Assistant
Hmm, the test didn't run because it's a separate file. Let me check how the tests are structured:
Assistant
Test passes. Now let me also verify the test would fail WITHOUT my fix:
Assistant
The new test file was untracked, so stashing didn't save it. Let me run a manual reproduction without my changes:
Assistant
Without my fix, the test fails as expected. Now let me restore my fix:
Assistant
The patch failed for the integration_test.rs because I had already added the new module. Let me check what happened:
Assistant
OK the integration_test.rs already has my added module. Let me run the test again to confirm:
Assistant
The test is still failing because my source changes weren't applied. Let me apply them now:
Assistant
I see - my changes were lost. Let me re-apply:
Assistant
Good - the integration_test.rs was rejected (because I already manually added it), but everything else was applied. Let me also re-apply the pnpm_catalog.rs change since I see it wasn't in the patch list:
Assistant
Now let me run the test:
Assistant
The integration test passes. Let me run all the integration tests:
Assistant
All 546 integration tests pass. Now let me run the full test suite:
Assistant
All passing except the pre-existing permission test. Let me also check clippy once more:
Assistant
No clippy warnings. Let me run the formatter check:
Assistant
Let me fix the formatting:
Assistant
Now let me also verify my fix handles the case from the issue more thoroughly. Let me make sure my changes are complete:
Assistant
No false positives. Let me also verify by checking the human output:
Assistant
Now let me also think about whether there's any other place in the code that needs to know about this. Looking at
find_unlisted_dependenciesandfind_unused_dependencies:Currently:
- Resolver extracts package name from node_modules (e.g.,
@jsr/std__csv) - My fix translates it back to declared name (e.g.,
@std/csv) graph.package_usagecontains@std/csvfind_unused_dependencieschecksgraph.package_usage.keys()- finds@std/csv- Compares with package.json declared deps - finds
@std/csv- no unused ✓ find_unlisted_dependencieschecks all packages inpackage_usage- finds@std/csv- Compares with package.json declared deps - finds
@std/csv- no unlisted ✓
But wait - what if the user has declared
@std/csvand@jsr/std__csvBOTH in package.json? Then:graph.package_usagehas only@std/csv(translated)- package.json declared:
@std/csv,@jsr/std__csv @jsr/std__csvis not used -> reported as unused ✓ (correct!)
OK that's the expected behavior. Let me also think about another case: what if the user declares
@std/csvbut actually imports@jsr/std__csvdirectly?- pnpm installs
@jsr/std__csvin node_modules (because of catalog) - user imports
@jsr/std__csv/something - Resolver follows symlink? Wait,
@jsr/std__csvis a real package (the pnpm-installed one). There's no@std/csvto symlink because... hmm actually pnpm DOES create a symlink atnode_modules/@std/csvpointing to the virtual store. So if the user imports@jsr/std__csvdirectly, the resolver would:- Try to find
@jsr/std__csvinnode_modules/@jsr/std__csv- YES (it's the actual package) - Extract package name:
@jsr/std__csv - Translate to
@std/csv(because of the catalog)
- Try to find
- So
@std/csvis credited as used ✓
Now what about
@std/csvimport when the catalog is for an unrelated package?- catalog:
some-pkg: jsr:@std/csv@1.0.6 - package.json:
"some-pkg": "catalog:" - User imports
@std/csvdirectly - Resolver finds
@std/csvdoesn't exist in node_modules (because pnpm installed@jsr/std__csvunder thesome-pkgalias, not@std/csv) - This would be an unresolvable import - but my fix doesn't change this behavior
Hmm actually this is fine - the user is making an error in their import. The issue is for correctly declared dependencies.
Let me also think about: what if
npm:is used to install from a different package name likenpm:preact-nightly@1.0.0while declared aspreact?- catalog:
preact: npm:preact-nightly@1.0.0 - package.json:
"preact": "catalog:" - node_modules:
preact-> symlink to.pnpm/preact-nightly@1.0.0/... - User imports
preact - Resolver follows symlink, extracts
preact-nightly - Translate to
preact✓
OK my fix handles all these cases correctly.
Now let me also look at if there are any issues with my fix when there's no symlink involved. For example, if a workspace package is named the same as a catalog entry:
- Resolver extracts package name from node_modules (e.g.,
Assistant
The
workspace_roots.contains_key(pkg_name)check is to ensure that workspace packages (which are internal sources) are NOT treated as npm packages. So if a workspace package is named@jsr/std__csv(very unlikely), it would be treated as an internal module. My fix uses the translated name here, so if@jsr/std__csvis mapped to@std/csv, we'd check if@std/csvis a workspace. If it is, the resolution fails - but that's an unusual edge case.Actually wait - in the catalog fix, I need to check if the ORIGINAL name (
@jsr/std__csv) is a workspace, because that's what's actually installed. If@jsr/std__csvis a workspace, we shouldn't treat it as an npm package.Hmm, but this is getting too edge-case. Let me leave it as is for now since the user's example doesn't have a workspace named
@jsr/std__csv.Let me also look at the
try_workspace_package_fallback- this handles the case where the user imports a workspace package by name. Let me check:Assistant
OK, this uses the specifier's package name, not the node_modules path name. So this should be fine.
Now let me also think about another edge case. What if a workspace package's name is
@jsr/std__csv?Assistant
OK the
packages/internal/index.tsis reported as unused (which is correct since it's not referenced). But this isn't an issue with my fix. Let me clean up:Assistant
Let me also think about the case where
is_barewas used to short-circuit the early-exit:Assistant
The early-exit excludes
.pnpm/paths. So ifnode_modules/.pnpm/...is in the resolved path, we skip this early exit. The fallback (canonical resolution) then handles the translation. Let me verify this works:For
@std/csv/stringify-> resolves tonode_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/stringify.ts. This path contains/.pnpm/, so the early exit is skipped. Thetry_pnpm_workspace_fallbackis tried first (for workspace packages), thenextract_package_name_from_node_modules_pathis called.The path is
node_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/stringify.ts. The lastnode_modulessegment isnode_modules(at index 4). After that:@jsr/std__csv/stringify.ts. Soextract_package_name_from_node_modules_pathreturns@jsr/std__csv. ✓Let me also verify the canonical path. With symlinks,
dunce::canonicalizewould resolve the symlink. So the canonical path would benode_modules/.pnpm/@jsr+std__csv@1.0.6/node_modules/@jsr/std__csv/stringify.ts(which is what we want).Let me also think about: the early-exit with
.pnpm/exclusion - this is there because pnpm virtual store paths might have different package names (e.g.,@myorg+ui@1.0.0). But our case is actually exactly that scenario - we WANT to extract the package name and translate it.Actually, looking more carefully: the early-exit exclusion is meant to skip paths that might confuse the resolver (like the pnpm virtual store where multiple packages can coexist). The later code handles these via
try_pnpm_workspace_fallbackwhich is for workspace packages specifically.So my fix correctly applies the translation in the later code. Good.
Now let me verify a complete test once more by running the full integration test:
Assistant
Now let me also write a small unit test for the resolver with a simulated scenario. Let me look at how existing resolver tests work:
Assistant
Let me see what other tests use:
Assistant
OK, these tests verify the basic package name extraction from pnpm paths. My fix builds on top of this. Let me look at my changes once more:
Assistant
Let me see the full diff for the specifier changes:
Assistant
The diff looks clean. Let me also see the test file diff:
Assistant
Now let me also check if there are any remaining issues with my fix. Let me look at one more case - what if the catalog value is empty?
Assistant
Let me just look at the code logic to ensure it handles the edge case correctly:
Assistant
For an empty string
"", thestrip_inline_comment("")returns"", thenresolve_pnpm_source_spec("", "react")returns None. So we get(None, None). Good.For
nullvalue, the match arm returns(None, None). Good.Now let me also think about my logic - what if the catalog value is
"jsr:"(empty body)?Assistant
Hmm! I see a potential issue:
For
react: jsr:1.0.6, my fix resolves to@jsr/react. But that's wrong because:- declared
react - value
jsr:1.0.6(version-only) - pnpm interprets this as installing
reactfrom JSR - The actual JSR package name is... well, JSR packages always have a scope. There's no JSR package called
react.
But for users, this is an error in their config - they shouldn't use
jsr:1.0.6without specifying the JSR package name. My fallback says "use the declared name", which produces@jsr/react. This is wrong.Let me check what happens when the user uses this:
- declared
Assistant
So for
jsr:1.0.6with declaredreact, my code resolves to@jsr/react. But this is incorrect if the user really meantjsr:@react/something@1.0.6.Wait, let me re-read the issue:
catalog: '@std/csv': jsr:1.0.6The issue's example uses
@std/csv: jsr:1.0.6. The@std/csvis the declared name, and the valuejsr:1.0.6means "install@std/csv(the JSR package matching the declared name) at version 1.0.6". This is the user's intent.So
jsr:1.0.6with declared@std/csvcorrectly resolves to@jsr/std__csv. ✓But
jsr:1.0.6with declaredreactwould resolve to@jsr/react, which is wrong (because there's no JSR package namedreact). However, this is the user's config error - they should usejsr:@something/react@1.0.6for an arbitrary npm-style name.For pnpm, the semantics are:
jsr:<pkg>@<ver>- install the JSR package<pkg>at version<ver>jsr:<ver>- install the catalog-declared JSR package (i.e., the package whose JSR name matches the declared catalog key) at version<ver>jsr:- same as above with no version (latest)
So my fallback to "use the declared name" is correct per pnpm semantics. The user is expected to use a JSR-conventional name as the declared key (e.g.,
@std/csv->@jsr/std__csv).Let me re-read the issue once more to make sure:
catalog: '@std/csv': jsr:1.0.6 unstorage: npm:unstorage-nightly@2.0.0-alpha.5Yes, the user uses JSR package name conventions for the declared key. So my fix is correct.
Now what about a case where the user uses an arbitrary npm-style name as the declared key with
jsr:<ver>?catalog: csv: jsr:1.0.6Here
csvis the declared name andjsr:1.0.6means "install the JSR package corresponding tocsvat version 1.0.6". The JSR name doesn't exist (no JSR package namedcsv), so this would be a user error. But if we were to interpret it literally, the resolved name would be@jsr/csv.My code currently returns
@jsr/csvfor this case. That's consistent with pnpm's behavior.OK I think the logic is correct. Let me also think about whether there could be an issue when both the declared name and the resolved name are valid:
Actually, let me think more carefully. The pnpm JSR convention requires scoped JSR packages (
@scope/name). For unscoped JSR packages, the convention is unclear. Let me check pnpm docs once more:From pnpm docs:
By default, JSR packages are installed as @jsr/__. For example, @std/path is installed as @jsr/std__path.
So unscoped JSR packages are... not covered. Let me check the actual pnpm source code or test what happens:
Assistant
Wait, there's an issue with subpath! For
jsr:@std/csv/sub@1.0.6, it resolves to@jsr/std__csv/sub. That's because my regex grabs the subpath. But this is wrong - the resolved name should be just@jsr/std__csv(no subpath). Let me fix this:Assistant
For
jsr:@std/csv/sub@1.0.6:- body =
@std/csv/sub@1.0.6 - after_scope =
csv/sub@1.0.6 - after_scope.find('@') = 8 (at position of
@1.0.6) - pkg_end with slash = body.find('/') + 1 + 8 = 4 + 1 + 8 = 13
- pkg = body[..13] =
@std/csv/sub
That's wrong - the subpath is included. Let me also exclude subpath. The JSR package id never has subpaths in the same way npm does (JSR uses
^for subpath import). Actually let me check - pnpm docs say:jsr:[@]
So no subpath syntax. Let me strip subpath too:
- body =
Assistant
Hmm now there's a different problem. For
jsr:@std/csvwith declaredcsv, the result is@jsr/csvinstead of@jsr/std__csv. Let me check why...Oh I see - my logic now strips everything from the first
/onward. So for@std/csv, the head is@std, andjsr_package_id_to_npm_nameis called with@std, which doesn't have a/after position 0, so it returns@std. That's wrong.Let me fix this. The issue is that for the
@scope/nameformat, I need to find the slash AFTER the leading@. Let me restructure:Assistant
Most are correct now. But
@std/csv/sub@1.0.6is still wrong - returns@jsr/std__csv/sub. Let me think...The issue is that for
@std/csv/sub@1.0.6:- starts with
@-> scoped body.find('/')returns 4 (after@std)- after_scope =
csv/sub@1.0.6 - after_scope.find('@') = 8 (at position of
@1.0.6) - pkg_end = 4 + 1 + 8 = 13
- pkg = body[..13] =
@std/csv/sub
The issue is that
after_scope.find('@')finds@1.0.6AFTER the subpath. I need to find the subpath FIRST, then look for@in the package portion (before subpath).- starts with
Assistant
All look correct now. Let me run my tests to ensure they still pass:
Assistant
Let me also add a test for the subpath case:
Assistant
All 26 tests pass. Let me run all tests one more time:
Assistant
Let me run clippy and fmt:
Assistant
Let me fix this clippy warning:
Assistant
Still correct. Let me run clippy again:
Assistant
No clippy warnings. Let me run fmt:
Assistant
All passing. Let me also rebuild the release binary and do a final verification:
Assistant
No false positives. Let me also test the human-readable output:
Assistant
Let me also verify that I handle the case from the issue exactly:
Assistant
All looking good. Now let me make sure the existing catalog test still works (catalogs that don't have package-source values):
Assistant
All catalog tests pass. Let me also verify that the new pnpm source test passes:
Assistant
Let me also check whether the analyzer correctly produces the expected
unused-catalog-entries- i.e. that the@std/csvandunstoragecatalog entries are NOT marked as unused (since they're referenced via catalog:):Assistant
All correct. Let me look at the final summary of my changes:
Assistant
Let me also do a final review of the changes:
Assistant
All changes look clean. Let me also run a final summary check:
Assistant
All 546 integration tests pass.
Now let me re-review my changes one more time to make sure I haven't missed anything:
Assistant
All looks good. Let me also do a final verification of the specifier changes:
Assistant
Excellent. All my changes look good. Let me do one more comprehensive test:
Assistant
All tests pass except the pre-existing permission test. Let me check the checklist:
Checklist Review
Now let me review my work against the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
- YES. I successfully reproduced the issue by creating a test fixture and verifying that
fallow dead-code --format jsonreports@std/csvas unused and@jsr/std__csvas unlisted. After applying my fix, the same test fixture no longer reports those false positives.
- YES. I successfully reproduced the issue by creating a test fixture and verifying that
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- YES. I verified the fix by:
- Running my release binary against the test fixture and confirming no false positives
- Adding an integration test (
issue_pnpm_source_aliases) that fails without the fix and passes with it
- YES. I verified the fix by:
-
I have thought about edge cases and made sure my fix handles them as well.
- YES. I considered and handled:
- Scoped JSR packages (
@std/csv->@jsr/std__csv) - Unscoped JSR packages (
csv->@jsr/csv) - JSR version-only specifiers (
jsr:1.0.6with declared@std/csv) - Bare JSR specifiers (
jsr:with declared@std/csv) - Explicit JSR packages (
jsr:@std/csv@1.0.6) - npm aliases (
npm:unstorage-nightly@2.0.0-alpha.5->unstorage-nightly) - Scoped npm aliases (
npm:@scope/alias@^1.0.0) - Subpath stripping for both JSR and npm
- Plain version strings (no translation)
- Workspace, link, file, git, github sources (no translation)
- Empty values
- Scoped JSR packages (
- YES. I considered and handled:
-
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:
cargo test --workspace- all tests pass except the pre-existingfix_batch_aborts_when_a_target_directory_is_read_onlyfailure (unrelated to my changes, fails when running as root due to permission handling)cargo test -p fallow-core --test integration_test- all 546 tests pass (including my new test)cargo test -p fallow-config workspace::pnpm_catalog- all 26 tests passcargo clippy --workspace --all-targets -- -D warnings- cleancargo fmt --all -- --check- clean
- YES. I ran:
Let me clean up before submitting:
-
Assistant
Let me also clean up my temporary test directory:
Assistant
Now let me also look at if there's any issue with my approach regarding the
internal_package_namethat returns for some cases. Let me check:Assistant
Let me check where InternalPackageModule is created:
Assistant
This handles package.json
importsfield, not pnpm package sources. The pnpm package source resolution goes through a different path (extract_package_name_from_node_modules_path). My fix targets that path.Let me also check that we handle the case where the specifier itself uses
npm:orjsr::Assistant
Hmm - I forgot to add apps/native! Let me check:
Assistant
Let me check the actual directory:
Assistant
Interesting - the test files were created in /fallow (because the cwd became /fallow). Let me clean up and try again:
Assistant
Good, all cleaned up. Let me also make sure my fix is comprehensive by doing one more verification of the integration test:
Assistant
All tests pass. Now let me submit the changes:
Assistant
The summary of changes:
- crates/config/src/workspace/pnpm_catalog.rs: Extended
PnpmCatalogEntrywithsource_specandresolved_package_namefields. Addedresolve_pnpm_source_spec()helper to compute the resolved name for pnpm package sources (jsr:,npm:<other>@<ver>). Addedresolved_to_declared_map()method onPnpmCatalogData. Added comprehensive unit tests. - crates/config/src/workspace/mod.rs: Re-export the new
resolve_pnpm_source_specfunction. - crates/core/src/analyze/mod.rs: Made
unused_catalogmodulepub(super)so other modules can use it. - crates/core/src/analyze/unused_catalog.rs: Added
gather_pnpm_resolved_to_declared_map()helper for building the mapping. - crates/core/src/lib.rs: Updated
resolve::resolve_all_importscallers to build and pass the mapping. - crates/core/src/external_style_usage.rs: Updated to build and pass the mapping.
- crates/graph/src/resolve/types.rs: Added
pnpm_resolved_to_declaredfield toResolveContext. - crates/graph/src/resolve/mod.rs: Updated
resolve_all_importsto accept the mapping parameter. - crates/graph/src/resolve/specifier.rs: Added
translate_pnpm_package_namehelper and applied it at all 6 places whereextract_package_name_from_node_modules_pathis used. - crates/graph/src/resolve/fallbacks.rs and crates/graph/src/resolve/tests.rs: Updated test contexts to include the new field.
- crates/core/tests/integration_test.rs: Added new test module.
- crates/core/tests/integration_test/issue_pnpm_source_aliases.rs: New integration test reproducing the issue.
Let me submit:
- crates/config/src/workspace/pnpm_catalog.rs: Extended
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →