Skip to content

fix: keep a peer dependency out of dependencies when a sub path resolves to it - #519

Merged
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_peer_dep_sub_path
Jul 28, 2026
Merged

fix: keep a peer dependency out of dependencies when a sub path resolves to it#519
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_peer_dep_sub_path

Conversation

@dsherret

Copy link
Copy Markdown
Collaborator

Found while checking whether #433 still reproduces. The cases reported there are all fixed on main, but a neighbouring one isn't.

A package imported both bare and by a sub path produces two npm: specifiers:

import pc from "picocolors";
import "picocolors/types";

Only the bare specifier matches the user's mapping, so the sub path gets an auto derived PackageMappedSpecifier with peer_dependency: false. get_dependencies emits both entries, and package_json.ts filters that same list into each section, so the package lands in both:

"dependencies": { "picocolors": "^1.1.1" },
"peerDependencies": { "picocolors": "^1.1.1" }

npm then installs it as a regular dependency, which is the symptom #433 describes.

Being a peer dependency is a property of the package in the package.json rather than of an individual specifier, so a name marked as one anywhere stays one. The entries are then identical and collapse in the existing dedup().

Mapping npm:pkg@^1 when the source only imports pkg/sub still errors with "specifiers were indicated to be mapped to a package, but were not found". That seems right — the specifier that's actually imported is the one to map, which is what subPath is for.

…olves to it

A package imported both bare and by a sub path produces two `npm:`
specifiers. Only the bare one matches the user's mapping, so the sub path
got an auto derived mapping with `peerDependency` unset and the package
ended up in both `dependencies` and `peerDependencies`.
@dsherret
dsherret merged commit 8e044fe into denoland:main Jul 28, 2026
5 checks passed
@dsherret
dsherret deleted the fix_peer_dep_sub_path branch July 28, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant