pacquet: drop the vestigial `Fn() -> DependencyGroupList` generic from `Add`
#13.088 aperta il 16 lug 2026
Metriche repository
- Star
- (30.787 stelle)
- Metriche merge PR
- (Merge medio 2g 7h) (398 PR mergiate in 30 g)
Descrizione
Context
pacquet_package_manager::Add (pnpm/crates/package-manager/src/add.rs) is generic over two parameters:
pub struct Add<'a, ListDependencyGroups, DependencyGroupList>
where
ListDependencyGroups: Fn() -> DependencyGroupList,
DependencyGroupList: IntoIterator<Item = DependencyGroup>,
The closure existed because the list was consumed more than once. The field used to say so:
pub list_dependency_groups: ListDependencyGroups, // must be a function because it is called multiple times
https://github.com/pnpm/pnpm/pull/12995 changed that. Add::run now collects the groups once and reuses the Vec:
let dependency_groups: Vec<DependencyGroup> = list_dependency_groups().into_iter().collect();
That PR correctly deleted the now-false comment, but left the machinery behind. list_dependency_groups is called exactly once, so the Fn() indirection no longer buys anything — a reader of the struct now sees a generic closure parameter with no justification.
Proposal
Collapse to a single generic and take the groups directly:
pub struct Add<'a, DependencyGroupList>
where
DependencyGroupList: IntoIterator<Item = DependencyGroup>,
{
pub dependency_groups: DependencyGroupList,
// ...
}
and thread dependency_groups: impl IntoIterator<Item = DependencyGroup> through add_package / add_packages in pnpm/crates/cli/src/cli_args/add.rs.
Every call site currently passes a trivial closure, so each becomes marginally simpler:
| Call site | Now | After |
|---|---|---|
cli_args/add.rs |
|| self.dependency_options.dependency_groups() |
self.dependency_options.dependency_groups() |
cli_args/global.rs |
|| std::iter::once(DependencyGroup::Prod) |
[DependencyGroup::Prod] |
cli_args/dlx.rs |
|| std::iter::once(DependencyGroup::Prod) |
[DependencyGroup::Prod] |
cli_args/runtime.rs |
|| std::iter::once(request.dependency_group) |
[request.dependency_group] |
cli_args/self_update/install_pnpm.rs |
|| std::iter::once(DependencyGroup::Prod) |
[DependencyGroup::Prod] |
Notes
Pure refactor — no user-visible behavior changes, so no changeset and no TypeScript counterpart. It was left out of https://github.com/pnpm/pnpm/pull/12995 under the scope-discipline rule in REVIEW_GUIDE.md §4, since it reaches three files (dlx.rs, runtime.rs, install_pnpm.rs) that PR otherwise had no reason to touch.
Written by an agent (Claude Code, claude-opus-4-8).